Skip to content

Commit 6c83c0f

Browse files
authored
chore: use numeric separators (#14570)
1 parent 769ee6e commit 6c83c0f

File tree

60 files changed

+107
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+107
-104
lines changed

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ module.exports = {
599599
'unicorn/explicit-length-check': 'error',
600600
'unicorn/no-array-for-each': 'error',
601601
'unicorn/no-negated-condition': 'error',
602+
'unicorn/numeric-separators-style': 'error',
602603
'unicorn/prefer-default-parameters': 'error',
603604
'unicorn/prefer-includes': 'error',
604605
'unicorn/template-indent': 'error',

docs/MockFunctionAPI.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ afterEach(() => {
746746
});
747747

748748
test('renders correctly with a given date', () => {
749-
spiedDateNow = setDateNow(1482363367071);
749+
spiedDateNow = setDateNow(1_482_363_367_071);
750750
// ...
751751

752752
expect(spiedDateNow).toHaveBeenCalledTimes(1);

docs/SnapshotTesting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Your tests should be deterministic. Running the same tests multiple times on a c
255255
For example, if you have a [Clock](https://github.com/jestjs/jest/blob/main/examples/snapshot/Clock.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run:
256256

257257
```js
258-
Date.now = jest.fn(() => 1482363367071);
258+
Date.now = jest.fn(() => 1_482_363_367_071);
259259
```
260260

261261
Now, every time the snapshot test case runs, `Date.now()` will return `1482363367071` consistently. This will result in the same snapshot being generated for this component regardless of when the test is run.

docs/Troubleshooting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Most commonly this is being caused by conflicting Promise implementations. Consi
150150
If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout`
151151

152152
```js
153-
jest.setTimeout(10000); // 10 second timeout
153+
jest.setTimeout(10_000); // 10 second timeout
154154
```
155155

156156
## Watchman Issues

e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports[`prints out info about open handlers from inside tests 1`] = `
3838
3939
7 |
4040
8 | test('something', () => {
41-
> 9 | setTimeout(() => {}, 30000);
41+
> 9 | setTimeout(() => {}, 30_000);
4242
| ^
4343
10 | expect(true).toBe(true);
4444
11 | });
@@ -54,7 +54,7 @@ exports[`prints out info about open handlers from lifecycle functions with a \`d
5454
5555
7 |
5656
8 | beforeAll(done => {
57-
> 9 | setTimeout(() => {}, 10000);
57+
> 9 | setTimeout(() => {}, 10_000);
5858
| ^
5959
10 | done();
6060
11 | });
@@ -70,7 +70,7 @@ exports[`prints out info about open handlers from tests with a \`done\` callback
7070
7171
7 |
7272
8 | test('something', done => {
73-
> 9 | setTimeout(() => {}, 10000);
73+
> 9 | setTimeout(() => {}, 10_000);
7474
| ^
7575
10 | expect(true).toBe(true);
7676
11 | done();

e2e/__tests__/complexItemsInErrors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test('handles functions that close over outside variables', async () => {
5050
tempDir,
5151
['--no-watchman', '--watch-all'],
5252
// timeout in case the `waitUntil` below doesn't fire
53-
{stripAnsi: true, timeout: 10000},
53+
{stripAnsi: true, timeout: 10_000},
5454
);
5555

5656
await waitUntil(({stderr}) => stderr.includes('Ran all test suites.'));

e2e/__tests__/customReporters.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('Custom Reporters Integration', () => {
4949

5050
test('invalid format for adding reporters', () => {
5151
const reporterConfig = {
52-
reporters: [[3243242]],
52+
reporters: [[3_243_242]],
5353
};
5454

5555
const {exitCode, stderr} = runJest('custom-reporters', [

e2e/__tests__/watchModeNoAccess.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test('does not re-run tests when only access time is modified', async () => {
7171
await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 2);
7272

7373
// Should NOT re-run the test
74-
const fakeATime = 1541723621;
74+
const fakeATime = 1_541_723_621;
7575
fs.utimesSync(
7676
modulePath,
7777
getOneSecondAfterMs(fakeATime),

e2e/__tests__/workerForceExit.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ test('force exits a worker that fails to exit gracefully', async () => {
7676
expect(pidNumber).not.toBeNaN();
7777

7878
expect(await findProcess('pid', pidNumber)).toHaveLength(0);
79-
}, 15000);
79+
}, 15_000);

e2e/detect-open-handles/__tests__/in-done-function.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
test('something', done => {
9-
setTimeout(() => {}, 10000);
9+
setTimeout(() => {}, 10_000);
1010
expect(true).toBe(true);
1111
done();
1212
});

e2e/detect-open-handles/__tests__/in-done-lifecycle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
beforeAll(done => {
9-
setTimeout(() => {}, 10000);
9+
setTimeout(() => {}, 10_000);
1010
done();
1111
});
1212

e2e/detect-open-handles/__tests__/inside.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
*/
77

88
test('something', () => {
9-
setTimeout(() => {}, 30000);
9+
setTimeout(() => {}, 30_000);
1010
expect(true).toBe(true);
1111
});

e2e/detect-open-handles/__tests__/unref.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
test('something', () => {
9-
const timeout = setTimeout(() => {}, 30000);
9+
const timeout = setTimeout(() => {}, 30_000);
1010
timeout.unref();
1111
expect(true).toBe(true);
1212
});

e2e/fake-timers/advance-timers/__tests__/advanceTimers.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('advances timers if a number is passed', done => {
3232
test('works with `now` option', done => {
3333
jest.useFakeTimers({advanceTimers: 30, now: new Date('2015-09-25')});
3434

35-
expect(Date.now()).toBe(1443139200000);
35+
expect(Date.now()).toBe(1_443_139_200_000);
3636

3737
const start = Date.now();
3838

e2e/runJest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const runContinuous = function (
172172
args?: Array<string>,
173173
options: RunJestOptions = {},
174174
) {
175-
const jestPromise = spawnJest(dir, args, {timeout: 30000, ...options}, true);
175+
const jestPromise = spawnJest(dir, args, {timeout: 30_000, ...options}, true);
176176

177177
let stderr = '';
178178
let stdout = '';

examples/react-native/__tests__/intro.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {ActivityIndicator, FlatList, Text, TextInput} from 'react-native';
99
import renderer from 'react-test-renderer';
1010
import Intro from '../Intro';
1111

12-
jest.setTimeout(15000);
12+
jest.setTimeout(15_000);
1313

1414
it('renders correctly', () => {
1515
const tree = renderer.create(<Intro />).toJSON();

examples/snapshot/__tests__/clock.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import renderer from 'react-test-renderer';
66
import Clock from '../Clock';
77

8-
jest.useFakeTimers().setSystemTime(1482363367071);
8+
jest.useFakeTimers().setSystemTime(1_482_363_367_071);
99

1010
it('renders correctly', () => {
1111
const testRenderer = renderer.create(<Clock />);

examples/timer/__tests__/infinite_timer_game.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ it('schedules a 10-second timer after 1 second', () => {
2626
// And it should have created a new timer to start the game over in
2727
// 10 seconds
2828
expect(setTimeout).toHaveBeenCalledTimes(2);
29-
expect(setTimeout).toHaveBeenNthCalledWith(2, expect.any(Function), 10000);
29+
expect(setTimeout).toHaveBeenNthCalledWith(2, expect.any(Function), 10_000);
3030
});

examples/timer/infiniteTimerGame.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function infiniteTimerGame(callback) {
1010
// Schedule the next game in 10 seconds
1111
setTimeout(() => {
1212
infiniteTimerGame(callback);
13-
}, 10000);
13+
}, 10_000);
1414
}, 1000);
1515
}
1616

jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default {
6666
'/e2e/__tests__/iterator-to-null-test.ts',
6767
'/e2e/__tests__/tsIntegration.test.ts', // this test needs types to be build, it runs in a separate CI job through `jest.config.ts.mjs`
6868
],
69-
testTimeout: 70000,
69+
testTimeout: 70_000,
7070
transform: {
7171
'\\.[jt]sx?$': require.resolve('babel-jest'),
7272
},

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ describe('closeTo', () => {
430430
for (const [expected, received] of [
431431
[0, 0.01],
432432
[1, 1.23],
433-
[1.23, 1.2249999],
433+
[1.23, 1.224_999_9],
434434
[Infinity, -Infinity],
435435
[Infinity, 1.23],
436436
[-Infinity, -1.23],
@@ -446,8 +446,8 @@ describe('closeTo', () => {
446446
for (const [expected, received, precision] of [
447447
[0, 0.1, 0],
448448
[0, 0.0001, 3],
449-
[0, 0.000004, 5],
450-
[2.0000002, 2, 5],
449+
[0, 0.000_004, 5],
450+
[2.000_000_2, 2, 5],
451451
]) {
452452
test(`${expected} closeTo ${received} with precision ${precision} return true`, () => {
453453
jestExpect(closeTo(expected, precision).asymmetricMatch(received)).toBe(
@@ -462,8 +462,8 @@ describe('closeTo', () => {
462462
}
463463

464464
for (const [expected, received, precision] of [
465-
[3.141592e-7, 3e-7, 8],
466-
[56789, 51234, -4],
465+
[3.141_592e-7, 3e-7, 8],
466+
[56_789, 51_234, -4],
467467
]) {
468468
test(`${expected} closeTo ${received} with precision ${precision} return false`, () => {
469469
jestExpect(closeTo(expected, precision).asymmetricMatch(received)).toBe(

packages/expect/src/__tests__/matchers.test.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ describe('.toEqual()', () => {
666666
[, , 2, ,],
667667
],
668668
[
669-
Object.assign([], {4294967295: 1}),
670-
Object.assign([], {4294967295: 2}), // issue 11056
669+
Object.assign([], {4_294_967_295: 1}),
670+
Object.assign([], {4_294_967_295: 2}), // issue 11056
671671
],
672672
[
673673
// eslint-disable-next-line no-useless-computed-key
@@ -1658,7 +1658,7 @@ describe('.toBeCloseTo', () => {
16581658
for (const [n1, n2] of [
16591659
[0, 0.01],
16601660
[1, 1.23],
1661-
[1.23, 1.2249999],
1661+
[1.23, 1.224_999_9],
16621662
[Infinity, -Infinity],
16631663
[Infinity, 1.23],
16641664
[-Infinity, -1.23],
@@ -1673,8 +1673,8 @@ describe('.toBeCloseTo', () => {
16731673
}
16741674

16751675
for (const [n1, n2, p] of [
1676-
[3.141592e-7, 3e-7, 8],
1677-
[56789, 51234, -4],
1676+
[3.141_592e-7, 3e-7, 8],
1677+
[56_789, 51_234, -4],
16781678
]) {
16791679
it(`{pass: false} expect(${n1}).toBeCloseTo(${n2}, ${p})`, () => {
16801680
jestExpect(n1).not.toBeCloseTo(n2, p);
@@ -1688,8 +1688,8 @@ describe('.toBeCloseTo', () => {
16881688
for (const [n1, n2, p] of [
16891689
[0, 0.1, 0],
16901690
[0, 0.0001, 3],
1691-
[0, 0.000004, 5],
1692-
[2.0000002, 2, 5],
1691+
[0, 0.000_004, 5],
1692+
[2.000_000_2, 2, 5],
16931693
]) {
16941694
it(`{pass: true} expect(${n1}).toBeCloseTo(${n2}, ${p})`, () => {
16951695
jestExpect(n1).toBeCloseTo(n2, p);

packages/jest-config/src/ValidConfig.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const initialOptions: Config.InitialOptions = {
6767
],
6868
enableGlobally: true,
6969
legacyFakeTimers: false,
70-
now: 1483228800000,
70+
now: 1_483_228_800_000,
7171
timerLimit: 1000,
7272
},
7373
filter: '<rootDir>/filter.js',
@@ -231,7 +231,7 @@ export const initialProjectOptions: Config.InitialProjectOptions = {
231231
],
232232
enableGlobally: true,
233233
legacyFakeTimers: false,
234-
now: 1483228800000,
234+
now: 1_483_228_800_000,
235235
timerLimit: 1000,
236236
},
237237
filter: '<rootDir>/filter.js',

packages/jest-config/src/__tests__/normalize.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ it('keeps custom ids based on the rootDir', async () => {
132132

133133
it('minimal config is stable across runs', async () => {
134134
const firstNormalization = await normalize({rootDir: '/root/path/foo'}, {
135-
seed: 55555,
135+
seed: 55_555,
136136
} as Config.Argv);
137137
const secondNormalization = await normalize({rootDir: '/root/path/foo'}, {
138-
seed: 55555,
138+
seed: 55_555,
139139
} as Config.Argv);
140140

141141
expect(firstNormalization).toEqual(secondNormalization);
@@ -2130,7 +2130,7 @@ it('parses workerIdleMemoryLimit', async () => {
21302130
{} as Config.Argv,
21312131
);
21322132

2133-
expect(options.workerIdleMemoryLimit).toBe(47185920);
2133+
expect(options.workerIdleMemoryLimit).toBe(47_185_920);
21342134
});
21352135

21362136
describe('seed', () => {

packages/jest-config/src/__tests__/readConfigFileAndSetRootDir.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ describe('readConfigFileAndSetRootDir', () => {
4141
test('handles exported async function', async () => {
4242
jest
4343
.mocked(requireOrImportModule)
44-
.mockResolvedValueOnce(async () => ({testTimeout: 10000}));
44+
.mockResolvedValueOnce(async () => ({testTimeout: 10_000}));
4545

4646
const rootDir = path.resolve('some', 'path', 'to');
4747
const config = await readConfigFileAndSetRootDir(
4848
path.join(rootDir, 'jest.config.js'),
4949
);
5050

51-
expect(config).toEqual({rootDir, testTimeout: 10000});
51+
expect(config).toEqual({rootDir, testTimeout: 10_000});
5252
});
5353
});
5454

packages/jest-config/src/__tests__/stringToBytes.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -76,43 +76,43 @@ describe('string input', () => {
7676
// The units caps is intentionally janky to test for forgiving string parsing.
7777
describe('k', () => {
7878
test('30k', () => {
79-
expect(stringToBytes('30K')).toBe(30000);
79+
expect(stringToBytes('30K')).toBe(30_000);
8080
});
8181

8282
test('30KB', () => {
83-
expect(stringToBytes('30kB')).toBe(30000);
83+
expect(stringToBytes('30kB')).toBe(30_000);
8484
});
8585

8686
test('30KiB', () => {
87-
expect(stringToBytes('30kIb')).toBe(30720);
87+
expect(stringToBytes('30kIb')).toBe(30_720);
8888
});
8989
});
9090

9191
describe('m', () => {
9292
test('30M', () => {
93-
expect(stringToBytes('30M')).toBe(30000000);
93+
expect(stringToBytes('30M')).toBe(30_000_000);
9494
});
9595

9696
test('30MB', () => {
97-
expect(stringToBytes('30MB')).toBe(30000000);
97+
expect(stringToBytes('30MB')).toBe(30_000_000);
9898
});
9999

100100
test('30MiB', () => {
101-
expect(stringToBytes('30MiB')).toBe(31457280);
101+
expect(stringToBytes('30MiB')).toBe(31_457_280);
102102
});
103103
});
104104

105105
describe('g', () => {
106106
test('30G', () => {
107-
expect(stringToBytes('30G')).toBe(30000000000);
107+
expect(stringToBytes('30G')).toBe(30_000_000_000);
108108
});
109109

110110
test('30GB', () => {
111-
expect(stringToBytes('30gB')).toBe(30000000000);
111+
expect(stringToBytes('30gB')).toBe(30_000_000_000);
112112
});
113113

114114
test('30GiB', () => {
115-
expect(stringToBytes('30GIB')).toBe(32212254720);
115+
expect(stringToBytes('30GIB')).toBe(32_212_254_720);
116116
});
117117
});
118118

packages/jest-core/src/__tests__/SearchSource.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {normalize} from 'jest-config';
1313
import Runtime from 'jest-runtime';
1414
import SearchSource from '../SearchSource';
1515

16-
jest.setTimeout(15000);
16+
jest.setTimeout(15_000);
1717

1818
jest.mock('graceful-fs', () => {
1919
const realFs = jest.requireActual<typeof import('fs')>('fs');

packages/jest-each/src/__tests__/array.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ describe('jest-each', () => {
283283
const eachObject = each.withGlobal(globalTestMocks)([['hello']]);
284284

285285
const testFunction = get(eachObject, keyPath);
286-
testFunction('some test', noop, 10000);
286+
testFunction('some test', noop, 10_000);
287287
const globalMock = get(globalTestMocks, keyPath);
288288
expect(globalMock).toHaveBeenCalledWith(
289289
'some test',
290290
expect.any(Function),
291-
10000,
291+
10_000,
292292
);
293293
});
294294

0 commit comments

Comments
 (0)