Skip to content

Commit

Permalink
fix: avoid returning failureMessages: [undefined] (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed May 15, 2022
1 parent 60bc054 commit 05f8f8f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 7 deletions.
8 changes: 2 additions & 6 deletions jest.config.js
@@ -1,9 +1,5 @@
module.exports = {
projects: [
{
displayName: 'e2e',
testMatch: ['<rootDir>/e2e/*.test.ts'],
},
],
reporters: ['default', 'github-actions'],
testMatch: ['<rootDir>/**/__tests__/*.test.ts', '<rootDir>/e2e/*.test.ts'],
testTimeout: 30000,
};
55 changes: 55 additions & 0 deletions 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<string>(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<string>(concat(1, 2));
| ^
at e2e/__fixtures__/js-failing/index.test.ts:5:1",
],
"fullName": undefined,
"numPassingAsserts": 1,
"status": "failed",
"title": "tsd typecheck",
},
],
}
`;
39 changes: 39 additions & 0 deletions 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",
},
],
}
`;
27 changes: 27 additions & 0 deletions 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<string>(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();
});
16 changes: 16 additions & 0 deletions 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();
});
2 changes: 1 addition & 1 deletion src/toTestResult.js
Expand Up @@ -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',
Expand Down

0 comments on commit 05f8f8f

Please sign in to comment.