Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-jest-util
Browse files Browse the repository at this point in the history
  • Loading branch information
eryue0220 committed Aug 18, 2023
2 parents 829c991 + eb61702 commit 34d589c
Show file tree
Hide file tree
Showing 313 changed files with 77 additions and 89,762 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

### Fixes

- `[expect, @jest/expect-utils]` `ObjectContaining` support `sumbol` as key ([#14414](https://github.com/jestjs/jest/pull/14414))
- `[expect]` Remove `@types/node` from dependencies ([#14385](https://github.com/jestjs/jest/pull/14385))
- `[jest-core]` Use workers in watch mode by default to avoid crashes ([#14059](https://github.com/facebook/jest/pull/14059) & [#14085](https://github.com/facebook/jest/pull/14085)).
- `[jest-reporters]` Update `istanbul-lib-instrument` dependency to v6. ([#14401](https://github.com/jestjs/jest/pull/14401))

### Chore & Maintenance
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"clean-all": "yarn clean-e2e && yarn build-clean && rimraf --glob './packages/*/node_modules' && rimraf './node_modules'",
"clean-e2e": "node ./scripts/cleanE2e.mjs",
"crowdin:upload": "echo 'Uploading sources to Crowdin' && crowdin upload sources --config ./crowdin.yaml",
"crowdin:download": "echo 'Downloading translations from Crowdin' && crowdin download --config ./crowdin.yaml",
"crowdin:download": "echo 'Downloading translations from Crowdin' && crowdin download --config ./crowdin.yaml --language ja --language es-ES --language fr --language pt-BR --language ro --language ru --language uk --language zh-CN",
"jest": "node ./packages/jest-cli/bin/jest.js",
"jest-jasmine": "JEST_JASMINE=1 yarn jest",
"jest-jasmine-ci": "yarn jest-jasmine --color --config jest.config.ci.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const hasPropertyInObject = (object: object, key: string | symbol): boolean => {
// the prototype chain for string keys but not for symbols. (Otherwise, it
// could find values such as a Set or Map's Symbol.toStringTag, with unexpected
// results.)
const getObjectKeys = (object: object) => [
export const getObjectKeys = (object: object): Array<string | symbol> => [
...Object.keys(object),
...Object.getOwnPropertySymbols(object),
];
Expand Down
8 changes: 8 additions & 0 deletions packages/expect/src/__tests__/asymmetricMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ test('ArrayNotContaining throws for non-arrays', () => {
});

test('ObjectContaining matches', () => {
const foo = Symbol('foo');
[
objectContaining({}).asymmetricMatch('jest'),
objectContaining({foo: 'foo'}).asymmetricMatch({foo: 'foo', jest: 'jest'}),
Expand All @@ -192,12 +193,15 @@ test('ObjectContaining matches', () => {
foo: Buffer.from('foo'),
jest: 'jest',
}),
objectContaining({[foo]: 'foo'}).asymmetricMatch({[foo]: 'foo'}),
].forEach(test => {
jestExpect(test).toEqual(true);
});
});

test('ObjectContaining does not match', () => {
const foo = Symbol('foo');
const bar = Symbol('bar');
[
objectContaining({foo: 'foo'}).asymmetricMatch({bar: 'bar'}),
objectContaining({foo: 'foo'}).asymmetricMatch({foo: 'foox'}),
Expand All @@ -206,6 +210,7 @@ test('ObjectContaining does not match', () => {
answer: 42,
foo: {bar: 'baz', foobar: 'qux'},
}).asymmetricMatch({foo: {bar: 'baz'}}),
objectContaining({[foo]: 'foo'}).asymmetricMatch({[bar]: 'bar'}),
].forEach(test => {
jestExpect(test).toEqual(false);
});
Expand Down Expand Up @@ -250,9 +255,12 @@ test('ObjectContaining does not mutate the sample', () => {
});

test('ObjectNotContaining matches', () => {
const foo = Symbol('foo');
const bar = Symbol('bar');
[
objectContaining({}).asymmetricMatch(null),
objectContaining({}).asymmetricMatch(undefined),
objectNotContaining({[foo]: 'foo'}).asymmetricMatch({[bar]: 'bar'}),
objectNotContaining({foo: 'foo'}).asymmetricMatch({bar: 'bar'}),
objectNotContaining({foo: 'foo'}).asymmetricMatch({foo: 'foox'}),
objectNotContaining({foo: undefined}).asymmetricMatch({}),
Expand Down
24 changes: 14 additions & 10 deletions packages/expect/src/asymmetricMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {
equals,
getObjectKeys,
isA,
iterableEquality,
subsetEquality,
Expand Down Expand Up @@ -52,7 +53,10 @@ function getPrototype(obj: object) {
return obj.constructor.prototype;
}

export function hasProperty(obj: object | null, property: string): boolean {
export function hasProperty(
obj: object | null,
property: string | symbol,
): boolean {
if (!obj) {
return false;
}
Expand Down Expand Up @@ -216,8 +220,10 @@ class ArrayContaining extends AsymmetricMatcher<Array<unknown>> {
}
}

class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
constructor(sample: Record<string, unknown>, inverse = false) {
class ObjectContaining extends AsymmetricMatcher<
Record<string | symbol, unknown>
> {
constructor(sample: Record<string | symbol, unknown>, inverse = false) {
super(sample, inverse);
}

Expand All @@ -232,14 +238,12 @@ class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
let result = true;

const matcherContext = this.getMatcherContext();
for (const property in this.sample) {
const objectKeys = getObjectKeys(this.sample);

for (const key of objectKeys) {
if (
!hasProperty(other, property) ||
!equals(
this.sample[property],
other[property],
matcherContext.customTesters,
)
!hasProperty(other, key) ||
!equals(this.sample[key], other[key], matcherContext.customTesters)
) {
result = false;
break;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const groupOptions = (
replname: options.replname,
reporters: options.reporters,
rootDir: options.rootDir,
runInBand: options.runInBand,
runTestsByPath: options.runTestsByPath,
seed: options.seed,
shard: options.shard,
Expand Down
41 changes: 22 additions & 19 deletions packages/jest-core/src/__tests__/testSchedulerHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,34 @@ const getTestMock = () => ({
const getTestsMock = () => [getTestMock(), getTestMock()];

test.each`
tests | timings | detectOpenHandles | maxWorkers | watch | workerIdleMemoryLimit | expectedResult
${[getTestMock()]} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${2} | ${true} | ${undefined} | ${false}
${[getTestMock()]} | ${[2000, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestMock()} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${false} | ${undefined} | ${true}
${getTestMock()} | ${[2000, 500]} | ${false} | ${2} | ${false} | ${undefined} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${getTestsMock()} | ${[500, 500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${new Array(45)} | ${[500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${undefined} | ${false} | ${undefined} | ${true}
${[getTestMock()]} | ${[500, 500]} | ${false} | ${undefined} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${1} | ${false} | ${'500MB'} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[500, 500]} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${undefined} | ${false} | ${'500MB'} | ${true}
tests | timings | detectOpenHandles | runInBand | maxWorkers | watch | workerIdleMemoryLimit | expectedResult
${[getTestMock()]} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${2} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${true} | ${1} | ${true} | ${undefined} | ${true}
${[getTestMock()]} | ${[2000, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${false} | ${undefined} | ${true}
${getTestMock()} | ${[2000, 500]} | ${false} | ${false} | ${2} | ${false} | ${undefined} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${getTestsMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${new Array(45)} | ${[500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${undefined} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${false} | ${undefined} | ${false} | ${undefined} | ${true}
${[getTestMock()]} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${true} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${false} | ${false} | ${1} | ${false} | ${'500MB'} | ${false}
${[getTestMock()]} | ${[2000]} | ${false} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[500, 500]} | ${false} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${false}
${getTestsMock()} | ${[2000, 500]} | ${true} | ${false} | ${undefined} | ${false} | ${'500MB'} | ${true}
`(
'shouldRunInBand() - should return $expectedResult for runInBand mode',
({
tests,
timings,
detectOpenHandles,
maxWorkers,
runInBand,
watch,
workerIdleMemoryLimit,
expectedResult,
Expand All @@ -57,6 +59,7 @@ test.each`
shouldRunInBand(tests, timings, {
detectOpenHandles,
maxWorkers,
runInBand,
watch,
workerIdleMemoryLimit,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ exports[`prints the config object 1`] = `
"projects": [],
"reporters": [],
"rootDir": "/test_root_dir/",
"runInBand": false,
"runTestsByPath": false,
"seed": 1234,
"silent": false,
Expand Down
7 changes: 3 additions & 4 deletions packages/jest-core/src/testSchedulerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export function shouldRunInBand(
{
detectOpenHandles,
maxWorkers,
runInBand,
watch,
watchAll,
workerIdleMemoryLimit,
}: Config.GlobalConfig,
): boolean {
// If user asked for run in band, respect that.
// detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers
if (detectOpenHandles) {
if (runInBand || detectOpenHandles) {
return true;
}

Expand All @@ -39,9 +41,6 @@ export function shouldRunInBand(
* Otherwise, run in band if we only have one test or one worker available.
* Also, if we are confident from previous runs that the tests will finish
* quickly we also run in band to reduce the overhead of spawning workers.
* Finally, the user can provide the runInBand argument in the CLI to
* force running in band, which sets maxWorkers to 1 here:
* https://github.com/jestjs/jest/blob/d106643a8ee0ffa9c2f11c6bb2d12094e99135aa/packages/jest-config/src/getMaxWorkers.ts#L27-L28
*/
const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);
const oneWorkerOrLess = maxWorkers <= 1;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export type GlobalConfig = {
randomize?: boolean;
replname?: string;
reporters?: Array<ReporterConfig>;
runInBand: boolean;
runTestsByPath: boolean;
rootDir: string;
seed: number;
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const DEFAULT_GLOBAL_CONFIG: Config.GlobalConfig = {
replname: undefined,
reporters: [],
rootDir: '/test_root_dir/',
runInBand: false,
runTestsByPath: false,
seed: 1234,
silent: false,
Expand Down
8 changes: 8 additions & 0 deletions website/archivedVersions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"29.3": "https://jest-archive-august-2023.netlify.app/docs/29.3/getting-started/",
"29.2": "https://jest-archive-august-2023.netlify.app/docs/29.2/getting-started/",
"29.1": "https://jest-archive-august-2023.netlify.app/docs/29.1/getting-started/",
"29.0": "https://jest-archive-august-2023.netlify.app/docs/29.0/getting-started/",
"28.x": "https://jest-archive-august-2023.netlify.app/docs/28.x/getting-started/",
"27.x": "https://jest-archive-august-2023.netlify.app/docs/27.x/getting-started/",
"26.x": "https://jest-archive-august-2023.netlify.app/docs/26.x/getting-started/",
"25.x": "https://jest-archive-august-2023.netlify.app/docs/25.x/getting-started/",
"24.x": "https://archive.jestjs.io/docs/en/24.x/getting-started.html",
"23.x": "https://archive.jestjs.io/docs/en/23.x/getting-started.html",
"22.x": "https://archive.jestjs.io/docs/en/22.x/getting-started.html"
Expand Down
2 changes: 1 addition & 1 deletion website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const config = {
dropdownItemsAfter: [
...Object.entries(ArchivedVersions).map(
([versionName, versionUrl]) => ({
to: versionUrl,
href: versionUrl,
label: versionName,
})
),
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@docusaurus/plugin-pwa": "^2.0.0",
"@docusaurus/preset-classic": "^2.0.0",
"@docusaurus/remark-plugin-npm2yarn": "^2.0.0",
"clsx": "^1.1.1",
"clsx": "^2.0.0",
"docusaurus-remark-plugin-tab-blocks": "^1.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
3 changes: 2 additions & 1 deletion website/src/pages/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default function VersionsPage() {
</table>
<h3 id="archive">Archived Versions</h3>
<p>
Here you can find documentation for archived versions of Jest.
Here you can find archived documentation for older versions of
Jest.
</p>
<table>
<tbody>
Expand Down
16 changes: 0 additions & 16 deletions website/versioned_docs/version-25.x/Architecture.md

This file was deleted.

58 changes: 0 additions & 58 deletions website/versioned_docs/version-25.x/BypassingModuleMocks.md

This file was deleted.

Loading

0 comments on commit 34d589c

Please sign in to comment.