Skip to content

Commit b0cbcbf

Browse files
authored
export functions compatible with import jest from 'jest' (#8081)
1 parent 5c726bd commit b0cbcbf

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Fixes
66

7+
- `[jest-cli]` export functions compatible with `import {default}` ([#8080](https://github.com/facebook/jest/pull/8080))
8+
79
### Chore & Maintenance
810

911
- `[pretty-format]`: Use `react-is` instead of manual `$$typeof` checks ([#8060](https://github.com/facebook/jest/pull/8060))

e2e/__tests__/runProgrammatically.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {run} from '../Utils';
1111

1212
const dir = resolve(__dirname, '..', 'run-programmatically');
1313

14-
test('run Jest programatically', () => {
14+
test('run Jest programmatically cjs', () => {
15+
const {stdout} = run(`node cjs.js --version`, dir);
16+
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
17+
});
18+
19+
test('run Jest programmatically esm', () => {
1520
const {stdout} = run(`node index.js --version`, dir);
1621
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
1722
});
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
2+
3+
module.exports = {
4+
presets: ['@babel/preset-env'],
5+
};

e2e/run-programmatically/cjs.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
* @flow
8+
*/
9+
10+
// Running Jest like this is not officially supported,
11+
// but it is common practice until there is a proper API as a substitute.
12+
require('jest').run(process.argv);

e2e/run-programmatically/esm.js

+14
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+
* @flow
8+
*/
9+
10+
import myJestImport from 'jest';
11+
12+
// Running Jest like this is not officially supported,
13+
// but it is common practice until there is a proper API as a substitute.
14+
myJestImport.run(process.argv);

e2e/run-programmatically/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
* @flow
99
*/
1010

11-
// Running Jest like this is not officially supported,
12-
// but it is common practice until there is a proper API as a substitute.
13-
require('jest').run(process.argv);
11+
require('@babel/register');
12+
13+
require('./esm');

packages/jest-cli/src/index.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
// TODO: remove exports for the next major
9-
export {runCLI, SearchSource, TestScheduler, TestWatcher} from '@jest/core';
10-
export {run} from './cli';
11-
export {default as getVersion} from './version';
8+
// TODO: remove @jest/core exports for the next major
9+
import {runCLI, SearchSource, TestScheduler, TestWatcher} from '@jest/core';
10+
import {run} from './cli';
11+
import {default as getVersion} from './version';
12+
13+
export = {
14+
SearchSource,
15+
TestScheduler,
16+
TestWatcher,
17+
getVersion,
18+
run,
19+
runCLI,
20+
};

0 commit comments

Comments
 (0)