Skip to content

Commit

Permalink
moduleFileExtensions extensions is now passed to babel-jest (#5110)
Browse files Browse the repository at this point in the history
* moduleFileExtensions extensions is now passed to babel-jest

* Added test to show use of custom files extensions with babel-jest

CHANGELOG: moduleFileExtensions now passed to babel transformer

* Cleanup

Cleaned integration_tests/transform/ecmascript-modules-support/yarn.lock
Cleaned integration_tests/transform/ecmascript-modules-support/package.json
Enable testing on windows

* Remove yarn lock

* Add changelog line
  • Loading branch information
drownbes authored and cpojer committed Dec 22, 2017
1 parent 95c0e5f commit 043a8b2
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ None for now

### Fixes

* `[babel-jest]` moduleFileExtensions not passed to babel transformer.
([#4637](https://github.com/facebook/jest/issues/4637))

### Features

### Chore & Maintenance
Expand Down
15 changes: 15 additions & 0 deletions integration_tests/__tests__/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,18 @@ describe('multiple-transformers', () => {
expect(json.numPassedTests).toBe(1);
});
});

describe('ecmascript-modules-support', () => {
const dir = path.resolve(
__dirname,
'..',
'transform/ecmascript-modules-support',
);

it('runs transpiled code', () => {
// --no-cache because babel can cache stuff and result in false green
const {json} = runJest.json(dir, ['--no-cache']);
expect(json.success).toBe(true);
expect(json.numTotalTests).toBeGreaterThanOrEqual(1);
});
});
10 changes: 10 additions & 0 deletions integration_tests/transform/ecmascript-modules-support/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
["env", {
"targets": {
"node": "current"
},
"modules": "commonjs"
}]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. 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.
*/
'use strict';

import {foo} from '../src/module';

it('can be used with mjs files using babel-jest', () => {
expect(foo()).toBe('a');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jest": {
"testEnvironment": "node",
"moduleFileExtensions": ["js", "json", "jsx", "node", "mjs"],
"testMatch": [ "**/__tests__/**/*.mjs"],
"transform": {
"^.+\\.mjs?$": "../../../packages/babel-jest"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {foo} from './module';

foo();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = () => 'a';
5 changes: 4 additions & 1 deletion packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ const createTransformer = (options: any) => {
config: ProjectConfig,
transformOptions: TransformOptions,
): string {
if (babelUtil && !babelUtil.canCompile(filename)) {
const altExts = config.moduleFileExtensions.map(
extension => '.' + extension,
);
if (babelUtil && !babelUtil.canCompile(filename, altExts)) {
return src;
}

Expand Down

0 comments on commit 043a8b2

Please sign in to comment.