diff --git a/jest.config.js b/jest.config.js index 55bf77d..ed66a93 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,5 @@ module.exports = { - projects: [ - { - displayName: 'e2e', - testMatch: ['/e2e/*.test.ts'], - }, - ], + reporters: ['default', 'github-actions'], + 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(); +}); 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',