mirror of https://github.com/facebook/jest.git
chore: access Number globals via `Number` (#14807)
This commit is contained in:
parent
69fd995fea
commit
306a70aef8
|
@ -234,6 +234,7 @@ module.exports = {
|
||||||
'no-undef': 'off',
|
'no-undef': 'off',
|
||||||
'no-unused-vars': 'off',
|
'no-unused-vars': 'off',
|
||||||
'sort-keys': 'off',
|
'sort-keys': 'off',
|
||||||
|
'unicorn/prefer-number-properties': 'off',
|
||||||
'unicorn/no-static-only-class': 'off',
|
'unicorn/no-static-only-class': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -452,6 +453,12 @@ module.exports = {
|
||||||
'unicorn/no-empty-file': 'off',
|
'unicorn/no-empty-file': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
files: 'packages/expect/src/__tests__/*.test.js',
|
||||||
|
rules: {
|
||||||
|
'unicorn/prefer-number-properties': 'off',
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
parser: '@typescript-eslint/parser',
|
parser: '@typescript-eslint/parser',
|
||||||
parserOptions: {
|
parserOptions: {
|
||||||
|
@ -707,9 +714,6 @@ module.exports = {
|
||||||
'unicorn/no-typeof-undefined': 'off',
|
'unicorn/no-typeof-undefined': 'off',
|
||||||
'unicorn/no-useless-undefined': 'off',
|
'unicorn/no-useless-undefined': 'off',
|
||||||
'unicorn/prefer-logical-operator-over-ternary': 'off',
|
'unicorn/prefer-logical-operator-over-ternary': 'off',
|
||||||
'unicorn/prefer-math-trunc': 'off',
|
|
||||||
'unicorn/prefer-native-coercion-functions': 'off',
|
|
||||||
'unicorn/prefer-number-properties': 'off',
|
|
||||||
'unicorn/prefer-object-from-entries': 'off',
|
'unicorn/prefer-object-from-entries': 'off',
|
||||||
'unicorn/prefer-prototype-methods': 'off',
|
'unicorn/prefer-prototype-methods': 'off',
|
||||||
'unicorn/prefer-spread': 'off',
|
'unicorn/prefer-spread': 'off',
|
||||||
|
|
|
@ -772,7 +772,7 @@ exports[`works with node assert 1`] = `
|
||||||
|
|
||||||
48 |
|
48 |
|
||||||
49 | test('assert.strictEqual', () => {
|
49 | test('assert.strictEqual', () => {
|
||||||
> 50 | assert.strictEqual(1, NaN);
|
> 50 | assert.strictEqual(1, Number.NaN);
|
||||||
| ^
|
| ^
|
||||||
51 | });
|
51 | });
|
||||||
52 |
|
52 |
|
||||||
|
|
|
@ -19,9 +19,9 @@ describe('array', () => {
|
||||||
[noop, noop],
|
[noop, noop],
|
||||||
[[], []],
|
[[], []],
|
||||||
[[{foo: {bar: 'baz'}}], [{foo: {bar: 'baz'}}]],
|
[[{foo: {bar: 'baz'}}], [{foo: {bar: 'baz'}}]],
|
||||||
[Infinity, Infinity],
|
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||||
[-Infinity, -Infinity],
|
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||||
[NaN, NaN],
|
[Number.NaN, Number.NaN],
|
||||||
])('%p == %p', (left, right) => {
|
])('%p == %p', (left, right) => {
|
||||||
expect(left).toEqual(right);
|
expect(left).toEqual(right);
|
||||||
});
|
});
|
||||||
|
@ -29,20 +29,20 @@ describe('array', () => {
|
||||||
|
|
||||||
describe('template', () => {
|
describe('template', () => {
|
||||||
it.each`
|
it.each`
|
||||||
left | right
|
left | right
|
||||||
${'hello'} | ${'hello'}
|
${'hello'} | ${'hello'}
|
||||||
${1} | ${1}
|
${1} | ${1}
|
||||||
${null} | ${null}
|
${null} | ${null}
|
||||||
${undefined} | ${undefined}
|
${undefined} | ${undefined}
|
||||||
${1.2} | ${1.2}
|
${1.2} | ${1.2}
|
||||||
${{foo: 'bar'}} | ${{foo: 'bar'}}
|
${{foo: 'bar'}} | ${{foo: 'bar'}}
|
||||||
${{foo: {bar: 'baz'}}} | ${{foo: {bar: 'baz'}}}
|
${{foo: {bar: 'baz'}}} | ${{foo: {bar: 'baz'}}}
|
||||||
${noop} | ${noop}
|
${noop} | ${noop}
|
||||||
${[]} | ${[]}
|
${[]} | ${[]}
|
||||||
${[{foo: {bar: 'baz'}}]} | ${[{foo: {bar: 'baz'}}]}
|
${[{foo: {bar: 'baz'}}]} | ${[{foo: {bar: 'baz'}}]}
|
||||||
${Infinity} | ${Infinity}
|
${Number.POSITIVE_INFINITY} | ${Number.POSITIVE_INFINITY}
|
||||||
${-Infinity} | ${-Infinity}
|
${Number.NEGATIVE_INFINITY} | ${Number.NEGATIVE_INFINITY}
|
||||||
${NaN} | ${NaN}
|
${Number.NaN} | ${Number.NaN}
|
||||||
`('$left == $right', ({left, right}) => {
|
`('$left == $right', ({left, right}) => {
|
||||||
expect(left).toEqual(right);
|
expect(left).toEqual(right);
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,7 +47,7 @@ test('assert.notDeepEqual', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('assert.strictEqual', () => {
|
test('assert.strictEqual', () => {
|
||||||
assert.strictEqual(1, NaN);
|
assert.strictEqual(1, Number.NaN);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('assert.notStrictEqual', () => {
|
test('assert.notStrictEqual', () => {
|
||||||
|
|
|
@ -13,8 +13,8 @@ describe('returning values', () => {
|
||||||
'string',
|
'string',
|
||||||
0.1,
|
0.1,
|
||||||
null,
|
null,
|
||||||
NaN,
|
Number.NaN,
|
||||||
Infinity,
|
Number.POSITIVE_INFINITY,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
[1],
|
[1],
|
||||||
|
|
|
@ -18,7 +18,7 @@ beforeAll(() => {
|
||||||
jest.retryTimes(3);
|
jest.retryTimes(3);
|
||||||
|
|
||||||
it('retries', () => {
|
it('retries', () => {
|
||||||
const tries = parseInt(fs.readFileSync(countPath, 'utf8'), 10);
|
const tries = Number.parseInt(fs.readFileSync(countPath, 'utf8'), 10);
|
||||||
fs.writeFileSync(countPath, `${tries + 1}`, 'utf8');
|
fs.writeFileSync(countPath, `${tries + 1}`, 'utf8');
|
||||||
expect(tries).toBe(3);
|
expect(tries).toBe(3);
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@ const users = {
|
||||||
|
|
||||||
export default function request(url) {
|
export default function request(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const userID = parseInt(url.slice('/users/'.length), 10);
|
const userID = Number.parseInt(url.slice('/users/'.length), 10);
|
||||||
process.nextTick(() =>
|
process.nextTick(() =>
|
||||||
users[userID]
|
users[userID]
|
||||||
? resolve(users[userID])
|
? resolve(users[userID])
|
||||||
|
|
|
@ -21,12 +21,12 @@ describe('invalid arg', () => {
|
||||||
});
|
});
|
||||||
test('Infinity is not a safe integer', () => {
|
test('Infinity is not a safe integer', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
diff(Infinity, 0, isCommon, foundSubsequence);
|
diff(Number.POSITIVE_INFINITY, 0, isCommon, foundSubsequence);
|
||||||
}).toThrow(/aLength/);
|
}).toThrow(/aLength/);
|
||||||
});
|
});
|
||||||
test('Not a Number is not a safe integer', () => {
|
test('Not a Number is not a safe integer', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
diff(NaN, 0, isCommon, foundSubsequence);
|
diff(Number.NaN, 0, isCommon, foundSubsequence);
|
||||||
}).toThrow(/aLength/);
|
}).toThrow(/aLength/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ describe('input callback encapsulates comparison', () => {
|
||||||
|
|
||||||
describe('Not a Number', () => {
|
describe('Not a Number', () => {
|
||||||
// input callback encapsulates identical sequences
|
// input callback encapsulates identical sequences
|
||||||
const a = [NaN];
|
const a = [Number.NaN];
|
||||||
|
|
||||||
test('is common according to Object.is method', () => {
|
test('is common according to Object.is method', () => {
|
||||||
expect(countCommonObjectIs(a, a)).toBe(1);
|
expect(countCommonObjectIs(a, a)).toBe(1);
|
||||||
|
|
|
@ -415,8 +415,8 @@ describe('closeTo', () => {
|
||||||
[1.23, 1.226],
|
[1.23, 1.226],
|
||||||
[1.23, 1.225],
|
[1.23, 1.225],
|
||||||
[1.23, 1.234],
|
[1.23, 1.234],
|
||||||
[Infinity, Infinity],
|
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||||
[-Infinity, -Infinity],
|
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||||
]) {
|
]) {
|
||||||
test(`${expected} closeTo ${received} return true`, () => {
|
test(`${expected} closeTo ${received} return true`, () => {
|
||||||
jestExpect(closeTo(expected).asymmetricMatch(received)).toBe(true);
|
jestExpect(closeTo(expected).asymmetricMatch(received)).toBe(true);
|
||||||
|
@ -430,9 +430,9 @@ describe('closeTo', () => {
|
||||||
[0, 0.01],
|
[0, 0.01],
|
||||||
[1, 1.23],
|
[1, 1.23],
|
||||||
[1.23, 1.224_999_9],
|
[1.23, 1.224_999_9],
|
||||||
[Infinity, -Infinity],
|
[Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||||
[Infinity, 1.23],
|
[Number.POSITIVE_INFINITY, 1.23],
|
||||||
[-Infinity, -1.23],
|
[Number.NEGATIVE_INFINITY, -1.23],
|
||||||
]) {
|
]) {
|
||||||
test(`${expected} closeTo ${received} return false`, () => {
|
test(`${expected} closeTo ${received} return false`, () => {
|
||||||
jestExpect(closeTo(expected).asymmetricMatch(received)).toBe(false);
|
jestExpect(closeTo(expected).asymmetricMatch(received)).toBe(false);
|
||||||
|
|
|
@ -649,7 +649,7 @@ describe.each([
|
||||||
fn('foo1', 'bar');
|
fn('foo1', 'bar');
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
jestExpect(fn).not[calledWith](Infinity, 'foo1', 'bar');
|
jestExpect(fn).not[calledWith](Number.POSITIVE_INFINITY, 'foo1', 'bar');
|
||||||
}).toThrowErrorMatchingSnapshot();
|
}).toThrowErrorMatchingSnapshot();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,9 +333,15 @@ class CloseTo extends AsymmetricMatcher<number> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let result = false;
|
let result = false;
|
||||||
if (other === Infinity && this.sample === Infinity) {
|
if (
|
||||||
|
other === Number.POSITIVE_INFINITY &&
|
||||||
|
this.sample === Number.POSITIVE_INFINITY
|
||||||
|
) {
|
||||||
result = true; // Infinity - Infinity is NaN
|
result = true; // Infinity - Infinity is NaN
|
||||||
} else if (other === -Infinity && this.sample === -Infinity) {
|
} else if (
|
||||||
|
other === Number.NEGATIVE_INFINITY &&
|
||||||
|
this.sample === Number.NEGATIVE_INFINITY
|
||||||
|
) {
|
||||||
result = true; // -Infinity - -Infinity is NaN
|
result = true; // -Infinity - -Infinity is NaN
|
||||||
} else {
|
} else {
|
||||||
result =
|
result =
|
||||||
|
|
|
@ -176,9 +176,15 @@ const matchers: MatchersObject = {
|
||||||
let expectedDiff = 0;
|
let expectedDiff = 0;
|
||||||
let receivedDiff = 0;
|
let receivedDiff = 0;
|
||||||
|
|
||||||
if (received === Infinity && expected === Infinity) {
|
if (
|
||||||
|
received === Number.POSITIVE_INFINITY &&
|
||||||
|
expected === Number.POSITIVE_INFINITY
|
||||||
|
) {
|
||||||
pass = true; // Infinity - Infinity is NaN
|
pass = true; // Infinity - Infinity is NaN
|
||||||
} else if (received === -Infinity && expected === -Infinity) {
|
} else if (
|
||||||
|
received === Number.NEGATIVE_INFINITY &&
|
||||||
|
expected === Number.NEGATIVE_INFINITY
|
||||||
|
) {
|
||||||
pass = true; // -Infinity - -Infinity is NaN
|
pass = true; // -Infinity - -Infinity is NaN
|
||||||
} else {
|
} else {
|
||||||
expectedDiff = Math.pow(10, -precision) / 2;
|
expectedDiff = Math.pow(10, -precision) / 2;
|
||||||
|
|
|
@ -70,11 +70,14 @@ const _runTestsForDescribeBlock = async (
|
||||||
// Tests that fail and are retried we run after other tests
|
// Tests that fail and are retried we run after other tests
|
||||||
const retryTimes =
|
const retryTimes =
|
||||||
// eslint-disable-next-line no-restricted-globals
|
// eslint-disable-next-line no-restricted-globals
|
||||||
parseInt((global as Global.Global)[RETRY_TIMES] as string, 10) || 0;
|
Number.parseInt((global as Global.Global)[RETRY_TIMES] as string, 10) || 0;
|
||||||
|
|
||||||
const waitBeforeRetry =
|
const waitBeforeRetry =
|
||||||
// eslint-disable-next-line no-restricted-globals
|
Number.parseInt(
|
||||||
parseInt((global as Global.Global)[WAIT_BEFORE_RETRY] as string, 10) || 0;
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
(global as Global.Global)[WAIT_BEFORE_RETRY] as string,
|
||||||
|
10,
|
||||||
|
) || 0;
|
||||||
const deferredRetryTests = [];
|
const deferredRetryTests = [];
|
||||||
|
|
||||||
if (rng) {
|
if (rng) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ it('picks an id based on the rootDir', async () => {
|
||||||
const rootDir = '/root/path/foo';
|
const rootDir = '/root/path/foo';
|
||||||
const expected = createHash('sha1')
|
const expected = createHash('sha1')
|
||||||
.update('/root/path/foo')
|
.update('/root/path/foo')
|
||||||
.update(String(Infinity))
|
.update(String(Number.POSITIVE_INFINITY))
|
||||||
.digest('hex')
|
.digest('hex')
|
||||||
.slice(0, 32);
|
.slice(0, 32);
|
||||||
const {options} = await normalize(
|
const {options} = await normalize(
|
||||||
|
|
|
@ -42,7 +42,7 @@ export default function getMaxWorkers(
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseWorkers = (maxWorkers: string | number): number => {
|
const parseWorkers = (maxWorkers: string | number): number => {
|
||||||
const parsed = parseInt(maxWorkers.toString(), 10);
|
const parsed = Number.parseInt(maxWorkers.toString(), 10);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof maxWorkers === 'string' &&
|
typeof maxWorkers === 'string' &&
|
||||||
|
|
|
@ -40,7 +40,7 @@ export async function readConfig(
|
||||||
// read individual configs for every project.
|
// read individual configs for every project.
|
||||||
skipArgvConfigOption?: boolean,
|
skipArgvConfigOption?: boolean,
|
||||||
parentConfigDirname?: string | null,
|
parentConfigDirname?: string | null,
|
||||||
projectIndex = Infinity,
|
projectIndex = Number.POSITIVE_INFINITY,
|
||||||
skipMultipleConfigError = false,
|
skipMultipleConfigError = false,
|
||||||
): Promise<ReadConfig> {
|
): Promise<ReadConfig> {
|
||||||
const {config: initialOptions, configPath} = await readInitialOptions(
|
const {config: initialOptions, configPath} = await readInitialOptions(
|
||||||
|
|
|
@ -487,7 +487,7 @@ export default async function normalize(
|
||||||
initialOptions: Config.InitialOptions,
|
initialOptions: Config.InitialOptions,
|
||||||
argv: Config.Argv,
|
argv: Config.Argv,
|
||||||
configPath?: string | null,
|
configPath?: string | null,
|
||||||
projectIndex = Infinity,
|
projectIndex = Number.POSITIVE_INFINITY,
|
||||||
isProjectOptions?: boolean,
|
isProjectOptions?: boolean,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
hasDeprecationWarnings: boolean;
|
hasDeprecationWarnings: boolean;
|
||||||
|
@ -1009,7 +1009,7 @@ export default async function normalize(
|
||||||
newOptions.testPathPatterns = testPathPatterns.patterns;
|
newOptions.testPathPatterns = testPathPatterns.patterns;
|
||||||
newOptions.json = !!argv.json;
|
newOptions.json = !!argv.json;
|
||||||
|
|
||||||
newOptions.testFailureExitCode = parseInt(
|
newOptions.testFailureExitCode = Number.parseInt(
|
||||||
newOptions.testFailureExitCode as unknown as string,
|
newOptions.testFailureExitCode as unknown as string,
|
||||||
10,
|
10,
|
||||||
);
|
);
|
||||||
|
@ -1086,7 +1086,7 @@ export default async function normalize(
|
||||||
? 'all'
|
? 'all'
|
||||||
: 'new';
|
: 'new';
|
||||||
|
|
||||||
newOptions.maxConcurrency = parseInt(
|
newOptions.maxConcurrency = Number.parseInt(
|
||||||
newOptions.maxConcurrency as unknown as string,
|
newOptions.maxConcurrency as unknown as string,
|
||||||
10,
|
10,
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,7 +13,7 @@ export const parseShardPair = (pair: string): ShardPair => {
|
||||||
const shardPair = pair
|
const shardPair = pair
|
||||||
.split('/')
|
.split('/')
|
||||||
.filter(d => /^\d+$/.test(d))
|
.filter(d => /^\d+$/.test(d))
|
||||||
.map(d => parseInt(d, 10))
|
.map(d => Number.parseInt(d, 10))
|
||||||
.filter(shard => !Number.isNaN(shard));
|
.filter(shard => !Number.isNaN(shard));
|
||||||
|
|
||||||
const [shardIndex, shardCount] = shardPair;
|
const [shardIndex, shardCount] = shardPair;
|
||||||
|
|
|
@ -30,7 +30,7 @@ function stringToBytes(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof input === 'string') {
|
if (typeof input === 'string') {
|
||||||
if (isNaN(Number.parseFloat(input.slice(-1)))) {
|
if (Number.isNaN(Number.parseFloat(input.slice(-1)))) {
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
let [, numericString, trailingChars] =
|
let [, numericString, trailingChars] =
|
||||||
input.match(/(.*?)([^\d.-]+)$/i) || [];
|
input.match(/(.*?)([^\d.-]+)$/i) || [];
|
||||||
|
|
|
@ -33,7 +33,7 @@ export default function getNoTestFoundVerbose(
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.filter(line => line)
|
.filter(Boolean)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
return testRun.matches.total
|
return testRun.matches.total
|
||||||
|
|
|
@ -78,8 +78,10 @@ describe('no visual difference', () => {
|
||||||
[1, 2],
|
[1, 2],
|
||||||
],
|
],
|
||||||
[11, 11],
|
[11, 11],
|
||||||
|
/* eslint-disable unicorn/prefer-number-properties */
|
||||||
[NaN, NaN],
|
[NaN, NaN],
|
||||||
[Number.NaN, NaN],
|
[Number.NaN, NaN],
|
||||||
|
/* eslint-enable */
|
||||||
[() => {}, () => {}],
|
[() => {}, () => {}],
|
||||||
[null, null],
|
[null, null],
|
||||||
[undefined, undefined],
|
[undefined, undefined],
|
||||||
|
|
|
@ -126,8 +126,8 @@ describe('jest-each', () => {
|
||||||
{foo: 'bar'},
|
{foo: 'bar'},
|
||||||
() => {},
|
() => {},
|
||||||
[],
|
[],
|
||||||
Infinity,
|
Number.POSITIVE_INFINITY,
|
||||||
NaN,
|
Number.NaN,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'world',
|
'world',
|
||||||
|
@ -138,8 +138,8 @@ describe('jest-each', () => {
|
||||||
{baz: 'qux'},
|
{baz: 'qux'},
|
||||||
() => {},
|
() => {},
|
||||||
[],
|
[],
|
||||||
Infinity,
|
Number.POSITIVE_INFINITY,
|
||||||
NaN,
|
Number.NaN,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
const testFunction = get(eachObject, keyPath);
|
const testFunction = get(eachObject, keyPath);
|
||||||
|
@ -304,8 +304,8 @@ describe('jest-each', () => {
|
||||||
f: {key: 'foo'},
|
f: {key: 'foo'},
|
||||||
g: () => {},
|
g: () => {},
|
||||||
h: [],
|
h: [],
|
||||||
i: Infinity,
|
i: Number.POSITIVE_INFINITY,
|
||||||
j: NaN,
|
j: Number.NaN,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: 'world',
|
a: 'world',
|
||||||
|
@ -316,8 +316,8 @@ describe('jest-each', () => {
|
||||||
f: {key: 'bar'},
|
f: {key: 'bar'},
|
||||||
g: () => {},
|
g: () => {},
|
||||||
h: [],
|
h: [],
|
||||||
i: Infinity,
|
i: Number.POSITIVE_INFINITY,
|
||||||
j: NaN,
|
j: Number.NaN,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
const testFunction = get(eachObject, keyPath);
|
const testFunction = get(eachObject, keyPath);
|
||||||
|
|
|
@ -485,14 +485,14 @@ describe('FakeTimers', () => {
|
||||||
const mockAnimationFrame = jest.fn(() => runOrder.push('animationFrame'));
|
const mockAnimationFrame = jest.fn(() => runOrder.push('animationFrame'));
|
||||||
|
|
||||||
global.setTimeout(mock1, 100);
|
global.setTimeout(mock1, 100);
|
||||||
global.setTimeout(mock2, NaN);
|
global.setTimeout(mock2, Number.NaN);
|
||||||
global.setTimeout(mock3, 0);
|
global.setTimeout(mock3, 0);
|
||||||
const intervalHandler = global.setInterval(() => {
|
const intervalHandler = global.setInterval(() => {
|
||||||
mock4();
|
mock4();
|
||||||
global.clearInterval(intervalHandler);
|
global.clearInterval(intervalHandler);
|
||||||
}, 200);
|
}, 200);
|
||||||
global.setTimeout(mock5, Infinity);
|
global.setTimeout(mock5, Number.POSITIVE_INFINITY);
|
||||||
global.setTimeout(mock6, -Infinity);
|
global.setTimeout(mock6, Number.NEGATIVE_INFINITY);
|
||||||
global.requestAnimationFrame(mockAnimationFrame);
|
global.requestAnimationFrame(mockAnimationFrame);
|
||||||
|
|
||||||
timers.runAllTimers();
|
timers.runAllTimers();
|
||||||
|
|
|
@ -251,14 +251,14 @@ describe('FakeTimers', () => {
|
||||||
const mock6 = jest.fn(() => runOrder.push('mock6'));
|
const mock6 = jest.fn(() => runOrder.push('mock6'));
|
||||||
|
|
||||||
global.setTimeout(mock1, 100);
|
global.setTimeout(mock1, 100);
|
||||||
global.setTimeout(mock2, NaN);
|
global.setTimeout(mock2, Number.NaN);
|
||||||
global.setTimeout(mock3, 0);
|
global.setTimeout(mock3, 0);
|
||||||
const intervalHandler = global.setInterval(() => {
|
const intervalHandler = global.setInterval(() => {
|
||||||
mock4();
|
mock4();
|
||||||
global.clearInterval(intervalHandler);
|
global.clearInterval(intervalHandler);
|
||||||
}, 200);
|
}, 200);
|
||||||
global.setTimeout(mock5, Infinity);
|
global.setTimeout(mock5, Number.POSITIVE_INFINITY);
|
||||||
global.setTimeout(mock6, -Infinity);
|
global.setTimeout(mock6, Number.NEGATIVE_INFINITY);
|
||||||
|
|
||||||
timers.runAllTimers();
|
timers.runAllTimers();
|
||||||
expect(runOrder).toEqual([
|
expect(runOrder).toEqual([
|
||||||
|
|
|
@ -560,7 +560,7 @@ export default class FakeTimers<TimerRef = unknown> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-bitwise
|
// eslint-disable-next-line no-bitwise,unicorn/prefer-math-trunc
|
||||||
delay = Number(delay) | 0;
|
delay = Number(delay) | 0;
|
||||||
|
|
||||||
const uuid = this._uuidCounter++;
|
const uuid = this._uuidCounter++;
|
||||||
|
|
|
@ -17,8 +17,8 @@ describe('.isPrimitive()', () => {
|
||||||
true,
|
true,
|
||||||
Symbol.for('a'),
|
Symbol.for('a'),
|
||||||
0,
|
0,
|
||||||
NaN,
|
Number.NaN,
|
||||||
Infinity,
|
Number.POSITIVE_INFINITY,
|
||||||
BigInt(1),
|
BigInt(1),
|
||||||
])('returns true when given primitive value of: %s', primitive => {
|
])('returns true when given primitive value of: %s', primitive => {
|
||||||
expect(isPrimitive(primitive)).toBe(true);
|
expect(isPrimitive(primitive)).toBe(true);
|
||||||
|
|
|
@ -28,7 +28,7 @@ it('complains if the value is a primitive', () => {
|
||||||
expect(() => new LeakDetector('foo')).toThrowErrorMatchingSnapshot();
|
expect(() => new LeakDetector('foo')).toThrowErrorMatchingSnapshot();
|
||||||
expect(() => new LeakDetector(Symbol())).toThrowErrorMatchingSnapshot();
|
expect(() => new LeakDetector(Symbol())).toThrowErrorMatchingSnapshot();
|
||||||
expect(() => new LeakDetector(Symbol('foo'))).toThrowErrorMatchingSnapshot();
|
expect(() => new LeakDetector(Symbol('foo'))).toThrowErrorMatchingSnapshot();
|
||||||
expect(() => new LeakDetector(NaN)).toThrowErrorMatchingSnapshot();
|
expect(() => new LeakDetector(Number.NaN)).toThrowErrorMatchingSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not show the GC if hidden', async () => {
|
it('does not show the GC if hidden', async () => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ test('returns the same value for primitive or function values', () => {
|
||||||
expect(deepCyclicCopyReplaceable(null)).toBeNull();
|
expect(deepCyclicCopyReplaceable(null)).toBeNull();
|
||||||
expect(deepCyclicCopyReplaceable(true)).toBe(true);
|
expect(deepCyclicCopyReplaceable(true)).toBe(true);
|
||||||
expect(deepCyclicCopyReplaceable(42)).toBe(42);
|
expect(deepCyclicCopyReplaceable(42)).toBe(42);
|
||||||
expect(Number.isNaN(deepCyclicCopyReplaceable(NaN))).toBe(true);
|
expect(Number.isNaN(deepCyclicCopyReplaceable(Number.NaN))).toBe(true);
|
||||||
expect(deepCyclicCopyReplaceable('foo')).toBe('foo');
|
expect(deepCyclicCopyReplaceable('foo')).toBe('foo');
|
||||||
expect(deepCyclicCopyReplaceable(fn)).toBe(fn);
|
expect(deepCyclicCopyReplaceable(fn)).toBe(fn);
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,9 +33,14 @@ describe('stringify()', () => {
|
||||||
[undefined, 'undefined'],
|
[undefined, 'undefined'],
|
||||||
['abc', '"abc"'],
|
['abc', '"abc"'],
|
||||||
[Symbol.for('abc'), 'Symbol(abc)'],
|
[Symbol.for('abc'), 'Symbol(abc)'],
|
||||||
|
/* eslint-disable unicorn/prefer-number-properties */
|
||||||
[NaN, 'NaN'],
|
[NaN, 'NaN'],
|
||||||
[Infinity, 'Infinity'],
|
[Infinity, 'Infinity'],
|
||||||
[-Infinity, '-Infinity'],
|
[-Infinity, '-Infinity'],
|
||||||
|
/* eslint-enable */
|
||||||
|
[Number.NaN, 'NaN'],
|
||||||
|
[Number.POSITIVE_INFINITY, 'Infinity'],
|
||||||
|
[Number.NEGATIVE_INFINITY, '-Infinity'],
|
||||||
[/ab\.c/gi, '/ab\\.c/gi'],
|
[/ab\.c/gi, '/ab\\.c/gi'],
|
||||||
[BigInt(1), '1n'],
|
[BigInt(1), '1n'],
|
||||||
[BigInt(0), '0n'],
|
[BigInt(0), '0n'],
|
||||||
|
|
|
@ -49,7 +49,9 @@ describe('moduleMocker', () => {
|
||||||
expect(moduleMocker.getMetadata('banana').value).toBe('banana');
|
expect(moduleMocker.getMetadata('banana').value).toBe('banana');
|
||||||
expect(moduleMocker.getMetadata(27).value).toBe(27);
|
expect(moduleMocker.getMetadata(27).value).toBe(27);
|
||||||
expect(moduleMocker.getMetadata(false).value).toBe(false);
|
expect(moduleMocker.getMetadata(false).value).toBe(false);
|
||||||
expect(moduleMocker.getMetadata(Infinity).value).toEqual(Infinity);
|
expect(moduleMocker.getMetadata(Number.POSITIVE_INFINITY).value).toEqual(
|
||||||
|
Number.POSITIVE_INFINITY,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not retrieve metadata for arrays', () => {
|
it('does not retrieve metadata for arrays', () => {
|
||||||
|
@ -1326,16 +1328,16 @@ describe('moduleMocker', () => {
|
||||||
|
|
||||||
describe('should throw', () => {
|
describe('should throw', () => {
|
||||||
it.each`
|
it.each`
|
||||||
value | type
|
value | type
|
||||||
${'foo'} | ${'string'}
|
${'foo'} | ${'string'}
|
||||||
${1} | ${'number'}
|
${1} | ${'number'}
|
||||||
${NaN} | ${'number'}
|
${Number.NaN} | ${'number'}
|
||||||
${1n} | ${'bigint'}
|
${1n} | ${'bigint'}
|
||||||
${Symbol()} | ${'symbol'}
|
${Symbol()} | ${'symbol'}
|
||||||
${true} | ${'boolean'}
|
${true} | ${'boolean'}
|
||||||
${false} | ${'boolean'}
|
${false} | ${'boolean'}
|
||||||
${undefined} | ${'undefined'}
|
${undefined} | ${'undefined'}
|
||||||
${null} | ${'null'}
|
${null} | ${'null'}
|
||||||
`(
|
`(
|
||||||
'when primitive value $value is provided instead of an object',
|
'when primitive value $value is provided instead of an object',
|
||||||
({value, type}) => {
|
({value, type}) => {
|
||||||
|
@ -2208,16 +2210,16 @@ describe('moduleMocker', () => {
|
||||||
|
|
||||||
describe('should throw', () => {
|
describe('should throw', () => {
|
||||||
it.each`
|
it.each`
|
||||||
value | type
|
value | type
|
||||||
${'foo'} | ${'string'}
|
${'foo'} | ${'string'}
|
||||||
${1} | ${'number'}
|
${1} | ${'number'}
|
||||||
${NaN} | ${'number'}
|
${Number.NaN} | ${'number'}
|
||||||
${1n} | ${'bigint'}
|
${1n} | ${'bigint'}
|
||||||
${Symbol()} | ${'symbol'}
|
${Symbol()} | ${'symbol'}
|
||||||
${true} | ${'boolean'}
|
${true} | ${'boolean'}
|
||||||
${false} | ${'boolean'}
|
${false} | ${'boolean'}
|
||||||
${undefined} | ${'undefined'}
|
${undefined} | ${'undefined'}
|
||||||
${null} | ${'null'}
|
${null} | ${'null'}
|
||||||
`(
|
`(
|
||||||
'when primitive value $value is provided instead of an object',
|
'when primitive value $value is provided instead of an object',
|
||||||
({value, type}) => {
|
({value, type}) => {
|
||||||
|
|
|
@ -21,7 +21,7 @@ function summarize(coverageMap: CoverageMap): CoverageMap {
|
||||||
const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage();
|
const lineCoverage = coverageMap.fileCoverageFor(file).getLineCoverage();
|
||||||
|
|
||||||
for (const lineNumber of Object.keys(lineCoverage)) {
|
for (const lineNumber of Object.keys(lineCoverage)) {
|
||||||
const number = parseInt(lineNumber, 10);
|
const number = Number.parseInt(lineNumber, 10);
|
||||||
// Line numbers start at one
|
// Line numbers start at one
|
||||||
covered[number - 1] = lineCoverage[number] ? 'C' : 'U';
|
covered[number - 1] = lineCoverage[number] ? 'C' : 'U';
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ export default class CoverageReporter extends BaseReporter {
|
||||||
}
|
}
|
||||||
istanbulReports
|
istanbulReports
|
||||||
.create(reporter, {
|
.create(reporter, {
|
||||||
maxCols: process.stdout.columns || Infinity,
|
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
|
||||||
...additionalOptions,
|
...additionalOptions,
|
||||||
})
|
})
|
||||||
.execute(reportContext);
|
.execute(reportContext);
|
||||||
|
|
|
@ -262,7 +262,7 @@ export default class GitHubActionsReporter extends BaseReporter {
|
||||||
const branches: Array<Array<string>> = [];
|
const branches: Array<Array<string>> = [];
|
||||||
for (const element of suiteResult) {
|
for (const element of suiteResult) {
|
||||||
let duration = element.duration;
|
let duration = element.duration;
|
||||||
if (!duration || isNaN(duration)) {
|
if (!duration || Number.isNaN(duration)) {
|
||||||
duration = 1;
|
duration = 1;
|
||||||
}
|
}
|
||||||
if (this.arrayEqual(element.ancestorTitles, ancestors)) {
|
if (this.arrayEqual(element.ancestorTitles, ancestors)) {
|
||||||
|
|
|
@ -439,7 +439,7 @@ describe('onRunComplete', () => {
|
||||||
.onRunComplete(new Set(), {}, mockAggResults)
|
.onRunComplete(new Set(), {}, mockAggResults)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(istanbulReports.create).toHaveBeenCalledWith('json', {
|
expect(istanbulReports.create).toHaveBeenCalledWith('json', {
|
||||||
maxCols: process.stdout.columns || Infinity,
|
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
|
||||||
});
|
});
|
||||||
expect(istanbulReports.create).toHaveBeenCalledWith('lcov', {
|
expect(istanbulReports.create).toHaveBeenCalledWith('lcov', {
|
||||||
maxCols: 10,
|
maxCols: 10,
|
||||||
|
|
|
@ -439,7 +439,7 @@ export default class Resolver {
|
||||||
? (moduleName: string) =>
|
? (moduleName: string) =>
|
||||||
moduleName.replace(
|
moduleName.replace(
|
||||||
/\$(\d+)/g,
|
/\$(\d+)/g,
|
||||||
(_, index) => matches[parseInt(index, 10)] || '',
|
(_, index) => matches[Number.parseInt(index, 10)] || '',
|
||||||
)
|
)
|
||||||
: (moduleName: string) => moduleName;
|
: (moduleName: string) => moduleName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1164,7 +1164,7 @@ describe('printSnapshotAndReceived', () => {
|
||||||
|
|
||||||
test('number', () => {
|
test('number', () => {
|
||||||
const expected = -0;
|
const expected = -0;
|
||||||
const received = NaN;
|
const received = Number.NaN;
|
||||||
|
|
||||||
expect(testWithStringify(expected, received, false)).toMatchSnapshot();
|
expect(testWithStringify(expected, received, false)).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,7 +15,7 @@ it('returns the same value for primitive or function values', () => {
|
||||||
expect(deepCyclicCopy(null)).toBeNull();
|
expect(deepCyclicCopy(null)).toBeNull();
|
||||||
expect(deepCyclicCopy(true)).toBe(true);
|
expect(deepCyclicCopy(true)).toBe(true);
|
||||||
expect(deepCyclicCopy(42)).toBe(42);
|
expect(deepCyclicCopy(42)).toBe(42);
|
||||||
expect(Number.isNaN(deepCyclicCopy(NaN))).toBe(true);
|
expect(Number.isNaN(deepCyclicCopy(Number.NaN))).toBe(true);
|
||||||
expect(deepCyclicCopy('foo')).toBe('foo');
|
expect(deepCyclicCopy('foo')).toBe('foo');
|
||||||
expect(deepCyclicCopy(fn)).toBe(fn);
|
expect(deepCyclicCopy(fn)).toBe(fn);
|
||||||
});
|
});
|
||||||
|
|
|
@ -149,8 +149,8 @@ test('a function constructor', new Function());
|
||||||
test('an anonymous function', () => {});
|
test('an anonymous function', () => {});
|
||||||
function named() {}
|
function named() {}
|
||||||
test('a named function', named);
|
test('a named function', named);
|
||||||
test('Infinity', Infinity);
|
test('Infinity', Number.POSITIVE_INFINITY);
|
||||||
test('-Infinity', -Infinity);
|
test('-Infinity', Number.NEGATIVE_INFINITY);
|
||||||
test('an empty map', new Map());
|
test('an empty map', new Map());
|
||||||
const mapWithValues = new Map();
|
const mapWithValues = new Map();
|
||||||
const mapWithNonStringKeys = new Map();
|
const mapWithNonStringKeys = new Map();
|
||||||
|
@ -159,7 +159,7 @@ mapWithValues.set('prop2', 'value2');
|
||||||
mapWithNonStringKeys.set({prop: 'value'}, {prop: 'value'});
|
mapWithNonStringKeys.set({prop: 'value'}, {prop: 'value'});
|
||||||
test('a map with values', mapWithValues);
|
test('a map with values', mapWithValues);
|
||||||
test('a map with non-string keys', mapWithNonStringKeys);
|
test('a map with non-string keys', mapWithNonStringKeys);
|
||||||
test('NaN', NaN);
|
test('NaN', Number.NaN);
|
||||||
test('null', null);
|
test('null', null);
|
||||||
test('a number', 123);
|
test('a number', 123);
|
||||||
test('a date', new Date(10e11));
|
test('a date', new Date(10e11));
|
||||||
|
|
|
@ -149,7 +149,10 @@ test('closeTo(number)', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('closeTo(Infinity)', () => {
|
test('closeTo(Infinity)', () => {
|
||||||
const result = prettyFormat(expect.closeTo(-Infinity), options);
|
const result = prettyFormat(
|
||||||
|
expect.closeTo(Number.NEGATIVE_INFINITY),
|
||||||
|
options,
|
||||||
|
);
|
||||||
expect(result).toBe('NumberCloseTo -Infinity (2 digits)');
|
expect(result).toBe('NumberCloseTo -Infinity (2 digits)');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -950,8 +950,8 @@ describe('Immutable.Seq lazy values', () => {
|
||||||
const filterer = (item: string) => item.length > 0;
|
const filterer = (item: string) => item.length > 0;
|
||||||
|
|
||||||
test('from Immutable.Range', () => {
|
test('from Immutable.Range', () => {
|
||||||
const val = Immutable.Range(1, Infinity);
|
const val = Immutable.Range(1, Number.POSITIVE_INFINITY);
|
||||||
expect(val.size).toBe(Infinity);
|
expect(val.size).toBe(Number.POSITIVE_INFINITY);
|
||||||
expect(val).toPrettyPrintTo(expected);
|
expect(val).toPrettyPrintTo(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -165,12 +165,12 @@ describe('prettyFormat()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prints Infinity', () => {
|
it('prints Infinity', () => {
|
||||||
const val = Infinity;
|
const val = Number.POSITIVE_INFINITY;
|
||||||
expect(prettyFormat(val)).toBe('Infinity');
|
expect(prettyFormat(val)).toBe('Infinity');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prints -Infinity', () => {
|
it('prints -Infinity', () => {
|
||||||
const val = -Infinity;
|
const val = Number.NEGATIVE_INFINITY;
|
||||||
expect(prettyFormat(val)).toBe('-Infinity');
|
expect(prettyFormat(val)).toBe('-Infinity');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ describe('prettyFormat()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prints NaN', () => {
|
it('prints NaN', () => {
|
||||||
const val = NaN;
|
const val = Number.NaN;
|
||||||
expect(prettyFormat(val)).toBe('NaN');
|
expect(prettyFormat(val)).toBe('NaN');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ describe('prettyFormat()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prints an invalid date', () => {
|
it('prints an invalid date', () => {
|
||||||
const val = new Date(Infinity);
|
const val = new Date(Number.POSITIVE_INFINITY);
|
||||||
expect(prettyFormat(val)).toBe('Date { NaN }');
|
expect(prettyFormat(val)).toBe('Date { NaN }');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -914,7 +914,15 @@ describe('prettyFormat()', () => {
|
||||||
const val = {
|
const val = {
|
||||||
boolean: [false, true],
|
boolean: [false, true],
|
||||||
null: null,
|
null: null,
|
||||||
number: [0, -0, 123, -123, Infinity, -Infinity, NaN],
|
number: [
|
||||||
|
0,
|
||||||
|
-0,
|
||||||
|
123,
|
||||||
|
-123,
|
||||||
|
Number.POSITIVE_INFINITY,
|
||||||
|
Number.NEGATIVE_INFINITY,
|
||||||
|
Number.NaN,
|
||||||
|
],
|
||||||
string: ['', 'non-empty'],
|
string: ['', 'non-empty'],
|
||||||
undefined,
|
undefined,
|
||||||
};
|
};
|
||||||
|
|
|
@ -175,7 +175,7 @@ function printBasicValue(
|
||||||
return printSymbol(val);
|
return printSymbol(val);
|
||||||
}
|
}
|
||||||
if (toStringed === '[object Date]') {
|
if (toStringed === '[object Date]') {
|
||||||
return isNaN(+val) ? 'Date { NaN }' : toISOString.call(val);
|
return Number.isNaN(+val) ? 'Date { NaN }' : toISOString.call(val);
|
||||||
}
|
}
|
||||||
if (toStringed === '[object Error]') {
|
if (toStringed === '[object Error]') {
|
||||||
return printError(val);
|
return printError(val);
|
||||||
|
@ -410,8 +410,8 @@ export const DEFAULT_OPTIONS = toOptionsSubtype({
|
||||||
escapeString: true,
|
escapeString: true,
|
||||||
highlight: false,
|
highlight: false,
|
||||||
indent: 2,
|
indent: 2,
|
||||||
maxDepth: Infinity,
|
maxDepth: Number.POSITIVE_INFINITY,
|
||||||
maxWidth: Infinity,
|
maxWidth: Number.POSITIVE_INFINITY,
|
||||||
min: false,
|
min: false,
|
||||||
plugins: [],
|
plugins: [],
|
||||||
printBasicPrototype: true,
|
printBasicPrototype: true,
|
||||||
|
|
|
@ -27,7 +27,7 @@ export function setupLandingAnimation() {
|
||||||
function positionCards() {
|
function positionCards() {
|
||||||
const handWidth = hand.offsetWidth;
|
const handWidth = hand.offsetWidth;
|
||||||
for (const card of cards) {
|
for (const card of cards) {
|
||||||
const offset = parseInt(card.dataset.index, 10) - 2;
|
const offset = Number.parseInt(card.dataset.index, 10) - 2;
|
||||||
card.parentElement.style.transform = cardTransform(offset, handWidth);
|
card.parentElement.style.transform = cardTransform(offset, handWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ export function setupLandingAnimation() {
|
||||||
card = ev.target.parentElement;
|
card = ev.target.parentElement;
|
||||||
}
|
}
|
||||||
if (card) {
|
if (card) {
|
||||||
const index = parseInt(card.dataset.index, 10);
|
const index = Number.parseInt(card.dataset.index, 10);
|
||||||
runTest(card, index);
|
runTest(card, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue