Skip to content

Commit 043a8b2

Browse files
drownbescpojer
authored andcommitted
moduleFileExtensions extensions is now passed to babel-jest (#5110)
* 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
1 parent 95c0e5f commit 043a8b2

8 files changed

Lines changed: 59 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ None for now
44

55
### Fixes
66

7+
* `[babel-jest]` moduleFileExtensions not passed to babel transformer.
8+
([#4637](https://github.com/facebook/jest/issues/4637))
9+
710
### Features
811

912
### Chore & Maintenance

integration_tests/__tests__/transform.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,18 @@ describe('multiple-transformers', () => {
120120
expect(json.numPassedTests).toBe(1);
121121
});
122122
});
123+
124+
describe('ecmascript-modules-support', () => {
125+
const dir = path.resolve(
126+
__dirname,
127+
'..',
128+
'transform/ecmascript-modules-support',
129+
);
130+
131+
it('runs transpiled code', () => {
132+
// --no-cache because babel can cache stuff and result in false green
133+
const {json} = runJest.json(dir, ['--no-cache']);
134+
expect(json.success).toBe(true);
135+
expect(json.numTotalTests).toBeGreaterThanOrEqual(1);
136+
});
137+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"node": "current"
6+
},
7+
"modules": "commonjs"
8+
}]
9+
]
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. 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+
'use strict';
8+
9+
import {foo} from '../src/module';
10+
11+
it('can be used with mjs files using babel-jest', () => {
12+
expect(foo()).toBe('a');
13+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node",
4+
"moduleFileExtensions": ["js", "json", "jsx", "node", "mjs"],
5+
"testMatch": [ "**/__tests__/**/*.mjs"],
6+
"transform": {
7+
"^.+\\.mjs?$": "../../../packages/babel-jest"
8+
}
9+
}
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {foo} from './module';
2+
3+
foo();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = () => 'a';

packages/babel-jest/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ const createTransformer = (options: any) => {
104104
config: ProjectConfig,
105105
transformOptions: TransformOptions,
106106
): string {
107-
if (babelUtil && !babelUtil.canCompile(filename)) {
107+
const altExts = config.moduleFileExtensions.map(
108+
extension => '.' + extension,
109+
);
110+
if (babelUtil && !babelUtil.canCompile(filename, altExts)) {
108111
return src;
109112
}
110113

0 commit comments

Comments
 (0)