Skip to content

Commit c54bccd

Browse files
authored
chore(test): remove redundant onNodeVersions() wrappers (#15119)
1 parent 3206952 commit c54bccd

File tree

4 files changed

+65
-112
lines changed

4 files changed

+65
-112
lines changed

packages/expect/src/__tests__/toThrowMatchers.test.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {alignedAnsiStyleSerializer, onNodeVersions} from '@jest/test-utils';
8+
import {alignedAnsiStyleSerializer} from '@jest/test-utils';
99
import jestExpect from '../';
1010

1111
expect.addSnapshotSerializer(alignedAnsiStyleSerializer);
@@ -302,36 +302,32 @@ describe('toThrow', () => {
302302
}).not.toThrow(expected);
303303
});
304304

305-
onNodeVersions('>=16.9.0', () => {
306-
test('isNot true, incorrect cause', () => {
307-
jestExpect(() => {
308-
throw new Error('good', {cause: errorA});
309-
}).not.toThrow(expected);
310-
});
305+
test('isNot true, incorrect cause', () => {
306+
jestExpect(() => {
307+
throw new Error('good', {cause: errorA});
308+
}).not.toThrow(expected);
311309
});
312310
});
313311

314312
describe('fail', () => {
315-
onNodeVersions('>=16.9.0', () => {
316-
test('isNot false, incorrect message', () => {
317-
expect(() =>
318-
jestExpect(() => {
319-
throw new Error('bad', {cause: errorB});
320-
}).toThrow(expected),
321-
).toThrow(
322-
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
323-
);
324-
});
313+
test('isNot false, incorrect message', () => {
314+
expect(() =>
315+
jestExpect(() => {
316+
throw new Error('bad', {cause: errorB});
317+
}).toThrow(expected),
318+
).toThrow(
319+
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
320+
);
321+
});
325322

326-
test('isNot true, incorrect cause', () => {
327-
expect(() =>
328-
jestExpect(() => {
329-
throw new Error('good', {cause: errorA});
330-
}).toThrow(expected),
331-
).toThrow(
332-
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
333-
);
334-
});
323+
test('isNot true, incorrect cause', () => {
324+
expect(() =>
325+
jestExpect(() => {
326+
throw new Error('good', {cause: errorA});
327+
}).toThrow(expected),
328+
).toThrow(
329+
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
330+
);
335331
});
336332
});
337333
});

