Skip to content

Commit

Permalink
feat: use @babel/plugin-transform-runtime instead of regenerator-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee committed Jan 10, 2019
1 parent 50c3852 commit f3ca428
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 93 deletions.
4 changes: 0 additions & 4 deletions e2e/custom-resolver/__tests__/customResolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ test('should use the custom resolver', () => {
require('foo');
});

test('should have regenerator injected', () => {
expect(global.fakeRegeneratorInjected).toEqual(true);
});

test('should work with automock', () => {
jest.mock('foo');

Expand Down
3 changes: 0 additions & 3 deletions e2e/custom-resolver/fakeRegenerator.js

This file was deleted.

6 changes: 1 addition & 5 deletions e2e/custom-resolver/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ const {
default: defaultResolver,
} = require('jest-resolve/build/defaultResolver');

const exportedModules = new Map([
['foo', 'foo'],
['bar', 'bar'],
['regenerator-runtime/runtime', 'fakeRegenerator'],
]);
const exportedModules = new Map([['foo', 'foo'], ['bar', 'bar']]);

module.exports = (name, options) => {
const resolution = exportedModules.get(name);
Expand Down
9 changes: 1 addition & 8 deletions examples/async/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
module.exports = {
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true,
},
],
],
plugins: ['@babel/plugin-transform-runtime'],
presets: ['@babel/preset-env'],
};
3 changes: 1 addition & 2 deletions examples/snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"@babel/preset-react": "*",
"babel-jest": "*",
"jest": "*",
"react-test-renderer": "*",
"regenerator-runtime": "*"
"react-test-renderer": "*"
},
"scripts": {
"test": "jest"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"@babel/runtime": "^7.0.0",
"ansi-regex": "^4.0.0",
"ansi-styles": "^3.2.0",
"babel-eslint": "^9.0.0",
Expand Down Expand Up @@ -52,7 +53,6 @@
"progress": "^2.0.0",
"promise": "^8.0.2",
"readable-stream": "^3.0.3",
"regenerator-runtime": "^0.12.1",
"resolve": "^1.4.0",
"rimraf": "^2.6.2",
"rollup": "^0.66.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"main": "build/index.js",
"dependencies": {
"babel-plugin-istanbul": "^5.1.0",
"babel-preset-jest": "^23.2.0"
"babel-preset-jest": "^23.2.0",
"@babel/plugin-transform-runtime": "^7.2.0"
},
"devDependencies": {
"@babel/core": "^7.1.0"
Expand Down
47 changes: 1 addition & 46 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,6 @@ describe('babel-jest', () => {

expect(options.transform[0][0]).toBe(DEFAULT_JS_PATTERN);
expect(options.transform[0][1]).toEqual(require.resolve('babel-jest'));
expect(options.setupFiles).toEqual([
path.sep +
'node_modules' +
path.sep +
'regenerator-runtime' +
path.sep +
'runtime',
]);
});

it('uses babel-jest if babel-jest is explicitly specified in a custom transform options', () => {
Expand All @@ -762,38 +754,6 @@ describe('babel-jest', () => {

expect(options.transform[0][0]).toBe(customJSPattern);
expect(options.transform[0][1]).toEqual(require.resolve('babel-jest'));
expect(options.setupFiles).toEqual([
path.sep +
'node_modules' +
path.sep +
'regenerator-runtime' +
path.sep +
'runtime',
]);
});

it('uses regenerator if babel-jest is explicitly specified', () => {
const ROOT_DIR = '<rootDir>' + path.sep;

const {options} = normalize(
{
rootDir: '/root',
transform: {
[DEFAULT_JS_PATTERN]:
ROOT_DIR + Resolver.findNodeModule('babel-jest'),
},
},
{},
);

expect(options.setupFiles).toEqual([
path.sep +
'node_modules' +
path.sep +
'regenerator-runtime' +
path.sep +
'runtime',
]);
});
});

Expand Down Expand Up @@ -1188,12 +1148,7 @@ describe('preset without setupFiles', () => {
);

expect(options).toEqual(
expect.objectContaining({
setupFiles: [
'/node_modules/regenerator-runtime/runtime',
'/node_modules/a',
],
}),
expect.objectContaining({setupFiles: ['/node_modules/a']}),
);
});
});
Expand Down
16 changes: 2 additions & 14 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ const setupBabelJest = (options: InitialOptions) => {
[DEFAULT_JS_PATTERN]: babelJest,
};
}

