From 2c5aeda80108d4b4adbb0269ec26635de4570f42 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 19 Aug 2019 14:47:51 +0200 Subject: [PATCH] fix stack traces in tests for node 12 --- .../errorOnDeprecated.test.ts.snap | 2 +- .../__snapshots__/failures.test.ts.snap | 2 +- e2e/__tests__/errorOnDeprecated.test.ts | 19 ++++++++++++++++++- e2e/__tests__/failures.test.ts | 19 +++++++++++++++---- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap b/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap index 9ca3c1100c97..613a80ca77b8 100644 --- a/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap +++ b/e2e/__tests__/__snapshots__/errorOnDeprecated.test.ts.snap @@ -16,7 +16,7 @@ FAIL __tests__/defaultTimeoutInterval.test.js 12 | }); 13 | - at Object..test (__tests__/defaultTimeoutInterval.test.js:10:3) + at Object. (__tests__/defaultTimeoutInterval.test.js:10:3) `; exports[`fail.test.js errors in errorOnDeprecated mode 1`] = ` diff --git a/e2e/__tests__/__snapshots__/failures.test.ts.snap b/e2e/__tests__/__snapshots__/failures.test.ts.snap index a2e434a385c4..02d7fa1921df 100644 --- a/e2e/__tests__/__snapshots__/failures.test.ts.snap +++ b/e2e/__tests__/__snapshots__/failures.test.ts.snap @@ -211,7 +211,7 @@ FAIL __tests__/duringTests.test.js 40 | 41 | test('done(non-error)', done => { - at Object..done (__tests__/duringTests.test.js:38:8) + at Object. (__tests__/duringTests.test.js:38:8) ● done(non-error) diff --git a/e2e/__tests__/errorOnDeprecated.test.ts b/e2e/__tests__/errorOnDeprecated.test.ts index f13846fd7ae8..5eae6b117a23 100644 --- a/e2e/__tests__/errorOnDeprecated.test.ts +++ b/e2e/__tests__/errorOnDeprecated.test.ts @@ -32,6 +32,8 @@ 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', [ @@ -39,7 +41,22 @@ testFiles.forEach(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..test ${lineEntry}`); + + rest = rest.replace( + `at Object..test ${lineEntry}`, + `at Object. ${lineEntry}`, + ); + } + expect(wrap(rest)).toMatchSnapshot(); }); }); diff --git a/e2e/__tests__/failures.test.ts b/e2e/__tests__/failures.test.ts index 9b38aa04d35e..dd7aec60d2ee 100644 --- a/e2e/__tests__/failures.test.ts +++ b/e2e/__tests__/failures.test.ts @@ -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); }); @@ -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..done ${lineEntry}`); + + stderr = stderr.replace( + `at Object..done ${lineEntry}`, + `at Object. ${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) @@ -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)