packages/jest-message-util/src/__tests__/__snapshots__/messages.test.ts.snap

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,6 @@ exports[`no stack 1`] = `
111111
"
112112
`;
113113
114-
exports[`on node >=15.0.0 should return the inner errors of an AggregateError 1`] = `
115-
" <bold>● </intensity>Test suite failed to run
116-
117-
AggregateError:
118-
119-
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:586:22)</intensity>
120-
121-
Errors contained in AggregateError:
122-
Err 1
123-
124-
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:587:7)</intensity>
125-
126-
Err 2
127-
128-
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:588:7)</intensity>
129-
130-
"
131-
`;
132-
133114
exports[`retains message in babel code frame error 1`] = `
134115
"<bold><red> <bold>● </intensity><bold>Babel test</color></intensity>
135116
@@ -177,12 +158,31 @@ exports[`should return the error cause if there is one 1`] = `
177158
178159
Test exception
179160
180-
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:565:17)</intensity>
161+
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:564:17)</intensity>
181162
182163
Cause:
183164
Cause Error
184165
185-
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:568:17)</intensity>
166+
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:567:17)</intensity>
167+
168+
"
169+
`;
170+
171+
exports[`should return the inner errors of an AggregateError 1`] = `
172+
" <bold>● </intensity>Test suite failed to run
173+
174+
AggregateError:
175+
176+
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:583:20)</intensity>
177+
178+
Errors contained in AggregateError:
179+
Err 1
180+
181+
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:583:40)</intensity>
182+
183+
Err 2
184+
185+
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:583:60)</intensity>
186186
187187
"
188188
`;

packages/jest-message-util/src/__tests__/messages.test.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {readFileSync} from 'graceful-fs';
1010
import slash = require('slash');
1111
import tempy = require('tempy');
12-
import {onNodeVersions} from '@jest/test-utils';
1312
import {
1413
formatExecError,
1514
formatResultsErrors,
@@ -579,24 +578,18 @@ it('should return the error cause if there is one', () => {
579578
expect(message).toMatchSnapshot();
580579
});
581580

582-
// TODO remove this wrapper when the lowest supported Node version is v16
583-
onNodeVersions('>=15.0.0', () => {
584-
it('should return the inner errors of an AggregateError', () => {
585-
// See https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V15.md#v8-86---35415
586-
const aggError = new AggregateError([
587-
new Error('Err 1'),
588-
new Error('Err 2'),
589-
]);
590-
const message = formatExecError(
591-
aggError,
592-
{
593-
rootDir: '',
594-
testMatch: [],
595-
},
596-
{
597-
noStackTrace: false,
598-
},
599-
);
600-
expect(message).toMatchSnapshot();
601-
});
581+
it('should return the inner errors of an AggregateError', () => {
582+
// See https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V15.md#v8-86---35415
583+
const aggError = new AggregateError([new Error('Err 1'), new Error('Err 2')]);
584+
const message = formatExecError(
585+
aggError,
586+
{
587+
rootDir: '',
588+
testMatch: [],
589+
},
590+
{
591+
noStackTrace: false,
592+
},
593+
);
594+
expect(message).toMatchSnapshot();
602595
});

packages/jest-runtime/src/__tests__/runtime_require_module.test.js

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {builtinModules, createRequire} from 'module';
1212
import * as path from 'path';
1313
import {pathToFileURL} from 'url';
1414
import slash from 'slash';
15-
import {onNodeVersions} from '@jest/test-utils';
1615

1716
let createRuntime;
1817

@@ -195,17 +194,15 @@ describe('Runtime requireModule', () => {
195194
}).not.toThrow();
196195
});
197196

198-
onNodeVersions('^16.0.0', () => {
199-
it('finds node core built-in modules with node:prefix', async () => {
200-
const runtime = await createRuntime(__filename);
197+
it('finds node core built-in modules with node:prefix', async () => {
198+
const runtime = await createRuntime(__filename);
201199

202-
expect(runtime.requireModule(runtime.__mockRootPath, 'fs')).toBe(
203-
runtime.requireModule(runtime.__mockRootPath, 'node:fs'),
204-
);
205-
expect(runtime.requireModule(runtime.__mockRootPath, 'module')).toBe(
206-
runtime.requireModule(runtime.__mockRootPath, 'node:module'),
207-
);
208-
});
200+
expect(runtime.requireModule(runtime.__mockRootPath, 'fs')).toBe(
201+
runtime.requireModule(runtime.__mockRootPath, 'node:fs'),
202+
);
203+
expect(runtime.requireModule(runtime.__mockRootPath, 'module')).toBe(
204+
runtime.requireModule(runtime.__mockRootPath, 'node:module'),
205+
);
209206
});
210207

211208
it('finds and loads JSON files without file extension', async () => {
@@ -416,37 +413,4 @@ describe('Runtime requireModule', () => {
416413
expect(exports.syncBuiltinESMExports).not.toThrow();
417414
expect(exports.builtinModules).toEqual(builtinModules);
418415
});
419-
420-
onNodeVersions('<16.0.0', () => {
421-
it('overrides module.createRequireFromPath', async () => {
422-
const runtime = await createRuntime(__filename);
423-
const exports = runtime.requireModule(runtime.__mockRootPath, 'module');
424-
425-
// createRequire with relative module path
426-
expect(() => exports.createRequireFromPath('./relative/path')).toThrow(
427-
new TypeError(
428-
"The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received './relative/path'",
429-
),
430-
);
431-
432-
// createRequireFromPath with absolute module path
433-
{
434-
const customRequire = exports.createRequireFromPath(
435-
runtime.__mockRootPath,
436-
);
437-
expect(customRequire('./create_require_module').foo).toBe('foo');
438-
}
439-
440-
// createRequireFromPath with file URL object
441-
expect(() =>
442-
exports.createRequireFromPath(pathToFileURL(runtime.__mockRootPath)),
443-
).toThrow(
444-
new TypeError(
445-
`The argument 'filename' must be string. Received '${pathToFileURL(
446-
runtime.__mockRootPath,
447-
)}'. Use createRequire for URL filename.`,
448-
),
449-
);
450-
});
451-
});
452416
});

0 commit comments

Comments
 (0)