Skip to content

Commit

Permalink
Merge branch 'main' into align-pretty-format-and-test-renderer-single…
Browse files Browse the repository at this point in the history
…-string-child
  • Loading branch information
SimenB committed Sep 19, 2023
2 parents 303cafb + 2cfb274 commit 84bf63a
Show file tree
Hide file tree
Showing 120 changed files with 927 additions and 858 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 }}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### Features

- `[jest-test-sequencer, jest-core]` Exposes globalConfig & contexts to TestSequencer ([#14535](https://github.com/jestjs/jest/pull/14535))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))
- `[@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
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);
});
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
6 changes: 3 additions & 3 deletions e2e/jasmine-async/__tests__/returningValues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'use strict';

describe('returning values', () => {
[
for (const val of [
1,
'string',
0.1,
Expand All @@ -20,7 +20,7 @@ describe('returning values', () => {
[1],
{},
() => {},
].forEach(val => {
]) {
it(`throws if '${val}:${typeof val}' is returned`, () => val);
});
}
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@types/node": "^16.10.0",
"@types/which": "^3.0.0",
"@types/ws": "8.5.1",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/parser": "^5.14.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"ansi-regex": "^5.0.1",
"ansi-styles": "^5.0.0",
"babel-jest": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions packages/diff-sequences/__benchmarks__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ const testLength = n => {

writeHeading3(n);

[2, 4, 8].forEach(tenth => {
for (const tenth of [2, 4, 8]) {
testDeleteInsert(
tenth,
all,
getItems(n, i => i % 10 >= tenth && `${i}`),
);
});
}
testChange(
1,
all,
Expand Down
Loading

0 comments on commit 84bf63a

Please sign in to comment.