From 7239ea6b84c70ba2894775cf2bd5f6af9791c9c9 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sun, 15 May 2022 11:15:12 +0300 Subject: [PATCH 1/3] fix: failureMessages --- src/toTestResult.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/toTestResult.js b/src/toTestResult.js index 1a9ae8e..2cdd830 100644 --- a/src/toTestResult.js +++ b/src/toTestResult.js @@ -32,7 +32,7 @@ module.exports.toTestResult = ({ return { ancestorTitles: [], duration: test.duration, - failureMessages: [test.errorMessage], + failureMessages: test.errorMessage ? [test.errorMessage] : [], fullName: test.testPath, numPassingAsserts: test.errorMessage ? 1 : 0, status: test.errorMessage ? 'failed' : 'passed', From 36bcd7c09790759e9b245d31c482ad6d8adbeb27 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sun, 15 May 2022 12:46:44 +0300 Subject: [PATCH 2/3] add unit tests --- jest.config.js | 7 +-- src/__tests__/__snapshots__/fail.test.ts.snap | 55 +++++++++++++++++++ src/__tests__/__snapshots__/pass.test.ts.snap | 39 +++++++++++++ src/__tests__/fail.test.ts | 27 +++++++++ src/__tests__/pass.test.ts | 16 ++++++ 5 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 src/__tests__/__snapshots__/fail.test.ts.snap create mode 100644 src/__tests__/__snapshots__/pass.test.ts.snap create mode 100644 src/__tests__/fail.test.ts create mode 100644 src/__tests__/pass.test.ts diff --git a/jest.config.js b/jest.config.js index 55bf77d..7756fbf 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,4 @@ module.exports = { - projects: [ - { - displayName: 'e2e', - testMatch: ['/e2e/*.test.ts'], - }, - ], + testMatch: ['/**/__tests__/*.test.ts', '/e2e/*.test.ts'], testTimeout: 30000, }; diff --git a/src/__tests__/__snapshots__/fail.test.ts.snap b/src/__tests__/__snapshots__/fail.test.ts.snap new file mode 100644 index 0000000..281b679 --- /dev/null +++ b/src/__tests__/__snapshots__/fail.test.ts.snap @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`fails 1`] = ` +Object { + "console": null, + "failureMessage": " ● tsd typecheck + + Argument of type 'number' is not assignable to parameter of type 'string'. + + > 5 | expectType(concat(1, 2)); + | ^ + + at e2e/__fixtures__/js-failing/index.test.ts:5:1", + "numFailingTests": 1, + "numPassingTests": 3, + "numPendingTests": 0, + "numTodoTests": 0, + "perfStats": Object { + "end": 1200, + "start": 0, + }, + "skipped": undefined, + "snapshot": Object { + "added": 0, + "fileDeleted": false, + "matched": 0, + "unchecked": 0, + "unmatched": 0, + "updated": 0, + }, + "sourceMaps": Object {}, + "testExecError": null, + "testFilePath": "/path/to/e2e/__fixtures__/js-failing/index.test.ts", + "testResults": Array [ + Object { + "ancestorTitles": Array [], + "duration": 1200, + "failureMessages": Array [ + " ● tsd typecheck + + Argument of type 'number' is not assignable to parameter of type 'string'. + + > 5 | expectType(concat(1, 2)); + | ^ + + at e2e/__fixtures__/js-failing/index.test.ts:5:1", + ], + "fullName": undefined, + "numPassingAsserts": 1, + "status": "failed", + "title": "tsd typecheck", + }, + ], +} +`; diff --git a/src/__tests__/__snapshots__/pass.test.ts.snap b/src/__tests__/__snapshots__/pass.test.ts.snap new file mode 100644 index 0000000..61a44f4 --- /dev/null +++ b/src/__tests__/__snapshots__/pass.test.ts.snap @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`pass 1`] = ` +Object { + "console": null, + "failureMessage": undefined, + "numFailingTests": 0, + "numPassingTests": 5, + "numPendingTests": 0, + "numTodoTests": 0, + "perfStats": Object { + "end": 1200, + "start": 0, + }, + "skipped": undefined, + "snapshot": Object { + "added": 0, + "fileDeleted": false, + "matched": 0, + "unchecked": 0, + "unmatched": 0, + "updated": 0, + }, + "sourceMaps": Object {}, + "testExecError": null, + "testFilePath": "/path/to/e2e/__fixtures__/js-passing/index.test.ts", + "testResults": Array [ + Object { + "ancestorTitles": Array [], + "duration": 1200, + "failureMessages": Array [], + "fullName": undefined, + "numPassingAsserts": 0, + "status": "passed", + "title": "tsd typecheck", + }, + ], +} +`; diff --git a/src/__tests__/fail.test.ts b/src/__tests__/fail.test.ts new file mode 100644 index 0000000..f011715 --- /dev/null +++ b/src/__tests__/fail.test.ts @@ -0,0 +1,27 @@ +import { expect, test } from '@jest/globals'; +import { fail } from '../fail'; + +const errorMessage = ` ● tsd typecheck + + Argument of type 'number' is not assignable to parameter of type 'string'. + + > 5 | expectType(concat(1, 2)); + | ^ + + at e2e/__fixtures__/js-failing/index.test.ts:5:1`; + +test('fails', () => { + const testResult = fail({ + start: 0, + end: 1200, + test: { + path: '/path/to/e2e/__fixtures__/js-failing/index.test.ts', + title: 'tsd typecheck', + }, + errorMessage, + numFailed: 1, + numPassed: 3, + }); + + expect(testResult).toMatchSnapshot(); +}); diff --git a/src/__tests__/pass.test.ts b/src/__tests__/pass.test.ts new file mode 100644 index 0000000..335fe31 --- /dev/null +++ b/src/__tests__/pass.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from '@jest/globals'; +import { pass } from '../pass'; + +test('pass', () => { + const testResult = pass({ + start: 0, + end: 1200, + test: { + path: '/path/to/e2e/__fixtures__/js-passing/index.test.ts', + title: 'tsd typecheck', + }, + numPassed: 5, + }); + + expect(testResult).toMatchSnapshot(); +}); From 69dc265e230ce20689e9800f140d7f202b1e14a8 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sun, 15 May 2022 12:58:21 +0300 Subject: [PATCH 3/3] add GH reporter --- jest.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.js b/jest.config.js index 7756fbf..ed66a93 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ module.exports = { + reporters: ['default', 'github-actions'], testMatch: ['/**/__tests__/*.test.ts', '/e2e/*.test.ts'], testTimeout: 30000, };