Skip to content

Commit

Permalink
fix stack traces in tests for node 12
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 19, 2019
1 parent bad6fc0 commit 2c5aeda
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap
Expand Up @@ -16,7 +16,7 @@ FAIL __tests__/defaultTimeoutInterval.test.js
12 | });
13 |
at Object.<anonymous>.test (__tests__/defaultTimeoutInterval.test.js:10:3)
at Object.<anonymous> (__tests__/defaultTimeoutInterval.test.js:10:3)
`;
exports[`fail.test.js errors in errorOnDeprecated mode 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/failures.test.ts.snap
Expand Up @@ -211,7 +211,7 @@ FAIL __tests__/duringTests.test.js
40 |
41 | test('done(non-error)', done => {
at Object.<anonymous>.done (__tests__/duringTests.test.js:38:8)
at Object.<anonymous> (__tests__/duringTests.test.js:38:8)
● done(non-error)
Expand Down
19 changes: 18 additions & 1 deletion e2e/__tests__/errorOnDeprecated.test.ts
Expand Up @@ -32,14 +32,31 @@ const SHOULD_NOT_PASS_IN_JEST = new Set([
'spyOnProperty.test.js',
]);

const nodeMajorVersion = Number(process.versions.node.split('.')[0]);

testFiles.forEach(testFile => {
test(`${testFile} errors in errorOnDeprecated mode`, () => {
const result = runJest('error-on-deprecated', [
testFile,
'--errorOnDeprecated',
]);
expect(result.status).toBe(1);
const {rest} = extractSummary(result.stderr);
let {rest} = extractSummary(result.stderr);

if (
nodeMajorVersion < 12 &&
testFile === 'defaultTimeoutInterval.test.js'
) {
const lineEntry = '(__tests__/defaultTimeoutInterval.test.js:10:3)';

expect(rest).toContain(`at Object.<anonymous>.test ${lineEntry}`);

rest = rest.replace(
`at Object.<anonymous>.test ${lineEntry}`,
`at Object.<anonymous> ${lineEntry}`,
);
}

expect(wrap(rest)).toMatchSnapshot();
});
});
Expand Down
19 changes: 15 additions & 4 deletions e2e/__tests__/failures.test.ts
Expand Up @@ -21,6 +21,8 @@ function cleanStderr(stderr: string) {
.replace(new RegExp('Failed: Object {', 'g'), 'thrown: Object {');
}

const nodeMajorVersion = Number(process.versions.node.split('.')[0]);

beforeAll(() => {
run('yarn', dir);
});
Expand All @@ -36,17 +38,28 @@ test('not throwing Error objects', () => {
stderr = runJest(dir, ['assertionCount.test.js']).stderr;
expect(wrap(cleanStderr(stderr))).toMatchSnapshot();
stderr = runJest(dir, ['duringTests.test.js']).stderr;

if (nodeMajorVersion < 12) {
const lineEntry = '(__tests__/duringTests.test.js:38:8)';

expect(stderr).toContain(`at Object.<anonymous>.done ${lineEntry}`);

stderr = stderr.replace(
`at Object.<anonymous>.done ${lineEntry}`,
`at Object.<anonymous> ${lineEntry}`,
);
}

expect(wrap(cleanStderr(stderr))).toMatchSnapshot();
});

test('works with node assert', () => {
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
const {stderr} = runJest(dir, ['assertionError.test.js']);
let summary = normalizeDots(cleanStderr(stderr));

// Node 9 started to include the error for `doesNotThrow`
// https://github.com/nodejs/node/pull/12167
if (nodeMajorVersion >= 9) {
if (nodeMajorVersion >= 10) {
expect(summary).toContain(`
assert.doesNotThrow(function)
Expand Down Expand Up @@ -91,9 +104,7 @@ test('works with node assert', () => {
expect(summary).toContain(specificErrorMessage);
summary = summary.replace(specificErrorMessage, commonErrorMessage);
}
}

if (nodeMajorVersion >= 10) {
const ifErrorMessage = `
assert.ifError(received, expected)
Expand Down

0 comments on commit 2c5aeda

Please sign in to comment.