Skip to content

Commit fc0f616

Browse files
committed
Merge branch 'master' into import-transformers
2 parents f1844a0 + 3c679f1 commit fc0f616

21 files changed

Lines changed: 150 additions & 117 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44

5+
- `[jest-changed-files]` Use '--' to separate paths from revisions ([#11160](https://github.com/facebook/jest/pull/11160))
56
- `[jest-circus]` [**BREAKING**] Fail tests when multiple `done()` calls are made ([#10624](https://github.com/facebook/jest/pull/10624))
67
- `[jest-circus, jest-jasmine2]` [**BREAKING**] Fail the test instead of just warning when describe returns a value ([#10947](https://github.com/facebook/jest/pull/10947))
78
- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
@@ -39,6 +40,7 @@
3940
- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638))
4041
- `[jest-core]` Don't report PerformanceObserver as open handle ([#11123](https://github.com/facebook/jest/pull/11123))
4142
- `[jest-each]` [**BREAKING**] Ignore excess words in headings ([#8766](https://github.com/facebook/jest/pull/8766))
43+
- `[jest-environment]` [**BREAKING**] Drop support for `runScript` for test environments ([#11155](https://github.com/facebook/jest/pull/11155))
4244
- `[jest-environment-jsdom]` Use inner realm’s `ArrayBuffer` constructor ([#10885](https://github.com/facebook/jest/pull/10885))
4345
- `[jest-globals]` [**BREAKING**] Disallow return values other than a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
4446
- `[jest-globals]` [**BREAKING**] Disallow mixing a done callback and returning a `Promise` from hooks and tests ([#10512](https://github.com/facebook/jest/pull/10512))
@@ -59,6 +61,7 @@
5961
- `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options ([#10834](https://github.com/facebook/jest/pull/10834))
6062
- `[jest-worker]` [**BREAKING**] Use named exports ([#10623](https://github.com/facebook/jest/pull/10623))
6163
- `[jest-worker]` Do not swallow errors during serialization ([#10984](https://github.com/facebook/jest/pull/10984))
64+
- `[jest-worker]` Handle `ERR_IPC_CHANNEL_CLOSED` errors properly ([#11143](https://github.com/facebook/jest/pull/11143))
6265
- `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515))
6366
- `[pretty-format]` Only call `hasAttribute` if it's a function ([#11000](https://github.com/facebook/jest/pull/11000))
6467

@@ -83,8 +86,9 @@
8386
- `[jest-reporters]` [**BREAKING**] Make `node-notifier` a peer dependency ([#10977](https://github.com/facebook/jest/pull/10977))
8487
- `[jest-resolve, jest-runtime]` [**BREAKING**] Use `Map`s instead of objects for all cached resources ([#10968](https://github.com/facebook/jest/pull/10968))
8588
- `[jest-runner]` [**BREAKING**] Migrate to ESM ([#10900](https://github.com/facebook/jest/pull/10900))
86-
- `[jest-runtime]` [**BREAKING**] Remove deprecated and unnused `getSourceMapInfo` from Runtime ([#9969](https://github.com/facebook/jest/pull/9969))
89+
- `[jest-runtime]` [**BREAKING**] Remove deprecated and unused `getSourceMapInfo` from Runtime ([#9969](https://github.com/facebook/jest/pull/9969))
8790
- `[jest-runtime]` Detect reexports from CJS as named exports in ESM ([#10988](https://github.com/facebook/jest/pull/10988))
91+
- `[jest-transformer]` [**BREAKING**] Remove unused `isCoreModule` option ([#11166](https://github.com/facebook/jest/pull/11166))
8892
- `[jest-util]` No longer checking `enumerable` when adding `process.domain` ([#10862](https://github.com/facebook/jest/pull/10862))
8993
- `[jest-validate]` [**BREAKING**] Remove `recursiveBlacklist ` option in favor of previously introduced `recursiveDenylist` ([#10650](https://github.com/facebook/jest/pull/10650))
9094

docs/Configuration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ test('use jsdom in this test file', () => {
10301030
});
10311031
```
10321032

1033-
You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `runScript` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables.
1033+
You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `getVmContext` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables.
10341034

10351035
The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases.
10361036

@@ -1076,8 +1076,8 @@ class CustomEnvironment extends NodeEnvironment {
10761076
await super.teardown();
10771077
}
10781078

1079-
runScript(script) {
1080-
return super.runScript(script);
1079+
getVmContext() {
1080+
return super.getVmContext();
10811081
}
10821082

10831083
async handleTestEvent(event, state) {

docs/Puppeteer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class PuppeteerEnvironment extends NodeEnvironment {
110110
await super.teardown();
111111
}
112112

113-
runScript(script) {
114-
return super.runScript(script);
113+
getVmContext() {
114+
return super.getVmContext();
115115
}
116116
}
117117

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`throw error if test env does not have getVmContext 1`] = `"Test environment found at \\"<rootDir>/EnvUsingRunScript.js\\" does not export a \\"getVmContext\\" method, which is mandatory from Jest 27. This method is a replacement for \\"runScript\\"."`;

e2e/__tests__/jestChangedFiles.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ function gitInit(dir: string) {
4444
run(initCommand, dir);
4545
}
4646

47+
function gitCreateBranch(branchName: string, dir: string) {
48+
run(`git branch ${branchName}`, dir);
49+
}
50+
4751
beforeEach(() => cleanup(DIR));
4852
afterEach(() => cleanup(DIR));
4953

@@ -171,9 +175,11 @@ test('gets changed files for git', async () => {
171175
gitInit(DIR);
172176

173177
const roots = [
174-
'',
178+
// same first root name with existing branch name makes pitfall that
179+
// causes "ambiguous argument" git error.
175180
'nested-dir',
176181
'nested-dir/second-nested-dir',
182+
'',
177183
].map(filename => path.resolve(DIR, filename));
178184

179185
let {changedFiles: files} = await getChangedFilesForRoots(roots, {});
@@ -190,6 +196,8 @@ test('gets changed files for git', async () => {
190196
// returns files and not parts of commit messages.
191197
run(`${GIT} commit --no-gpg-sign -m "test" -m "extra-line"`, DIR);
192198

199+
gitCreateBranch('nested-dir', DIR);
200+
193201
({changedFiles: files} = await getChangedFilesForRoots(roots, {}));
194202
expect(Array.from(files)).toEqual([]);
195203

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {resolve, sep} from 'path';
9+
import runJest from '../runJest';
10+
11+
it('throw error if test env does not have getVmContext', () => {
12+
const DIR = resolve(__dirname, '../test-environment-run-script');
13+
const {exitCode, stderr} = runJest(DIR);
14+
15+
expect(stderr.replace(`${DIR}${sep}`, '<rootDir>/')).toMatchSnapshot();
16+
expect(exitCode).toBe(1);
17+
});

e2e/test-environment-async/TestEnvironment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class TestEnvironment extends JSDOMEnvironment {
3434
});
3535
}
3636

37-
runScript(script) {
38-
return super.runScript(script);
37+
getVmContext() {
38+
return super.getVmContext();
3939
}
4040
}
4141

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
module.exports = class Env {
10+
constructor() {
11+
this.global = global;
12+
this.moduleMocker = {};
13+
}
14+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
test('dummy', () => {
10+
throw new Error('nothing to see here');
11+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "<rootDir>/EnvUsingRunScript.js"
4+
}
5+
}

0 commit comments

Comments
 (0)