Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
test: assertion messages are currently not handled
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Mar 22, 2020
1 parent 07eb848 commit 490a20b
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 16 deletions.
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
testEnvironment: 'node',
snapshotSerializers: [
'pretty-format/build/plugins/ConvertAnsi.js',
]
],
testMatch: ['<rootDir>/test/**/*.spec.ts'],
};
2 changes: 1 addition & 1 deletion lib/tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function translateResult(
context: Context,
builder: BuildTree,
[code, sig]: [number | null, string | null],
) {
): TestResult {
const result = defaultTestResult(context.testPath);

try {
Expand Down
109 changes: 109 additions & 0 deletions test/__snapshots__/assert-render.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`assert rendering handles equal 1`] = `
" ✕ is equal
We failed to fully process the tap output:
name: is equal
diag:
found: false
wanted: true
compare: ===
at:
line: 7
column: 7
file: assertions.test.js
type: Test
stack: |
Test.<anonymous> (assertions.test.js:7:7)
Test.<anonymous> (assertions.test.js:4:11)
Object.<anonymous> (assertions.test.js:3:1)
source: |2
t.notOk(true, 'is notOk');
t.equal(false, true, 'is equal');
------^
t.same(false, true, 'is same');
});
fullname: assertions.test.js assertions equality
"
`;
exports[`assert rendering handles notOk 1`] = `
" ✕ is notOk
We failed to fully process the tap output:
name: is notOk
diag:
at:
line: 6
column: 7
file: assertions.test.js
type: Test
stack: |
Test.<anonymous> (assertions.test.js:6:7)
Test.<anonymous> (assertions.test.js:4:11)
Object.<anonymous> (assertions.test.js:3:1)
source: |2
t.ok(false, 'is ok');
t.notOk(true, 'is notOk');
------^
t.equal(false, true, 'is equal');
t.same(false, true, 'is same');
fullname: assertions.test.js assertions equality
"
`;
exports[`assert rendering handles ok 1`] = `
" ✕ is ok
We failed to fully process the tap output:
name: is ok
diag:
at:
line: 5
column: 7
file: assertions.test.js
type: Test
stack: |
Test.<anonymous> (assertions.test.js:5:7)
Test.<anonymous> (assertions.test.js:4:11)
Object.<anonymous> (assertions.test.js:3:1)
source: |2
await t.test('equality', async (t) => {
t.ok(false, 'is ok');
------^
t.notOk(true, 'is notOk');
t.equal(false, true, 'is equal');
fullname: assertions.test.js assertions equality
"
`;
exports[`assert rendering handles same 1`] = `
" ✕ is same
We failed to fully process the tap output:
name: is same
diag:
diff: |
--- expected
+++ actual
@@ -1,1 +1,1 @@
-true
+false
at:
line: 8
column: 7
file: assertions.test.js
type: Test
stack: |
Test.<anonymous> (assertions.test.js:8:7)
Test.<anonymous> (assertions.test.js:4:11)
Object.<anonymous> (assertions.test.js:3:1)
source: |2
t.equal(false, true, 'is equal');
t.same(false, true, 'is same');
------^
});
fullname: assertions.test.js assertions equality
"
`;
4 changes: 2 additions & 2 deletions test/__snapshots__/error-render.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ exports[`error rendering handles exceptions 1`] = `
</> <gray> 15 | </>}</>
</> <gray> 16 | </></>
<dim>at buggy (</>type-error.js<dim>:14:3)</>
<dim>at Test.<anonymous> (</>type-error.js<dim>:5:3)</>
<dim>at buggy (</>type-error.test.js<dim>:14:3)</>
<dim>at Test.<anonymous> (</>type-error.test.js<dim>:5:3)</>
"
`;
36 changes: 36 additions & 0 deletions test/assert-render.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { testTranslation } from './translate.spec';
import { TestResult } from '@jest/test-result';

describe('assert rendering', () => {
let result: TestResult;
beforeAll(async () => {
result = await testTranslation('./fixtures/assertions.tap');
});

function findAssert(name: string) {
for (const test of result.testResults) {
for (const message of test.failureMessages) {
if (message.split('\n')[0].trim().endsWith(name)) {
return message;
}
}
}
throw new Error('no test result found');
}

it('handles ok', async () => {
expect(findAssert('is ok')).toMatchSnapshot();
});

it('handles notOk', async () => {
expect(findAssert('is notOk')).toMatchSnapshot();
});

it('handles equal', async () => {
expect(findAssert('is equal')).toMatchSnapshot();
});

it('handles same', async () => {
expect(findAssert('is same')).toMatchSnapshot();
});
});
Loading

0 comments on commit 490a20b

Please sign in to comment.