Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export babel-preset-jest as a function #7203

Merged
merged 2 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- `[jest-runtime]` Fix missing coverage when using negative glob pattern in `testMatch` ([#7170](https://github.com/facebook/jest/pull/7170))
- `[*]` Ensure `maxWorkers` is at least 1 (was 0 in some cases where there was only 1 CPU) ([#7182](https://github.com/facebook/jest/pull/7182))
- `[jest-runtime]` Fix transform cache invalidation when requiring a test file from multiple projects ([#7186](https://github.com/facebook/jest/pull/7186))
- `[babel-preset-jest]` [**BREAKING**] Export a function instead of an object for Babel 7 compatibility ([#7203](https://github.com/facebook/jest/pull/7203))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking for people doing require like we used to, not for people just doing "babel-preset-jest" as a string


### Chore & Maintenance

Expand Down
2 changes: 1 addition & 1 deletion e2e/coverage-transform-instrumented/Preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

const jestPreset = require('babel-preset-jest');
const {transform: babelTransform} = require('babel-core');
const {default: babelIstanbulPlugin} = require('babel-plugin-istanbul');
const jestPreset = require.resolve('babel-preset-jest');

const options = {
presets: ['env', jestPreset],
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
import jestPreset from 'babel-preset-jest';
import {transform as babelTransform, util as babelUtil} from 'babel-core';
import babelIstanbulPlugin from 'babel-plugin-istanbul';

Expand All @@ -28,6 +27,7 @@ const BABEL_CONFIG_JS_FILENAME = 'babel.config.js';
const BABEL_CONFIG_KEY = 'babel';
const PACKAGE_JSON = 'package.json';
const THIS_FILE = fs.readFileSync(__filename);
const jestPresetPath = require.resolve('babel-preset-jest');

const createTransformer = (options: any): Transformer => {
const cache = Object.create(null);
Expand Down Expand Up @@ -81,7 +81,7 @@ const createTransformer = (options: any): Transformer => {
options = Object.assign({}, options, {
compact: false,
plugins: (options && options.plugins) || [],
presets: ((options && options.presets) || []).concat([jestPreset]),
presets: ((options && options.presets) || []).concat(jestPresetPath),
sourceMaps: 'both',
});
delete options.cacheDirectory;
Expand Down
9 changes: 4 additions & 5 deletions packages/babel-preset-jest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

module.exports = {
module.exports = () => ({
plugins: [
// Cannot be `import` as this file is not compiled
require('babel-plugin-jest-hoist'),
require('babel-plugin-syntax-object-rest-spread'),
require.resolve('babel-plugin-jest-hoist'),
require.resolve('babel-plugin-syntax-object-rest-spread'),
],
};
});