Browse Source

chore: improve ci-cd

pull/25/head
Antoine Lanoe 7 months ago
parent
commit
7ea5a31096
  1. 1
      .eslintcache
  2. 47
      .github/workflows/cd.yml
  3. 50
      .github/workflows/ci.yml
  4. 29
      .github/workflows/superdiff.yml
  5. 1
      .gitignore
  6. 1
      .husky/pre-commit
  7. 8
      .prettierignore
  8. 1
      .prettierrc
  9. 2
      README.md
  10. 2
      dist/index.d.mts
  11. 2
      dist/index.d.ts
  12. 16
      eslint.config.mjs
  13. 13057
      package-lock.json
  14. 59
      package.json
  15. 10
      src/list-diff.ts
  16. 4
      src/model.ts
  17. 39
      src/object-diff.ts
  18. 4
      src/utils.ts
  19. 48
      test/list-diff.test.ts
  20. 92
      test/object-diff.test.ts
  21. 28
      test/utils.test.ts
  22. 9
      tsconfig.json
  23. 2
      tsup.config.ts

1
.eslintcache

@ -0,0 +1 @@ @@ -0,0 +1 @@
[{"/Users/antoine/Desktop/superdiff/eslint.config.mjs":"1","/Users/antoine/Desktop/superdiff/index.ts":"2","/Users/antoine/Desktop/superdiff/tsup.config.ts":"3","/Users/antoine/Desktop/superdiff/src/index.ts":"4","/Users/antoine/Desktop/superdiff/src/list-diff.ts":"5","/Users/antoine/Desktop/superdiff/src/model.ts":"6","/Users/antoine/Desktop/superdiff/src/object-diff.ts":"7","/Users/antoine/Desktop/superdiff/src/utils.ts":"8","/Users/antoine/Desktop/superdiff/test/list-diff.test.ts":"9","/Users/antoine/Desktop/superdiff/test/object-diff.test.ts":"10","/Users/antoine/Desktop/superdiff/test/utils.test.ts":"11"},{"size":426,"mtime":1727602294779,"results":"12","hashOfConfig":"13"},{"size":0,"mtime":1727601340027,"results":"14","hashOfConfig":"15"},{"size":222,"mtime":1727601767512,"results":"16","hashOfConfig":"15"},{"size":160,"mtime":1727601340028,"results":"17","hashOfConfig":"15"},{"size":4697,"mtime":1727601897826,"results":"18","hashOfConfig":"15"},{"size":1903,"mtime":1727601897832,"results":"19","hashOfConfig":"15"},{"size":9363,"mtime":1727602282176,"results":"20","hashOfConfig":"15"},{"size":1150,"mtime":1727601897855,"results":"21","hashOfConfig":"15"},{"size":18523,"mtime":1727601897889,"results":"22","hashOfConfig":"15"},{"size":23198,"mtime":1727601897918,"results":"23","hashOfConfig":"15"},{"size":3560,"mtime":1727601897925,"results":"24","hashOfConfig":"15"},{"filePath":"25","messages":"26","suppressedMessages":"27","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"13i3tau",{"filePath":"28","messages":"29","suppressedMessages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"a3qfx6",{"filePath":"31","messages":"32","suppressedMessages":"33","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","suppressedMessages":"36","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"37","messages":"38","suppressedMessages":"39","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","suppressedMessages":"42","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"43","messages":"44","suppressedMessages":"45","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","suppressedMessages":"48","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"49","messages":"50","suppressedMessages":"51","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","suppressedMessages":"54","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"55","messages":"56","suppressedMessages":"57","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/antoine/Desktop/superdiff/eslint.config.mjs",[],[],"/Users/antoine/Desktop/superdiff/index.ts",[],[],"/Users/antoine/Desktop/superdiff/tsup.config.ts",[],[],"/Users/antoine/Desktop/superdiff/src/index.ts",[],[],"/Users/antoine/Desktop/superdiff/src/list-diff.ts",[],[],"/Users/antoine/Desktop/superdiff/src/model.ts",[],[],"/Users/antoine/Desktop/superdiff/src/object-diff.ts",[],[],"/Users/antoine/Desktop/superdiff/src/utils.ts",[],[],"/Users/antoine/Desktop/superdiff/test/list-diff.test.ts",[],[],"/Users/antoine/Desktop/superdiff/test/object-diff.test.ts",[],[],"/Users/antoine/Desktop/superdiff/test/utils.test.ts",[],[]]

47
.github/workflows/cd.yml

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
name: CD Pipeline
on:
workflow_run:
workflows: ["CI Pipeline"]
types:
- completed
branches:
- master
jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
registry-url: https://registry.npmjs.org
cache-dependency-path: package-lock.json
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: npm install
- name: Build the project
run: npm run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release

50
.github/workflows/ci.yml

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
name: CI Pipeline
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
registry-url: https://registry.npmjs.org
cache-dependency-path: package-lock.json
- name: Retrieve dependencies
id: "modules_cache"
uses: actions/cache@v4
with:
path: node_modules
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
node-modules-${{ runner.os }}-
- name: Install dependencies
if: steps.modules_cache.outputs.cache-hit != 'true'
run: npm install
- name: Run typescript
run: npm run tsc
- name: Run linter
run: npm run lint
- name: Run tests
run: npm run test
- name: Build the project
run: npm run build

29
.github/workflows/superdiff.yml

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
name: Superdiff CI
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Install dependencies
run: npm install
- name: Build app
run: npm run build
- name: Test app
run: npm test

1
.gitignore vendored

@ -1 +1,2 @@ @@ -1 +1,2 @@
/node_modules
dist

1
.husky/pre-commit

@ -0,0 +1 @@ @@ -0,0 +1 @@
npm run test && npm run tsc && npm run lint

8
.prettierignore

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
dist
.github
.husky
jest.config.js
package-lock.json
README.md
tsconfig.json
tsup.config.ts

1
.prettierrc

@ -0,0 +1 @@ @@ -0,0 +1 @@
{}

2
README.md

@ -425,7 +425,7 @@ isEqual( @@ -425,7 +425,7 @@ isEqual(
[
{ name: "joe", age: 98 },
{ name: "nina", age: 23 },
]
],
);
```

2
dist/index.d.mts vendored

@ -87,7 +87,7 @@ declare function getObjectDiff(prevData: ObjectData, nextData: ObjectData, optio @@ -87,7 +87,7 @@ declare function getObjectDiff(prevData: ObjectData, nextData: ObjectData, optio
- `referenceProperty` will consider an object to be updated instead of added or deleted if one of its properties remains stable, such as its `id`. This option has no effect on other datatypes.
* @returns ListDiff
*/
declare const getListDiff: <T>(prevList: T[] | null | undefined, nextList: T[] | null | undefined, options?: ListOptions) => ListDiff;
declare const getListDiff: <T>(prevList: T[] | undefined | null, nextList: T[] | undefined | null, options?: ListOptions) => ListDiff;
/**
* Returns true if two data are equal

2
dist/index.d.ts vendored

@ -87,7 +87,7 @@ declare function getObjectDiff(prevData: ObjectData, nextData: ObjectData, optio @@ -87,7 +87,7 @@ declare function getObjectDiff(prevData: ObjectData, nextData: ObjectData, optio
- `referenceProperty` will consider an object to be updated instead of added or deleted if one of its properties remains stable, such as its `id`. This option has no effect on other datatypes.
* @returns ListDiff
*/
declare const getListDiff: <T>(prevList: T[] | null | undefined, nextList: T[] | null | undefined, options?: ListOptions) => ListDiff;
declare const getListDiff: <T>(prevList: T[] | undefined | null, nextList: T[] | undefined | null, options?: ListOptions) => ListDiff;
/**
* Returns true if two data are equal

16
eslint.config.mjs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
export default [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ ignores: ["dist", "jest.config.js"] },
{ settings: { react: { version: "detect" } } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off"
},
},
];

13057
package-lock.json generated

File diff suppressed because it is too large Load Diff

59
package.json

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
"version": "1.1.3",
"description": "SuperDiff checks the changes between two objects or arrays. It returns a complete diff with relevant information for each property or piece of data",
"main": "dist/index.js",
"module": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"declaration": true,
"files": [
@ -15,6 +15,35 @@ @@ -15,6 +15,35 @@
"type": "git",
"url": "git+https://github.com/DoneDeal0/superdiff"
},
"bugs": {
"url": "https://github.com/DoneDeal0/superdiff/issues"
},
"readme": "./README.md",
"release": {
"branches": [
"master"
],
"verifyConditions": [
"@semantic-release/github",
"@semantic-release/npm"
],
"prepare": [],
"publish": [
"@semantic-release/npm",
"@semantic-release/github"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
[
"@semantic-release/npm",
{
"npmPublish": true
}
]
]
},
"keywords": [
"data diff",
"comparison",
@ -31,17 +60,29 @@ @@ -31,17 +60,29 @@
"compare"
],
"scripts": {
"build": "tsup --dts --format esm,cjs",
"publish": "npm publish --access=public",
"build": "tsup",
"test": "jest",
"tsc": "tsc --noEmit"
"lint": "eslint --cache --max-warnings=0 --fix",
"tsc": "tsc --noEmit --incremental",
"format": "npx prettier . --write",
"prepare": "husky"
},
"devDependencies": {
"@babel/preset-env": "^7.23.8",
"@types/jest": "^29.5.11",
"@eslint/js": "^9.11.1",
"eslint": "^9.11.1",
"prettier": "^3.3.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^11.0.0",
"@semantic-release/npm": "^12.0.1",
"@actions/core": "^1.10.1",
"@babel/preset-env": "^7.25.4",
"@types/jest": "^29.5.13",
"husky": "^9.1.6",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
"ts-jest": "^29.2.5",
"tsup": "^8.3.0",
"typescript-eslint": "^8.7.0",
"typescript": "^5.6.2"
}
}

10
src/list-diff.ts

@ -3,7 +3,7 @@ import { isEqual, isObject } from "./utils"; @@ -3,7 +3,7 @@ import { isEqual, isObject } from "./utils";
function getLeanDiff(
diff: ListDiff["diff"],
showOnly = [] as ListOptions["showOnly"]
showOnly = [] as ListOptions["showOnly"],
): ListDiff["diff"] {
return diff.filter((value) => showOnly?.includes(value.status));
}
@ -11,7 +11,7 @@ function getLeanDiff( @@ -11,7 +11,7 @@ function getLeanDiff(
function formatSingleListDiff<T>(
listData: T[],
status: ListDiffStatus,
options: ListOptions = { showOnly: [] }
options: ListOptions = { showOnly: [] },
): ListDiff {
const diff = listData.map((data, i) => ({
value: data,
@ -42,7 +42,7 @@ function getListStatus(listDiff: ListDiff["diff"]): ListDiffStatus { @@ -42,7 +42,7 @@ function getListStatus(listDiff: ListDiff["diff"]): ListDiffStatus {
function isReferencedObject(
value: any,
referenceProperty: ListOptions["referenceProperty"]
referenceProperty: ListOptions["referenceProperty"],
): value is Record<string, any> {
if (isObject(value) && !!referenceProperty) {
return Object.hasOwn(value, referenceProperty);
@ -67,7 +67,7 @@ export const getListDiff = <T>( @@ -67,7 +67,7 @@ export const getListDiff = <T>(
referenceProperty: undefined,
considerMoveAsUpdate: false,
ignoreArrayOrder: false,
}
},
): ListDiff => {
if (!prevList && !nextList) {
return {
@ -91,7 +91,7 @@ export const getListDiff = <T>( @@ -91,7 +91,7 @@ export const getListDiff = <T>(
return (
isEqual(
prevValue[options.referenceProperty as string],
nextValue[options.referenceProperty as string]
nextValue[options.referenceProperty as string],
) && !prevIndexMatches.includes(prevIdx)
);
}

4
src/model.ts

@ -29,14 +29,14 @@ export type ObjectStatusTuple = readonly [ @@ -29,14 +29,14 @@ export type ObjectStatusTuple = readonly [
"added",
"equal",
"deleted",
"updated"
"updated",
];
export type ListStatusTuple = readonly [
"added",
"equal",
"deleted",
"moved",
"updated"
"updated",
];
export type isEqualOptions = {

39
src/object-diff.ts

@ -14,14 +14,15 @@ function getLeanDiff( @@ -14,14 +14,15 @@ function getLeanDiff(
showOnly: ObjectOptions["showOnly"] = {
statuses: [],
granularity: GRANULARITY.BASIC,
}
},
): ObjectDiff["diff"] {
const { statuses, granularity } = showOnly;
return diff.reduce((acc, value) => {
return diff.reduce(
(acc, value) => {
if (granularity === GRANULARITY.DEEP && value.subPropertiesDiff) {
const cleanSubPropertiesDiff = getLeanDiff(
value.subPropertiesDiff,
showOnly
showOnly,
);
if (cleanSubPropertiesDiff.length > 0) {
return [
@ -42,7 +43,9 @@ function getLeanDiff( @@ -42,7 +43,9 @@ function getLeanDiff(
return [...acc, value];
}
return acc;
}, [] as ObjectDiff["diff"]);
},
[] as ObjectDiff["diff"],
);
}
function getObjectStatus(diff: ObjectDiff["diff"]): ObjectDiffStatus {
@ -57,7 +60,7 @@ function formatSingleObjectDiff( @@ -57,7 +60,7 @@ function formatSingleObjectDiff(
options: ObjectOptions = {
ignoreArrayOrder: false,
showOnly: { statuses: [], granularity: GRANULARITY.BASIC },
}
},
): ObjectDiff {
if (!data) {
return {
@ -110,13 +113,13 @@ function formatSingleObjectDiff( @@ -110,13 +113,13 @@ function formatSingleObjectDiff(
function getPreviousMatch(
previousValue: any | undefined,
nextSubProperty: any,
options?: ObjectOptions
options?: ObjectOptions,
): any | undefined {
if (!previousValue) {
return undefined;
}
const previousMatch = Object.entries(previousValue).find(([subPreviousKey]) =>
isEqual(subPreviousKey, nextSubProperty, options)
isEqual(subPreviousKey, nextSubProperty, options),
);
return previousMatch ? previousMatch[1] : undefined;
}
@ -124,7 +127,7 @@ function getPreviousMatch( @@ -124,7 +127,7 @@ function getPreviousMatch(
function getValueStatus(
previousValue: any,
nextValue: any,
options?: ObjectOptions
options?: ObjectOptions,
): ObjectDiffStatus {
if (isEqual(previousValue, nextValue, options)) {
return STATUS.EQUAL;
@ -133,7 +136,7 @@ function getValueStatus( @@ -133,7 +136,7 @@ function getValueStatus(
}
function getPropertyStatus(
subPropertiesDiff: SubProperties[]
subPropertiesDiff: SubProperties[],
): ObjectDiffStatus {
return subPropertiesDiff.some((property) => property.status !== STATUS.EQUAL)
? STATUS.UPDATED
@ -142,7 +145,7 @@ function getPropertyStatus( @@ -142,7 +145,7 @@ function getPropertyStatus(
function getDeletedProperties(
previousValue: Record<string, any> | undefined,
nextValue: Record<string, any>
nextValue: Record<string, any>,
): { property: string; value: any }[] | undefined {
if (!previousValue) return undefined;
const prevKeys = Object.keys(previousValue);
@ -160,13 +163,13 @@ function getDeletedProperties( @@ -160,13 +163,13 @@ function getDeletedProperties(
function getSubPropertiesDiff(
previousValue: Record<string, any> | undefined,
nextValue: Record<string, any>,
options?: ObjectOptions
options?: ObjectOptions,
): SubProperties[] {
const subPropertiesDiff: SubProperties[] = [];
let subDiff: SubProperties[];
const deletedMainSubProperties = getDeletedProperties(
previousValue,
nextValue
nextValue,
);
if (deletedMainSubProperties) {
deletedMainSubProperties.forEach((deletedProperty) => {
@ -182,9 +185,9 @@ function getSubPropertiesDiff( @@ -182,9 +185,9 @@ function getSubPropertiesDiff(
const previousMatch = getPreviousMatch(
previousValue,
nextSubProperty,
options
options,
);
if (!!!previousMatch) {
if (!previousMatch) {
return subPropertiesDiff.push({
property: nextSubProperty,
previousValue: previousMatch,
@ -201,7 +204,7 @@ function getSubPropertiesDiff( @@ -201,7 +204,7 @@ function getSubPropertiesDiff(
const data: SubProperties[] = getSubPropertiesDiff(
previousMatch,
nextSubValue,
options
options,
);
if (data && data.length > 0) {
subDiff = data;
@ -237,7 +240,7 @@ export function getObjectDiff( @@ -237,7 +240,7 @@ export function getObjectDiff(
options: ObjectOptions = {
ignoreArrayOrder: false,
showOnly: { statuses: [], granularity: GRANULARITY.BASIC },
}
},
): ObjectDiff {
if (!prevData && !nextData) {
return {
@ -255,7 +258,7 @@ export function getObjectDiff( @@ -255,7 +258,7 @@ export function getObjectDiff(
const diff: ObjectDiff["diff"] = [];
Object.entries(nextData).forEach(([nextProperty, nextValue]) => {
const previousValue = prevData[nextProperty];
if (!!!previousValue) {
if (!previousValue) {
return diff.push({
property: nextProperty,
previousValue,
@ -271,7 +274,7 @@ export function getObjectDiff( @@ -271,7 +274,7 @@ export function getObjectDiff(
const subPropertiesDiff: SubProperties[] = getSubPropertiesDiff(
previousValue,
nextValue,
options
options,
);
const subPropertyStatus = getPropertyStatus(subPropertiesDiff);
return diff.push({

4
src/utils.ts

@ -10,7 +10,7 @@ import { isEqualOptions } from "./model"; @@ -10,7 +10,7 @@ import { isEqualOptions } from "./model";
export function isEqual(
a: any,
b: any,
options: isEqualOptions = { ignoreArrayOrder: false }
options: isEqualOptions = { ignoreArrayOrder: false },
): boolean {
if (typeof a !== typeof b) return false;
if (Array.isArray(a) && Array.isArray(b)) {
@ -19,7 +19,7 @@ export function isEqual( @@ -19,7 +19,7 @@ export function isEqual(
}
if (options.ignoreArrayOrder) {
return a.every((v) =>
b.some((nextV: any) => JSON.stringify(nextV) === JSON.stringify(v))
b.some((nextV: any) => JSON.stringify(nextV) === JSON.stringify(v)),
);
}
return a.every((v, i) => JSON.stringify(v) === JSON.stringify(b[i]));

48
test/list-diff.test.ts

@ -10,7 +10,7 @@ describe("getListDiff", () => { @@ -10,7 +10,7 @@ describe("getListDiff", () => {
});
it("consider previous list as completely deleted if no next list is provided", () => {
expect(
getListDiff(["mbappe", "mendes", "verratti", "ruiz"], null)
getListDiff(["mbappe", "mendes", "verratti", "ruiz"], null),
).toStrictEqual({
type: "list",
status: "deleted",
@ -48,7 +48,7 @@ describe("getListDiff", () => { @@ -48,7 +48,7 @@ describe("getListDiff", () => {
});
it("consider next list as completely added if no previous list is provided", () => {
expect(
getListDiff(null, ["mbappe", "mendes", "verratti", "ruiz"])
getListDiff(null, ["mbappe", "mendes", "verratti", "ruiz"]),
).toStrictEqual({
type: "list",
status: "added",
@ -88,8 +88,8 @@ describe("getListDiff", () => { @@ -88,8 +88,8 @@ describe("getListDiff", () => {
expect(
getListDiff(
["mbappe", "mendes", "verratti", "ruiz"],
["mbappe", "messi", "ruiz"]
)
["mbappe", "messi", "ruiz"],
),
).toStrictEqual({
type: "list",
status: "updated",
@ -187,8 +187,8 @@ describe("getListDiff", () => { @@ -187,8 +187,8 @@ describe("getListDiff", () => {
{ name: "paul", age: 32 },
{ name: "joe", age: 88 },
{ name: "nina", age: 23 },
]
)
],
),
).toStrictEqual({
type: "list",
status: "updated",
@ -226,7 +226,7 @@ describe("getListDiff", () => { @@ -226,7 +226,7 @@ describe("getListDiff", () => {
});
it("detects changes between lists containing duplicated values", () => {
expect(
getListDiff(["mbappe", "messi"], ["mbappe", "mbappe", "messi"])
getListDiff(["mbappe", "messi"], ["mbappe", "mbappe", "messi"]),
).toStrictEqual({
type: "list",
status: "updated",
@ -257,8 +257,8 @@ describe("getListDiff", () => { @@ -257,8 +257,8 @@ describe("getListDiff", () => {
expect(
getListDiff(
["mbappe", "messi", "messi", "mbappe"],
["mbappe", "messi", "messi"]
)
["mbappe", "messi", "messi"],
),
).toStrictEqual({
type: "list",
status: "updated",
@ -314,8 +314,8 @@ describe("getListDiff", () => { @@ -314,8 +314,8 @@ describe("getListDiff", () => {
{ name: "joe", age: 88 },
false,
{ name: "joe", age: 88 },
]
)
],
),
).toStrictEqual({
type: "list",
status: "updated",
@ -416,8 +416,8 @@ describe("getListDiff", () => { @@ -416,8 +416,8 @@ describe("getListDiff", () => {
false,
{ name: "joe", age: 88 },
],
{ showOnly: ["added", "deleted"] }
)
{ showOnly: ["added", "deleted"] },
),
).toStrictEqual({
type: "list",
status: "updated",
@ -462,7 +462,7 @@ describe("getListDiff", () => { @@ -462,7 +462,7 @@ describe("getListDiff", () => {
expect(
getListDiff(["mbappe", "mendes", "verratti", "ruiz"], null, {
showOnly: ["moved", "updated"],
})
}),
).toStrictEqual({
type: "list",
status: "deleted",
@ -473,7 +473,7 @@ describe("getListDiff", () => { @@ -473,7 +473,7 @@ describe("getListDiff", () => {
expect(
getListDiff(null, ["mbappe", "mendes", "verratti", "ruiz"], {
showOnly: ["added"],
})
}),
).toStrictEqual({
type: "list",
status: "added",
@ -529,8 +529,8 @@ describe("getListDiff", () => { @@ -529,8 +529,8 @@ describe("getListDiff", () => {
],
{
referenceProperty: "id",
}
)
},
),
).toStrictEqual({
type: "list",
status: "updated",
@ -591,7 +591,7 @@ describe("getListDiff", () => { @@ -591,7 +591,7 @@ describe("getListDiff", () => {
expect(
getListDiff(["mbappe", "messi"], ["mbappe", "mbappe", "messi"], {
considerMoveAsUpdate: true,
})
}),
).toStrictEqual({
type: "list",
status: "updated",
@ -639,8 +639,8 @@ describe("getListDiff", () => { @@ -639,8 +639,8 @@ describe("getListDiff", () => {
{
referenceProperty: "id",
considerMoveAsUpdate: true,
}
)
},
),
).toStrictEqual({
type: "list",
status: "updated",
@ -712,8 +712,8 @@ describe("getListDiff", () => { @@ -712,8 +712,8 @@ describe("getListDiff", () => {
],
{
ignoreArrayOrder: true,
}
)
},
),
).toStrictEqual({
type: "list",
status: "equal",
@ -758,8 +758,8 @@ describe("getListDiff", () => { @@ -758,8 +758,8 @@ describe("getListDiff", () => {
{
ignoreArrayOrder: true,
referenceProperty: "id",
}
)
},
),
).toStrictEqual({
type: "list",
status: "updated",

92
test/object-diff.test.ts

@ -12,8 +12,8 @@ describe("getObjectDiff", () => { @@ -12,8 +12,8 @@ describe("getObjectDiff", () => {
expect(
getObjectDiff(
{ name: "joe", age: 54, hobbies: ["golf", "football"] },
null
)
null,
),
).toStrictEqual({
type: "object",
status: "deleted",
@ -45,7 +45,7 @@ describe("getObjectDiff", () => { @@ -45,7 +45,7 @@ describe("getObjectDiff", () => {
name: "joe",
age: 54,
hobbies: ["golf", "football"],
})
}),
).toStrictEqual({
type: "object",
status: "added",
@ -89,8 +89,8 @@ describe("getObjectDiff", () => { @@ -89,8 +89,8 @@ describe("getObjectDiff", () => {
city: undefined,
hobbies: ["golf", "football"],
options: { vegan: undefined, phone: null },
}
)
},
),
).toStrictEqual({
type: "object",
status: "equal",
@ -156,8 +156,8 @@ describe("getObjectDiff", () => { @@ -156,8 +156,8 @@ describe("getObjectDiff", () => {
hobbies: ["golf", "chess"],
nickname: "super joe",
},
}
)
},
),
).toStrictEqual({
type: "object",
status: "updated",
@ -259,8 +259,8 @@ describe("getObjectDiff", () => { @@ -259,8 +259,8 @@ describe("getObjectDiff", () => {
},
},
},
}
)
},
),
).toStrictEqual({
type: "object",
status: "updated",
@ -387,8 +387,8 @@ describe("getObjectDiff", () => { @@ -387,8 +387,8 @@ describe("getObjectDiff", () => {
nickname: "super joe",
},
},
{ ignoreArrayOrder: true }
)
{ ignoreArrayOrder: true },
),
).toStrictEqual({
type: "object",
status: "updated",
@ -485,8 +485,8 @@ describe("getObjectDiff", () => { @@ -485,8 +485,8 @@ describe("getObjectDiff", () => {
nickname: "super joe",
},
},
{ showOnly: { statuses: ["added"] } }
)
{ showOnly: { statuses: ["added"] } },
),
).toStrictEqual({
type: "object",
status: "updated",
@ -523,8 +523,8 @@ describe("getObjectDiff", () => { @@ -523,8 +523,8 @@ describe("getObjectDiff", () => {
nickname: "super joe",
},
},
{ showOnly: { statuses: ["added", "deleted"], granularity: "deep" } }
)
{ showOnly: { statuses: ["added", "deleted"], granularity: "deep" } },
),
).toStrictEqual({
type: "object",
status: "updated",
@ -608,8 +608,8 @@ describe("getObjectDiff", () => { @@ -608,8 +608,8 @@ describe("getObjectDiff", () => {
statuses: ["updated"],
granularity: "deep",
},
}
)
},
),
).toStrictEqual({
type: "object",
status: "updated",
@ -716,8 +716,8 @@ describe("getObjectDiff", () => { @@ -716,8 +716,8 @@ describe("getObjectDiff", () => {
statuses: ["added"],
granularity: "deep",
},
}
)
},
),
).toStrictEqual({
type: "object",
status: "updated",
@ -803,8 +803,8 @@ describe("getObjectDiff", () => { @@ -803,8 +803,8 @@ describe("getObjectDiff", () => {
age: 54,
hobbies: ["golf", "football"],
},
{ showOnly: { statuses: ["deleted"], granularity: "deep" } }
)
{ showOnly: { statuses: ["deleted"], granularity: "deep" } },
),
).toStrictEqual({
type: "object",
status: "added",
@ -819,8 +819,8 @@ describe("getObjectDiff", () => { @@ -819,8 +819,8 @@ describe("getObjectDiff", () => {
hobbies: ["golf", "football"],
},
null,
{ showOnly: { statuses: ["added"], granularity: "deep" } }
)
{ showOnly: { statuses: ["added"], granularity: "deep" } },
),
).toStrictEqual({
type: "object",
status: "deleted",
@ -831,8 +831,8 @@ describe("getObjectDiff", () => { @@ -831,8 +831,8 @@ describe("getObjectDiff", () => {
getObjectDiff(
{ name: "joe", age: 54, hobbies: ["golf", "football"] },
null,
{ showOnly: { statuses: ["deleted"] } }
)
{ showOnly: { statuses: ["deleted"] } },
),
).toStrictEqual({
type: "object",
status: "deleted",
@ -864,14 +864,15 @@ describe("getObjectDiff", () => { @@ -864,14 +864,15 @@ describe("getObjectDiff", () => {
{
name: "joe",
age: 55,
hobbies: ["golf", "football"]
hobbies: ["golf", "football"],
},
{
name: "joe",
age: 55,
hobbies: null
}))
.toStrictEqual({
hobbies: null,
},
),
).toStrictEqual({
type: "object",
status: "updated",
diff: [
@ -889,30 +890,28 @@ describe("getObjectDiff", () => { @@ -889,30 +890,28 @@ describe("getObjectDiff", () => {
},
{
currentValue: null,
previousValue: [
"golf",
"football",
],
previousValue: ["golf", "football"],
property: "hobbies",
status: "updated",
}
]
})
})
},
],
});
});
it("detects changes when comparing a non-array value property to an array value property", () => {
expect(
getObjectDiff(
{
name: "joe",
age: 55,
hobbies: null
hobbies: null,
},
{
name: "joe",
age: 55,
hobbies: ["golf", "football"]
}))
.toStrictEqual({
hobbies: ["golf", "football"],
},
),
).toStrictEqual({
type: "object",
status: "updated",
diff: [
@ -929,15 +928,12 @@ describe("getObjectDiff", () => { @@ -929,15 +928,12 @@ describe("getObjectDiff", () => {
status: "equal",
},
{
currentValue: [
"golf",
"football",
],
currentValue: ["golf", "football"],
previousValue: null,
property: "hobbies",
status: "updated",
}
]
})
},
],
});
});
});

28
test/utils.test.ts

@ -16,8 +16,8 @@ describe("isEqual", () => { @@ -16,8 +16,8 @@ describe("isEqual", () => {
[
{ name: "joe", age: 99 },
{ name: "nina", age: 23 },
]
)
],
),
).toBeTruthy();
});
it("return false if data are different", () => {
@ -35,8 +35,8 @@ describe("isEqual", () => { @@ -35,8 +35,8 @@ describe("isEqual", () => {
[
{ name: "joe", age: 98 },
{ name: "nina", age: 23 },
]
)
],
),
).toBeFalsy();
expect(isEqual(["psg"], ["psg", "nantes"])).toBeFalsy();
expect(isEqual(null, ["hello", "world"])).toBeFalsy();
@ -46,10 +46,10 @@ describe("isEqual", () => { @@ -46,10 +46,10 @@ describe("isEqual", () => {
expect(
isEqual(["hello", "world"], ["world", "hello"], {
ignoreArrayOrder: true,
})
}),
).toBeTruthy();
expect(
isEqual([44, 45, "world"], [45, "world", 44], { ignoreArrayOrder: true })
isEqual([44, 45, "world"], [45, "world", 44], { ignoreArrayOrder: true }),
).toBeTruthy();
expect(
isEqual(
@ -63,23 +63,23 @@ describe("isEqual", () => { @@ -63,23 +63,23 @@ describe("isEqual", () => {
],
{
ignoreArrayOrder: true,
}
)
},
),
).toBeTruthy();
expect(
isEqual([true, 55, "hello"], ["hello", 55, true], {
ignoreArrayOrder: true,
})
}),
).toBeTruthy();
});
it("return false if ignoreArrayOrder option is activated but the arrays don't contain the same values", () => {
expect(
isEqual(["hello"], ["world", "hello"], {
ignoreArrayOrder: true,
})
}),
).toBeFalsy();
expect(
isEqual([44, 47, "world"], [45, "world", 44], { ignoreArrayOrder: true })
isEqual([44, 47, "world"], [45, "world", 44], { ignoreArrayOrder: true }),
).toBeFalsy();
expect(
isEqual(
@ -93,13 +93,13 @@ describe("isEqual", () => { @@ -93,13 +93,13 @@ describe("isEqual", () => {
],
{
ignoreArrayOrder: true,
}
)
},
),
).toBeFalsy();
expect(
isEqual([false, 55, "hello"], ["hello", 55, true], {
ignoreArrayOrder: true,
})
}),
).toBeFalsy();
});
});

9
tsconfig.json

@ -1,19 +1,20 @@ @@ -1,19 +1,20 @@
{
"exclude": ["node_modules", "dist"],
"include": ["src/*.ts"],
"compilerOptions": {
"declaration": true,
"declarationDir": "./dist",
"lib": ["esnext", "dom"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"noUnusedParameters": true,
"esModuleInterop": true,
"noImplicitAny": true,
"outDir": "./dist",
"strict": true,
"target": "esnext",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"include": ["src/*.ts"],
"exclude": ["node_modules"]
}

2
tsup.config.ts

@ -2,6 +2,8 @@ import { defineConfig } from "tsup"; @@ -2,6 +2,8 @@ import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
format: ["cjs", "esm"],
dts: true,
splitting: true,
clean: true,
treeshake: true,

Loading…
Cancel
Save