Skip to content

Commit

Permalink
export functions compatible with import jest from 'jest' (#8081)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 7, 2019
1 parent 5c726bd commit b0cbcbf
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-cli]` export functions compatible with `import {default}` ([#8080](https://github.com/facebook/jest/pull/8080))

### Chore & Maintenance

- `[pretty-format]`: Use `react-is` instead of manual `$$typeof` checks ([#8060](https://github.com/facebook/jest/pull/8060))
Expand Down
7 changes: 6 additions & 1 deletion e2e/__tests__/runProgrammatically.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {run} from '../Utils';

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

test('run Jest programatically', () => {
test('run Jest programmatically cjs', () => {
const {stdout} = run(`node cjs.js --version`, dir);
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
});

test('run Jest programmatically esm', () => {
const {stdout} = run(`node index.js --version`, dir);
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
});
5 changes: 5 additions & 0 deletions e2e/run-programmatically/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

module.exports = {
presets: ['@babel/preset-env'],
};
12 changes: 12 additions & 0 deletions e2e/run-programmatically/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

// Running Jest like this is not officially supported,
// but it is common practice until there is a proper API as a substitute.
require('jest').run(process.argv);
14 changes: 14 additions & 0 deletions e2e/run-programmatically/esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import myJestImport from 'jest';

// Running Jest like this is not officially supported,
// but it is common practice until there is a proper API as a substitute.
myJestImport.run(process.argv);
6 changes: 3 additions & 3 deletions e2e/run-programmatically/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
* @flow
*/

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

require('./esm');
17 changes: 13 additions & 4 deletions packages/jest-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* LICENSE file in the root directory of this source tree.
*/

// TODO: remove exports for the next major
export {runCLI, SearchSource, TestScheduler, TestWatcher} from '@jest/core';
export {run} from './cli';
export {default as getVersion} from './version';
// TODO: remove @jest/core exports for the next major
import {runCLI, SearchSource, TestScheduler, TestWatcher} from '@jest/core';
import {run} from './cli';
import {default as getVersion} from './version';

export = {
SearchSource,
TestScheduler,
TestWatcher,
getVersion,
run,
runCLI,
};

0 comments on commit b0cbcbf

Please sign in to comment.