Skip to content

Commit

Permalink
chore: remove obsolete test conditions for old versions of node (#10712)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 26, 2020
1 parent 2dafb09 commit 6dda424
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 112 deletions.
25 changes: 25 additions & 0 deletions e2e/__tests__/__snapshots__/failures.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,30 @@ FAIL __tests__/assertionError.test.js
assert.ifError
assert.ifError(received, expected)
Expected value ifError to:
null
Received:
1
Message:
ifError got unwanted exception: 1
Difference:
Comparing two different types of values. Expected null but received number.
64 |
65 | test('assert.ifError', () => {
> 66 | assert.ifError(1);
| ^
67 | });
68 |
69 | test('assert.doesNotThrow', () => {
at Object.ifError (__tests__/assertionError.test.js:66:10)
assert.doesNotThrow
assert.doesNotThrow(function)
Expand All @@ -716,6 +740,7 @@ FAIL __tests__/assertionError.test.js
Message:
Got unwanted exception.
Actual message: "err!"
68 |
69 | test('assert.doesNotThrow', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/v8Coverage.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`on node >=10 prints coverage 1`] = `
exports[`prints coverage 1`] = `
" console.log
42
Expand Down
97 changes: 1 addition & 96 deletions e2e/__tests__/failures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,102 +55,7 @@ test('not throwing Error objects', () => {

test('works with node assert', () => {
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 >= 10) {
expect(summary).toContain(`
assert.doesNotThrow(function)
Expected the function not to throw an error.
Instead, it threw:
[Error: err!]
Message:
Got unwanted exception.
`);

expect(summary).toContain(`
68 |
69 | test('assert.doesNotThrow', () => {
> 70 | assert.doesNotThrow(() => {
| ^
71 | throw Error('err!');
72 | });
73 | });
at Object.doesNotThrow (__tests__/assertionError.test.js:70:10)
`);

const commonErrorMessage = `Message:
Got unwanted exception.
`;

if (nodeMajorVersion === 9) {
const specificErrorMessage = `Message:
Got unwanted exception.
err!
`;

expect(summary).toContain(specificErrorMessage);
summary = summary.replace(specificErrorMessage, commonErrorMessage);
} else {
const specificErrorMessage = `Message:
Got unwanted exception.
Actual message: "err!"
`;

expect(summary).toContain(specificErrorMessage);
summary = summary.replace(specificErrorMessage, commonErrorMessage);
}

const ifErrorMessage = `
assert.ifError(received, expected)
Expected value ifError to:
null
Received:
1
Message:
ifError got unwanted exception: 1
Difference:
Comparing two different types of values. Expected null but received number.
64 |
65 | test('assert.ifError', () => {
> 66 | assert.ifError(1);
| ^
67 | });
68 |
69 | test('assert.doesNotThrow', () => {
at Object.ifError (__tests__/assertionError.test.js:66:10)
`;

expect(summary).toContain(ifErrorMessage);
summary = summary.replace(ifErrorMessage, '');
} else {
const ifErrorMessage = `
thrown: 1
63 | });
64 |
> 65 | test('assert.ifError', () => {
| ^
66 | assert.ifError(1);
67 | });
68 |
at Object.test (__tests__/assertionError.test.js:65:1)
`;

expect(summary).toContain(ifErrorMessage);
summary = summary.replace(ifErrorMessage, '');
}
const summary = normalizeDots(cleanStderr(stderr));

expect(wrap(summary)).toMatchSnapshot();
});
Expand Down
23 changes: 9 additions & 14 deletions e2e/__tests__/v8Coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@
*/

import * as path from 'path';
import {onNodeVersions} from '@jest/test-utils';
import runJest from '../runJest';

const DIR = path.resolve(__dirname, '../v8-coverage');

onNodeVersions('>=10', () => {
test('prints coverage', () => {
const sourcemapDir = path.join(DIR, 'no-sourcemap');
test('prints coverage', () => {
const sourcemapDir = path.join(DIR, 'no-sourcemap');

const {stdout, exitCode} = runJest(
sourcemapDir,
['--coverage', '--coverage-provider', 'v8'],
{
stripAnsi: true,
},
);
const {stdout, exitCode} = runJest(
sourcemapDir,
['--coverage', '--coverage-provider', 'v8'],
{stripAnsi: true},
);

expect(exitCode).toBe(0);
expect(stdout).toMatchSnapshot();
});
expect(exitCode).toBe(0);
expect(stdout).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"test-leak": "yarn jest -i --detectLeaks jest-mock jest-diff jest-repl pretty-format",
"test": "yarn lint && yarn jest",
"verify-old-ts": "node ./scripts/verifyOldTs.js",
"watch": "yarn build && node ./scripts/watch.js",
"watch": "yarn build:js && node ./scripts/watch.js",
"watch:ts": "yarn build:ts --watch"
},
"workspaces": [
Expand Down

0 comments on commit 6dda424

Please sign in to comment.