return babelJest;
};

const normalizeCollectCoverageOnlyFrom = (
Expand Down Expand Up @@ -446,7 +444,8 @@ export default function normalize(options: InitialOptions, argv: Argv) {
options.coverageDirectory = path.resolve(options.rootDir, 'coverage');
}

const babelJest = setupBabelJest(options);
setupBabelJest(options);

const newOptions: $Shape<
DefaultOptions & ProjectConfig & GlobalConfig,
> = (Object.assign({}, DEFAULT_CONFIG): any);
Expand Down Expand Up @@ -774,17 +773,6 @@ export default function normalize(options: InitialOptions, argv: Argv) {

newOptions.maxWorkers = getMaxWorkers(argv);

if (babelJest) {
const regeneratorRuntimePath = Resolver.findNodeModule(
'regenerator-runtime/runtime',
{basedir: options.rootDir, resolver: newOptions.resolver},
);

if (regeneratorRuntimePath) {
newOptions.setupFiles.unshift(regeneratorRuntimePath);
}
}

if (newOptions.testRegex.length && options.testMatch) {
throw createConfigError(
` Configuration options ${chalk.bold('testMatch')} and` +
Expand Down
28 changes: 19 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,17 @@
dependencies:
regenerator-transform "^0.13.3"

"@babel/plugin-transform-runtime@*", "@babel/plugin-transform-runtime@^7.0.0":
"@babel/plugin-transform-runtime@*", "@babel/plugin-transform-runtime@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.2.0.tgz#566bc43f7d0aedc880eaddbd29168d0f248966ea"
integrity sha512-jIgkljDdq4RYDnJyQsiWbdvGeei/0MOTtSHKO/rfbd/mXBxNpdlulMx49L0HQ4pug1fXannxoqCI+fYSle9eSw==
dependencies:
"@babel/helper-module-imports" "^7.0.0"
"@babel/helper-plugin-utils" "^7.0.0"
resolve "^1.8.1"
semver "^5.5.1"

"@babel/plugin-transform-runtime@^7.0.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.1.0.tgz#9f76920d42551bb577e2dc594df229b5f7624b63"
integrity sha512-WFLMgzu5DLQEah0lKTJzYb14vd6UiES7PTnXcvrPZ1VrwFeJ+mTbvr65fFAsXYMt2bIoOoC0jk76zY1S7HZjUg==
Expand Down Expand Up @@ -797,9 +807,9 @@
source-map-support "^0.5.9"

"@babel/runtime@*", "@babel/runtime@^7.0.0":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.1.2.tgz#81c89935f4647706fc54541145e6b4ecfef4b8e3"
integrity sha512-Y3SCjmhSupzFB6wcv1KmmFucH6gDVnI30WjOcicV10ju0cZjak3Jcs67YLIXBrmZYw1xCrVeJPbycFwrqNyxpg==
version "7.2.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.2.0.tgz#b03e42eeddf5898e00646e4c840fa07ba8dcad7f"
integrity sha512-oouEibCbHMVdZSDlJBO6bZmID/zA/G/Qx3H1d3rSNPTD+L8UNKvCat7aKWSJ74zYbm5zWGh0GQN0hKj8zYFTCg==
dependencies:
regenerator-runtime "^0.12.0"

Expand Down Expand Up @@ -11299,11 +11309,6 @@ regenerate@^1.4.0:
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==

regenerator-runtime@*, regenerator-runtime@^0.12.0, regenerator-runtime@^0.12.1:
version "0.12.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de"
integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==

regenerator-runtime@^0.10.0:
version "0.10.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"
Expand All @@ -11314,6 +11319,11 @@ regenerator-runtime@^0.11.0, regenerator-runtime@^0.11.1:
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==

regenerator-runtime@^0.12.0:
version "0.12.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de"
integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==

regenerator-transform@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.13.3.tgz#264bd9ff38a8ce24b06e0636496b2c856b57bcbb"
Expand Down

0 comments on commit f3ca428

Please sign in to comment.