From 166b8865810275aa581b9389773909e309ca1d6e Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 10 Mar 2023 12:39:16 +0100 Subject: [PATCH 1/3] using jest-expect-message to add custom error message --- jest.config.js | 1 + package.json | 1 + packages/nodes-base/test/nodes/Helpers.ts | 4 +++- pnpm-lock.yaml | 6 ++++++ tsconfig.json | 3 ++- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jest.config.js b/jest.config.js index 6aefc55ee1251..4ffe0bc85e71d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -22,6 +22,7 @@ const config = { moduleNameMapper: { '^@/(.*)$': '/src/$1', }, + setupFilesAfterEnv: ['jest-expect-message'], }; if (process.env.CI === 'true') { diff --git a/package.json b/package.json index 2531a535203ae..bb02cb576abc2 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "cypress-real-events": "^1.7.6", "jest": "^29.4.2", "jest-environment-jsdom": "^29.4.2", + "jest-expect-message": "^1.1.3", "jest-mock": "^29.4.2", "jest-mock-extended": "^3.0.1", "nock": "^13.2.9", diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 83fb957b2ee11..5e1c3c3d71ce1 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -247,7 +247,9 @@ export const equalityTest = async (testData: WorkflowTestData, types: INodeTypes const resultNodeData = getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => { - return expect(resultData).toEqual(testData.output.nodeData[nodeName]); + return expect(resultData, `Equality test failed for node "${nodeName}"`).toEqual( + testData.output.nodeData[nodeName], + ); }); expect(result.finished).toEqual(true); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a8ad959f0664..b95261280eb86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,7 @@ importers: cypress-real-events: ^1.7.6 jest: ^29.4.2 jest-environment-jsdom: ^29.4.2 + jest-expect-message: ^1.1.3 jest-mock: ^29.4.2 jest-mock-extended: ^3.0.1 n8n: workspace:* @@ -64,6 +65,7 @@ importers: cypress-real-events: 1.7.6_cypress@12.7.0 jest: 29.4.2 jest-environment-jsdom: 29.4.2 + jest-expect-message: 1.1.3 jest-mock: 29.4.2 jest-mock-extended: 3.0.1_gelezmms3va3pnkofxaadhcvma nock: 13.2.9 @@ -13362,6 +13364,10 @@ packages: jest-util: 29.4.2 dev: true + /jest-expect-message/1.1.3: + resolution: {integrity: sha512-bTK77T4P+zto+XepAX3low8XVQxDgaEqh3jSTQOG8qvPpD69LsIdyJTa+RmnJh3HNSzJng62/44RPPc7OIlFxg==} + dev: true + /jest-get-type/29.2.0: resolution: {integrity: sha512-uXNJlg8hKFEnDgFsrCjznB+sTxdkuqiCL6zMgA75qEbAJjJYTs9XPrvDctrEig2GDow22T/LvHgO57iJhXB/UA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} diff --git a/tsconfig.json b/tsconfig.json index 986eb63ac6550..0f396ac22e990 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,5 +20,6 @@ "sourceMap": true, "skipLibCheck": true }, - "exclude": ["**/dist/**/*", "**/node_modules/**/*"] + "exclude": ["**/dist/**/*", "**/node_modules/**/*"], + "files": ["node_modules/jest-expect-message/types/index.d.ts"] } From 54ec51b147e2905794c93f3127a958bb29b26903 Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 10 Mar 2023 15:16:34 +0100 Subject: [PATCH 2/3] improve error message --- packages/nodes-base/test/nodes/Helpers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 5e1c3c3d71ce1..e0611deeb80ee 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -245,11 +245,11 @@ export const equalityTest = async (testData: WorkflowTestData, types: INodeTypes // check if result node data matches expected test data const resultNodeData = getResultNodeData(result, testData); - resultNodeData.forEach(({ nodeName, resultData }) => { - return expect(resultData, `Equality test failed for node "${nodeName}"`).toEqual( - testData.output.nodeData[nodeName], - ); + return expect( + resultData, + `Equality failed for "${testData.description}" at node "${nodeName}"`, + ).toEqual(testData.output.nodeData[nodeName]); }); expect(result.finished).toEqual(true); From 1e0245ccd358dd6beddcd91bd1ec922828a0db02 Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 5 May 2023 12:44:23 +0200 Subject: [PATCH 3/3] improvements after merge --- jest.config.js | 1 + package.json | 1 + packages/nodes-base/test/nodes/Helpers.ts | 6 ++--- pnpm-lock.yaml | 27 ++++++++++++++--------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/jest.config.js b/jest.config.js index e34e01fa22e7c..729d2d3a59d5a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -22,6 +22,7 @@ const config = { moduleNameMapper: { '^@/(.*)$': '/src/$1', }, + setupFilesAfterEnv: ['jest-expect-message'], collectCoverage: true, coverageReporters: [process.env.COVERAGE_REPORT === 'true' ? 'text' : 'text-summary'], collectCoverageFrom: ['src/**/*.ts'], diff --git a/package.json b/package.json index 9d47f412cbb2b..f3117e3b155c5 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "cypress-real-events": "^1.7.6", "jest": "^29.5.0", "jest-environment-jsdom": "^29.5.0", + "jest-expect-message": "^1.1.3", "jest-mock": "^29.5.0", "jest-mock-extended": "^3.0.4", "nock": "^13.2.9", diff --git a/packages/nodes-base/test/nodes/Helpers.ts b/packages/nodes-base/test/nodes/Helpers.ts index 2f688a54586e0..2ef784be0925a 100644 --- a/packages/nodes-base/test/nodes/Helpers.ts +++ b/packages/nodes-base/test/nodes/Helpers.ts @@ -319,10 +319,8 @@ export const equalityTest = async (testData: WorkflowTestData, types: INodeTypes // check if result node data matches expected test data const resultNodeData = getResultNodeData(result, testData); resultNodeData.forEach(({ nodeName, resultData }) => { - return expect( - resultData, - `Equality failed for "${testData.description}" at node "${nodeName}"`, - ).toEqual(testData.output.nodeData[nodeName]); + const msg = `Equality failed for "${testData.description}" at node "${nodeName}"`; + return expect(resultData, msg).toEqual(testData.output.nodeData[nodeName]); }); expect(result.finished).toEqual(true); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8e8ba5e779f12..64008f00c5a86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -71,6 +71,9 @@ importers: jest-environment-jsdom: specifier: ^29.5.0 version: 29.5.0 + jest-expect-message: + specifier: ^1.1.3 + version: 1.1.3 jest-mock: specifier: ^29.5.0 version: 29.5.0 @@ -11646,7 +11649,6 @@ packages: dependencies: ms: 2.1.3 supports-color: 5.5.0 - dev: true /debug@3.2.7(supports-color@8.1.1): resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} @@ -11658,6 +11660,7 @@ packages: dependencies: ms: 2.1.3 supports-color: 8.1.1 + dev: true /debug@4.3.2: resolution: {integrity: sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==} @@ -12568,7 +12571,7 @@ packages: /eslint-import-resolver-node@0.3.7: resolution: {integrity: sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) is-core-module: 2.11.0 resolve: 1.22.1 transitivePeerDependencies: @@ -12621,7 +12624,7 @@ packages: optional: true dependencies: '@typescript-eslint/parser': 5.59.0(eslint@8.39.0)(typescript@5.0.3) - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) eslint: 8.39.0 eslint-import-resolver-node: 0.3.7 eslint-import-resolver-typescript: 3.5.5(@typescript-eslint/parser@5.59.0)(eslint-plugin-import@2.27.5)(eslint@8.39.0) @@ -12652,7 +12655,7 @@ packages: array-includes: 3.1.6 array.prototype.flat: 1.3.1 array.prototype.flatmap: 1.3.1 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) doctrine: 2.1.0 eslint: 8.39.0 eslint-import-resolver-node: 0.3.7 @@ -13535,7 +13538,7 @@ packages: debug: optional: true dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) dev: false /follow-redirects@1.15.2(debug@4.3.2): @@ -14126,7 +14129,7 @@ packages: array-parallel: 0.1.3 array-series: 0.1.5 cross-spawn: 4.0.2 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: false @@ -14242,7 +14245,6 @@ packages: /has-flag@3.0.0: resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==} engines: {node: '>=4'} - dev: true /has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} @@ -15496,6 +15498,10 @@ packages: jest-util: 29.5.0 dev: true + /jest-expect-message@1.1.3: + resolution: {integrity: sha512-bTK77T4P+zto+XepAX3low8XVQxDgaEqh3jSTQOG8qvPpD69LsIdyJTa+RmnJh3HNSzJng62/44RPPc7OIlFxg==} + dev: true + /jest-get-type@29.2.0: resolution: {integrity: sha512-uXNJlg8hKFEnDgFsrCjznB+sTxdkuqiCL6zMgA75qEbAJjJYTs9XPrvDctrEig2GDow22T/LvHgO57iJhXB/UA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -18632,7 +18638,7 @@ packages: resolution: {integrity: sha512-v6ZJ/efsBpGrGGknjtq9J/oC8tZWq0KWL5vQrk2GlzLEQPUDB1ex+13Rmidl1neNN358Jn9EHZw5y07FFtaC7A==} engines: {node: '>=6.8.1'} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) node-ensure: 0.0.0 transitivePeerDependencies: - supports-color @@ -20118,7 +20124,7 @@ packages: /rhea@1.0.24: resolution: {integrity: sha512-PEl62U2EhxCO5wMUZ2/bCBcXAVKN9AdMSNQOrp3+R5b77TEaOSiy16MQ0sIOmzj/iqsgIAgPs1mt3FYfu1vIXA==} dependencies: - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) transitivePeerDependencies: - supports-color dev: false @@ -20738,7 +20744,7 @@ packages: bignumber.js: 2.4.0 binascii: 0.0.2 browser-request: 0.3.3 - debug: 3.2.7(supports-color@8.1.1) + debug: 3.2.7(supports-color@5.5.0) expand-tilde: 2.0.2 extend: 3.0.2 generic-pool: 3.9.0 @@ -21390,7 +21396,6 @@ packages: engines: {node: '>=4'} dependencies: has-flag: 3.0.0 - dev: true /supports-color@6.1.0: resolution: {integrity: sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==}