Skip to content

Commit

Permalink
chore: use numeric separators (jestjs#14570)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Sep 25, 2023
1 parent 769ee6e commit 6c83c0f
Show file tree
Hide file tree
Showing 60 changed files with 107 additions and 104 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ module.exports = {
'unicorn/explicit-length-check': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/numeric-separators-style': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/template-indent': 'error',
Expand Down
2 changes: 1 addition & 1 deletion docs/MockFunctionAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ afterEach(() => {
});

test('renders correctly with a given date', () => {
spiedDateNow = setDateNow(1482363367071);
spiedDateNow = setDateNow(1_482_363_367_071);
// ...

expect(spiedDateNow).toHaveBeenCalledTimes(1);
Expand Down
2 changes: 1 addition & 1 deletion docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Your tests should be deterministic. Running the same tests multiple times on a c
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:

```js
Date.now = jest.fn(() => 1482363367071);
Date.now = jest.fn(() => 1_482_363_367_071);
```

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.
Expand Down
2 changes: 1 addition & 1 deletion docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Most commonly this is being caused by conflicting Promise implementations. Consi
If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout`

```js
jest.setTimeout(10000); // 10 second timeout
jest.setTimeout(10_000); // 10 second timeout
```

## Watchman Issues
Expand Down
6 changes: 3 additions & 3 deletions e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports[`prints out info about open handlers from inside tests 1`] = `
7 |
8 | test('something', () => {
> 9 | setTimeout(() => {}, 30000);
> 9 | setTimeout(() => {}, 30_000);
| ^
10 | expect(true).toBe(true);
11 | });
Expand All @@ -54,7 +54,7 @@ exports[`prints out info about open handlers from lifecycle functions with a \`d
7 |
8 | beforeAll(done => {
> 9 | setTimeout(() => {}, 10000);
> 9 | setTimeout(() => {}, 10_000);
| ^
10 | done();
11 | });
Expand All @@ -70,7 +70,7 @@ exports[`prints out info about open handlers from tests with a \`done\` callback
7 |
8 | test('something', done => {
> 9 | setTimeout(() => {}, 10000);
> 9 | setTimeout(() => {}, 10_000);
| ^
10 | expect(true).toBe(true);
11 | done();
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/complexItemsInErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('handles functions that close over outside variables', async () => {
tempDir,
['--no-watchman', '--watch-all'],
// timeout in case the `waitUntil` below doesn't fire
{stripAnsi: true, timeout: 10000},
{stripAnsi: true, timeout: 10_000},
);

await waitUntil(({stderr}) => stderr.includes('Ran all test suites.'));
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/customReporters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Custom Reporters Integration', () => {

test('invalid format for adding reporters', () => {
const reporterConfig = {
reporters: [[3243242]],
reporters: [[3_243_242]],
};

const {exitCode, stderr} = runJest('custom-reporters', [
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/watchModeNoAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ test('does not re-run tests when only access time is modified', async () => {
await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 2);

// Should NOT re-run the test
const fakeATime = 1541723621;
const fakeATime = 1_541_723_621;
fs.utimesSync(
modulePath,
getOneSecondAfterMs(fakeATime),
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/workerForceExit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ test('force exits a worker that fails to exit gracefully', async () => {
expect(pidNumber).not.toBeNaN();

expect(await findProcess('pid', pidNumber)).toHaveLength(0);
}, 15000);
}, 15_000);
2 changes: 1 addition & 1 deletion e2e/detect-open-handles/__tests__/in-done-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

test('something', done => {
setTimeout(() => {}, 10000);
setTimeout(() => {}, 10_000);
expect(true).toBe(true);
done();
});
2 changes: 1 addition & 1 deletion e2e/detect-open-handles/__tests__/in-done-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

beforeAll(done => {
setTimeout(() => {}, 10000);
setTimeout(() => {}, 10_000);
done();
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/detect-open-handles/__tests__/inside.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
*/

test('something', () => {
setTimeout(() => {}, 30000);
setTimeout(() => {}, 30_000);
expect(true).toBe(true);
});
2 changes: 1 addition & 1 deletion e2e/detect-open-handles/__tests__/unref.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

test('something', () => {
const timeout = setTimeout(() => {}, 30000);
const timeout = setTimeout(() => {}, 30_000);
timeout.unref();
expect(true).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('advances timers if a number is passed', done => {
test('works with `now` option', done => {
jest.useFakeTimers({advanceTimers: 30, now: new Date('2015-09-25')});

expect(Date.now()).toBe(1443139200000);
expect(Date.now()).toBe(1_443_139_200_000);

const start = Date.now();

Expand Down
2 changes: 1 addition & 1 deletion e2e/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const runContinuous = function (
args?: Array<string>,
options: RunJestOptions = {},
) {
const jestPromise = spawnJest(dir, args, {timeout: 30000, ...options}, true);
const jestPromise = spawnJest(dir, args, {timeout: 30_000, ...options}, true);

let stderr = '';
let stdout = '';
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native/__tests__/intro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ActivityIndicator, FlatList, Text, TextInput} from 'react-native';
import renderer from 'react-test-renderer';
import Intro from '../Intro';

jest.setTimeout(15000);
jest.setTimeout(15_000);

it('renders correctly', () => {
const tree = renderer.create(<Intro />).toJSON();
Expand Down
2 changes: 1 addition & 1 deletion examples/snapshot/__tests__/clock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import renderer from 'react-test-renderer';
import Clock from '../Clock';

jest.useFakeTimers().setSystemTime(1482363367071);
jest.useFakeTimers().setSystemTime(1_482_363_367_071);

it('renders correctly', () => {
const testRenderer = renderer.create(<Clock />);
Expand Down
2 changes: 1 addition & 1 deletion examples/timer/__tests__/infinite_timer_game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ it('schedules a 10-second timer after 1 second', () => {
// And it should have created a new timer to start the game over in
// 10 seconds
expect(setTimeout).toHaveBeenCalledTimes(2);
expect(setTimeout).toHaveBeenNthCalledWith(2, expect.any(Function), 10000);
expect(setTimeout).toHaveBeenNthCalledWith(2, expect.any(Function), 10_000);
});
2 changes: 1 addition & 1 deletion examples/timer/infiniteTimerGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function infiniteTimerGame(callback) {
// Schedule the next game in 10 seconds
setTimeout(() => {
infiniteTimerGame(callback);
}, 10000);
}, 10_000);
}, 1000);
}

Expand Down
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
'/e2e/__tests__/iterator-to-null-test.ts',
'/e2e/__tests__/tsIntegration.test.ts', // this test needs types to be build, it runs in a separate CI job through `jest.config.ts.mjs`
],
testTimeout: 70000,
testTimeout: 70_000,
transform: {
'\\.[jt]sx?$': require.resolve('babel-jest'),
},
Expand Down
10 changes: 5 additions & 5 deletions packages/expect/src/__tests__/asymmetricMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ describe('closeTo', () => {
for (const [expected, received] of [
[0, 0.01],
[1, 1.23],
[1.23, 1.2249999],
[1.23, 1.224_999_9],
[Infinity, -Infinity],
[Infinity, 1.23],
[-Infinity, -1.23],
Expand All @@ -446,8 +446,8 @@ describe('closeTo', () => {
for (const [expected, received, precision] of [
[0, 0.1, 0],
[0, 0.0001, 3],
[0, 0.000004, 5],
[2.0000002, 2, 5],
[0, 0.000_004, 5],
[2.000_000_2, 2, 5],
]) {
test(`${expected} closeTo ${received} with precision ${precision} return true`, () => {
jestExpect(closeTo(expected, precision).asymmetricMatch(received)).toBe(
Expand All @@ -462,8 +462,8 @@ describe('closeTo', () => {
}

for (const [expected, received, precision] of [
[3.141592e-7, 3e-7, 8],
[56789, 51234, -4],
[3.141_592e-7, 3e-7, 8],
[56_789, 51_234, -4],
]) {
test(`${expected} closeTo ${received} with precision ${precision} return false`, () => {
jestExpect(closeTo(expected, precision).asymmetricMatch(received)).toBe(
Expand Down
14 changes: 7 additions & 7 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,8 @@ describe('.toEqual()', () => {
[, , 2, ,],
],
[
Object.assign([], {4294967295: 1}),
Object.assign([], {4294967295: 2}), // issue 11056
Object.assign([], {4_294_967_295: 1}),
Object.assign([], {4_294_967_295: 2}), // issue 11056
],
[
// eslint-disable-next-line no-useless-computed-key
Expand Down Expand Up @@ -1658,7 +1658,7 @@ describe('.toBeCloseTo', () => {
for (const [n1, n2] of [
[0, 0.01],
[1, 1.23],
[1.23, 1.2249999],
[1.23, 1.224_999_9],
[Infinity, -Infinity],
[Infinity, 1.23],
[-Infinity, -1.23],
Expand All @@ -1673,8 +1673,8 @@ describe('.toBeCloseTo', () => {
}

for (const [n1, n2, p] of [
[3.141592e-7, 3e-7, 8],
[56789, 51234, -4],
[3.141_592e-7, 3e-7, 8],
[56_789, 51_234, -4],
]) {
it(`{pass: false} expect(${n1}).toBeCloseTo(${n2}, ${p})`, () => {
jestExpect(n1).not.toBeCloseTo(n2, p);
Expand All @@ -1688,8 +1688,8 @@ describe('.toBeCloseTo', () => {
for (const [n1, n2, p] of [
[0, 0.1, 0],
[0, 0.0001, 3],
[0, 0.000004, 5],
[2.0000002, 2, 5],
[0, 0.000_004, 5],
[2.000_000_2, 2, 5],
]) {
it(`{pass: true} expect(${n1}).toBeCloseTo(${n2}, ${p})`, () => {
jestExpect(n1).toBeCloseTo(n2, p);
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/ValidConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const initialOptions: Config.InitialOptions = {
],
enableGlobally: true,
legacyFakeTimers: false,
now: 1483228800000,
now: 1_483_228_800_000,
timerLimit: 1000,
},
filter: '<rootDir>/filter.js',
Expand Down Expand Up @@ -231,7 +231,7 @@ export const initialProjectOptions: Config.InitialProjectOptions = {
],
enableGlobally: true,
legacyFakeTimers: false,
now: 1483228800000,
now: 1_483_228_800_000,
timerLimit: 1000,
},
filter: '<rootDir>/filter.js',
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-config/src/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ it('keeps custom ids based on the rootDir', async () => {

it('minimal config is stable across runs', async () => {
const firstNormalization = await normalize({rootDir: '/root/path/foo'}, {
seed: 55555,
seed: 55_555,
} as Config.Argv);
const secondNormalization = await normalize({rootDir: '/root/path/foo'}, {
seed: 55555,
seed: 55_555,
} as Config.Argv);

expect(firstNormalization).toEqual(secondNormalization);
Expand Down Expand Up @@ -2130,7 +2130,7 @@ it('parses workerIdleMemoryLimit', async () => {
{} as Config.Argv,
);

expect(options.workerIdleMemoryLimit).toBe(47185920);
expect(options.workerIdleMemoryLimit).toBe(47_185_920);
});

describe('seed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ describe('readConfigFileAndSetRootDir', () => {
test('handles exported async function', async () => {
jest
.mocked(requireOrImportModule)
.mockResolvedValueOnce(async () => ({testTimeout: 10000}));
.mockResolvedValueOnce(async () => ({testTimeout: 10_000}));

const rootDir = path.resolve('some', 'path', 'to');
const config = await readConfigFileAndSetRootDir(
path.join(rootDir, 'jest.config.js'),
);

expect(config).toEqual({rootDir, testTimeout: 10000});
expect(config).toEqual({rootDir, testTimeout: 10_000});
});
});

Expand Down
18 changes: 9 additions & 9 deletions packages/jest-config/src/__tests__/stringToBytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,43 +76,43 @@ describe('string input', () => {
// The units caps is intentionally janky to test for forgiving string parsing.
describe('k', () => {
test('30k', () => {
expect(stringToBytes('30K')).toBe(30000);
expect(stringToBytes('30K')).toBe(30_000);
});

test('30KB', () => {
expect(stringToBytes('30kB')).toBe(30000);
expect(stringToBytes('30kB')).toBe(30_000);
});

test('30KiB', () => {
expect(stringToBytes('30kIb')).toBe(30720);
expect(stringToBytes('30kIb')).toBe(30_720);
});
});

describe('m', () => {
test('30M', () => {
expect(stringToBytes('30M')).toBe(30000000);
expect(stringToBytes('30M')).toBe(30_000_000);
});

test('30MB', () => {
expect(stringToBytes('30MB')).toBe(30000000);
expect(stringToBytes('30MB')).toBe(30_000_000);
});

test('30MiB', () => {
expect(stringToBytes('30MiB')).toBe(31457280);
expect(stringToBytes('30MiB')).toBe(31_457_280);
});
});

describe('g', () => {
test('30G', () => {
expect(stringToBytes('30G')).toBe(30000000000);
expect(stringToBytes('30G')).toBe(30_000_000_000);
});

test('30GB', () => {
expect(stringToBytes('30gB')).toBe(30000000000);
expect(stringToBytes('30gB')).toBe(30_000_000_000);
});

test('30GiB', () => {
expect(stringToBytes('30GIB')).toBe(32212254720);
expect(stringToBytes('30GIB')).toBe(32_212_254_720);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/__tests__/SearchSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {normalize} from 'jest-config';
import Runtime from 'jest-runtime';
import SearchSource from '../SearchSource';

jest.setTimeout(15000);
jest.setTimeout(15_000);

jest.mock('graceful-fs', () => {
const realFs = jest.requireActual<typeof import('fs')>('fs');
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-each/src/__tests__/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ describe('jest-each', () => {
const eachObject = each.withGlobal(globalTestMocks)([['hello']]);

const testFunction = get(eachObject, keyPath);
testFunction('some test', noop, 10000);
testFunction('some test', noop, 10_000);
const globalMock = get(globalTestMocks, keyPath);
expect(globalMock).toHaveBeenCalledWith(
'some test',
expect.any(Function),
10000,
10_000,
);
});

Expand Down
Loading

0 comments on commit 6c83c0f

Please sign in to comment.