Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-fake-timers
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Sep 19, 2023
2 parents 2295faf + c3f2914 commit 605d599
Show file tree
Hide file tree
Showing 144 changed files with 1,036 additions and 1,039 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module.exports = {
{
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:import/typescript',
],
files: ['*.ts', '*.tsx'],
Expand All @@ -64,6 +63,10 @@ module.exports = {
// TODO: enable at some point
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',

// TODO: part of "stylistic" rules, remove explicit activation when that lands
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-empty-interface': 'error',
},
},
{
Expand Down Expand Up @@ -592,6 +595,7 @@ module.exports = {
yoda: 'off',

'unicorn/explicit-length-check': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-includes': 'error',
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,36 @@ jobs:
test-ubuntu:
uses: ./.github/workflows/test.yml
needs: prepare-yarn-cache-ubuntu
strategy:
fail-fast: false
matrix:
shard: ['1/4', '2/4', '3/4', '4/4']
name: Ubuntu with shard ${{ matrix.shard }}
with:
os: ubuntu-latest
shard: ${{ matrix.shard }}
test-macos:
uses: ./.github/workflows/test.yml
needs: prepare-yarn-cache-macos
strategy:
fail-fast: false
matrix:
shard: ['1/3', '2/3', '3/3']
name: macOS with shard ${{ matrix.shard }}
with:
os: macos-latest
shard: ${{ matrix.shard }}
test-windows:
uses: ./.github/workflows/test.yml
needs: prepare-yarn-cache-windows
strategy:
fail-fast: false
matrix:
shard: ['1/4', '2/4', '3/4', '4/4']
name: Windows with shard ${{ matrix.shard }}
with:
os: windows-latest
shard: ${{ matrix.shard }}

test-leak:
name: Node LTS on Ubuntu with leak detection
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ on:
os:
required: true
type: string
shard:
required: true
type: string

jobs:
test:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 20.x]
shard: ['1/4', '2/4', '3/4', '4/4']
name: Node v${{ matrix.node-version }} on ${{ inputs.os }} (${{ matrix.shard }})
name: Node v${{ matrix.node-version }}
runs-on: ${{ inputs.os }}

steps:
Expand All @@ -34,14 +36,10 @@ jobs:
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@v2
- name: run tests
run: yarn test-ci-partial:parallel --max-workers ${{ steps.cpu-cores.outputs.count }} --shard=${{ matrix.shard }}
run: yarn test-ci-partial:parallel --max-workers ${{ steps.cpu-cores.outputs.count }} --shard=${{ inputs.shard }}

test-jasmine:
strategy:
fail-fast: false
matrix:
shard: ['1/4', '2/4', '3/4', '4/4']
name: Node LTS on ${{ inputs.os }} using jest-jasmine2 (${{ matrix.shard }})
name: Node LTS using jest-jasmine2
runs-on: ${{ inputs.os }}

steps:
Expand All @@ -61,4 +59,4 @@ jobs:
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@v2
- name: run tests using jest-jasmine
run: yarn jest-jasmine-ci --max-workers ${{ steps.cpu-cores.outputs.count }} --shard=${{ matrix.shard }}
run: yarn jest-jasmine-ci --max-workers ${{ steps.cpu-cores.outputs.count }} --shard=${{ inputs.shard }}
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

### Features

- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))
- `[@jest/fake-timers]` [**BREAKING**] Upgrade `@sinonjs/fake-timers` to v11 ([#14544](https://github.com/jestjs/jest/pull/14544))
- `[jest-test-sequencer, jest-core]` Exposes globalConfig & contexts to TestSequencer ([#14535](https://github.com/jestjs/jest/pull/14535))
- `[@jest/test-sequencer, jest-core]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543))
- `[pretty-format]` [**BREAKING**] Do not render empty string children (`''`) in React plugin ([#14470](https://github.com/facebook/jest/pull/14470))

### Fixes

Expand Down
4 changes: 0 additions & 4 deletions constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, Depende
DependencyType2 \= 'peerDependencies',
% A list of exception to same version rule
\+ member(DependencyIdent, [
% Allow enzyme example workspace use a older version react and react-dom, because enzyme don't support react 17
'react', 'react-dom', '@types/react',
% Only RN should be bumped to react 18
'react-test-renderer',
% @types/node in the root need to stay on ~14.14.45
'@types/node',
% upgrading the entire repository is a breaking change
Expand Down
2 changes: 1 addition & 1 deletion e2e/MockStdinWatchPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MockStdinWatchPlugin {
apply(jestHooks) {
jestHooks.onTestRunComplete(() => {
const {keys} = this._config.input.shift();
keys.forEach(key => this._stdin.emit('data', key));
for (const key of keys) this._stdin.emit('data', key);
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const writeFiles = (
files: {[filename: string]: string},
) => {
fs.mkdirSync(directory, {recursive: true});
Object.keys(files).forEach(fileOrPath => {
for (const fileOrPath of Object.keys(files)) {
const dirname = path.dirname(fileOrPath);

if (dirname !== '/') {
Expand All @@ -138,15 +138,15 @@ export const writeFiles = (
path.resolve(directory, ...fileOrPath.split('/')),
dedent(files[fileOrPath]),
);
});
}
};

export const writeSymlinks = (
directory: string,
symlinks: {[existingFile: string]: string},
) => {
fs.mkdirSync(directory, {recursive: true});
Object.keys(symlinks).forEach(fileOrPath => {
for (const fileOrPath of Object.keys(symlinks)) {
const symLinkPath = symlinks[fileOrPath];
const dirname = path.dirname(symLinkPath);

Expand All @@ -158,7 +158,7 @@ export const writeSymlinks = (
path.resolve(directory, ...symLinkPath.split('/')),
'junction',
);
});
}
};

const NUMBER_OF_TESTS_TO_FORCE_USING_WORKERS = 25;
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/coverageRemapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ it('maps code coverage against original source', () => {
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));

// reduce absolute paths embedded in the coverage map to just filenames
Object.keys(coverageMap).forEach(filename => {
for (const filename of Object.keys(coverageMap)) {
coverageMap[filename].path = path.basename(coverageMap[filename].path);
delete coverageMap[filename].hash;
coverageMap[path.basename(filename)] = coverageMap[filename];
delete coverageMap[filename];
});
}
expect(coverageMap).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions e2e/__tests__/coverageTransformInstrumented.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ it('code coverage for transform instrumented code', () => {
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));

// reduce absolute paths embedded in the coverage map to just filenames
Object.keys(coverageMap).forEach(filename => {
for (const filename of Object.keys(coverageMap)) {
coverageMap[filename].path = path.basename(coverageMap[filename].path);
delete coverageMap[filename].hash;
coverageMap[path.basename(filename)] = coverageMap[filename];
delete coverageMap[filename];
});
}
expect(coverageMap).toMatchSnapshot();
});
8 changes: 4 additions & 4 deletions e2e/__tests__/errorOnDeprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SHOULD_NOT_PASS_IN_JEST = new Set([
'spyOnProperty.test.js',
]);

testFiles.forEach(testFile => {
for (const testFile of testFiles) {
test(`${testFile} errors in errorOnDeprecated mode`, () => {
const result = runJest('error-on-deprecated', [
testFile,
Expand All @@ -42,9 +42,9 @@ testFiles.forEach(testFile => {

expect(rest).toMatchSnapshot();
});
});
}

testFiles.forEach(testFile => {
for (const testFile of testFiles) {
const shouldPass = SHOULD_NOT_PASS_IN_JEST.has(testFile);

const expectation = `${testFile} ${shouldPass ? 'errors' : 'passes'}`;
Expand All @@ -54,4 +54,4 @@ testFiles.forEach(testFile => {
const result = runJest('error-on-deprecated', [testFile]);
expect(result.exitCode).toBe(shouldPass ? 1 : 0);
});
});
}
6 changes: 3 additions & 3 deletions e2e/__tests__/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ const getSnapshotOfCopy = () => {

describe('Snapshot', () => {
const cleanup = () => {
[
for (const file of [
snapshotFile,
secondSnapshotFile,
snapshotOfCopy,
copyOfTestPath,
snapshotEscapeFile,
snapshotEscapeRegexFile,
snapshotEscapeSubstitutionFile,
].forEach(file => {
]) {
if (fileExists(file)) {
fs.unlinkSync(file);
}
});
}
if (fileExists(snapshotDir)) {
fs.rmdirSync(snapshotDir);
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/summaryThreshold.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import runJest from '../runJest';

['default', 'summary'].forEach(reporter => {
for (const reporter of ['default', 'summary']) {
describe(`${reporter} reporter`, () => {
test('prints failure messages when total number of test suites is over summaryThreshold', () => {
const {exitCode, stderr} = runJest('summary-threshold', [
Expand All @@ -26,4 +26,4 @@ import runJest from '../runJest';
);
});
});
});
}
4 changes: 2 additions & 2 deletions e2e/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ describe('transformer caching', () => {
const loggedFiles = stdout.split('\n');

// Verify any lines logged are _just_ the file we care about
loggedFiles.forEach(line => {
for (const line of loggedFiles) {
expect(line).toBe(transformedFile);
});
}

// We run with 2 workers, so the file should be transformed twice
expect(loggedFiles).toHaveLength(2);
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/watchModeOnlyFailed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ test('can press "f" to run only failed tests', () => {
const results = extractSummaries(stderr);

expect(results).toHaveLength(2);
results.forEach(({rest, summary}) => {
for (const {rest, summary} of results) {
expect(rest).toMatchSnapshot('test results');
expect(summary).toMatchSnapshot('test summary');
});
}
expect(exitCode).toBe(0);
});
8 changes: 4 additions & 4 deletions e2e/__tests__/watchModePatterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ test('can press "p" to filter by file name', () => {

expect(stdout).toMatchSnapshot();
expect(results).toHaveLength(2);
results.forEach(({rest, summary}) => {
for (const {rest, summary} of results) {
expect(rest).toMatchSnapshot('test results');
expect(summary).toMatchSnapshot('test summary');
});
}
expect(exitCode).toBe(0);
});

Expand All @@ -66,9 +66,9 @@ test('can press "t" to filter by test name', () => {

expect(stdout).toMatchSnapshot();
expect(results).toHaveLength(2);
results.forEach(({rest, summary}) => {
for (const {rest, summary} of results) {
expect(rest).toMatchSnapshot('test results');
expect(summary).toMatchSnapshot('test summary');
});
}
expect(exitCode).toBe(0);
});
4 changes: 2 additions & 2 deletions e2e/__tests__/watchModeUpdateSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ test('can press "u" to update snapshots', () => {
const {exitCode, stderr} = runJest(DIR, ['--no-watchman', '--watchAll']);
const results = extractSummaries(stderr);
expect(results).toHaveLength(2);
results.forEach(({rest, summary}) => {
for (const {rest, summary} of results) {
expect(rest).toMatchSnapshot('test results');
expect(summary).toMatchSnapshot('test summary');
});
}
expect(exitCode).toBe(0);
});
2 changes: 1 addition & 1 deletion e2e/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-typescript": "^7.0.0",
"react": "17.0.2"
"react": "18.2.0"
},
"jest": {
"automock": true,
Expand Down
18 changes: 5 additions & 13 deletions e2e/babel-plugin-jest-hoist/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1573,13 +1573,6 @@ __metadata:
languageName: node
linkType: hard

"object-assign@npm:^4.1.1":
version: 4.1.1
resolution: "object-assign@npm:4.1.1"
checksum: fcc6e4ea8c7fe48abfbb552578b1c53e0d194086e2e6bbbf59e0a536381a292f39943c6e9628af05b5528aa5e3318bb30d6b2e53cadaf5b8fe9e12c4b69af23f
languageName: node
linkType: hard

"path-parse@npm:^1.0.7":
version: 1.0.7
resolution: "path-parse@npm:1.0.7"
Expand All @@ -1594,13 +1587,12 @@ __metadata:
languageName: node
linkType: hard

"react@npm:17.0.2":
version: 17.0.2
resolution: "react@npm:17.0.2"
"react@npm:18.2.0":
version: 18.2.0
resolution: "react@npm:18.2.0"
dependencies:
loose-envify: ^1.1.0
object-assign: ^4.1.1
checksum: b254cc17ce3011788330f7bbf383ab653c6848902d7936a87b09d835d091e3f295f7e9dd1597c6daac5dc80f90e778c8230218ba8ad599f74adcc11e33b9d61b
checksum: 88e38092da8839b830cda6feef2e8505dec8ace60579e46aa5490fc3dc9bba0bd50336507dc166f43e3afc1c42939c09fe33b25fae889d6f402721dcd78fca1b
languageName: node
linkType: hard

Expand Down Expand Up @@ -1694,7 +1686,7 @@ __metadata:
"@babel/preset-env": ^7.0.0
"@babel/preset-flow": ^7.0.0
"@babel/preset-typescript": ^7.0.0
react: 17.0.2
react: 18.2.0
languageName: unknown
linkType: soft

Expand Down
4 changes: 2 additions & 2 deletions e2e/custom-reporters/reporters/AssertionCountsReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

class AssertionCountsReporter {
onTestFileResult(test, testResult, aggregatedResult) {
testResult.testResults.forEach((testCaseResult, index) => {
for (const [index, testCaseResult] of testResult.testResults.entries()) {
console.log(
`onTestFileResult testCaseResult ${index}: ${testCaseResult.title}, ` +
`status: ${testCaseResult.status}, ` +
`numExpectations: ${testCaseResult.numPassingAsserts}`,
);
});
}
}
onTestCaseResult(test, testCaseResult) {
console.log(
Expand Down
Loading

0 comments on commit 605d599

Please sign in to comment.