Skip to content

Commit 8717975

Browse files
authored
feat: support transpiled transformers (#11193)
1 parent dd13096 commit 8717975

File tree

8 files changed

+10
-7
lines changed

8 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- `[jest-transform]` Add support for transformers written in ESM ([#11163](https://github.com/facebook/jest/pull/11163))
2727
- `[jest-transform]` [**BREAKING**] Do not export `ScriptTransformer` class, instead export the async function `createScriptTransformer` ([#11163](https://github.com/facebook/jest/pull/11163))
2828
- `[jest-transform]` Async code transformations ([#9889](https://github.com/facebook/jest/pull/9889))
29+
- `[jest-transform]` Support transpiled transformers ([#11193](https://github.com/facebook/jest/pull/11193))
2930
- `[jest-worker]` Add support for custom task queues and adds a `PriorityQueue` implementation. ([#10921](https://github.com/facebook/jest/pull/10921))
3031
- `[jest-worker]` Add in-order scheduling policy to jest worker ([10902](https://github.com/facebook/jest/pull/10902))
3132

@@ -73,6 +74,7 @@
7374
- `[*]` [**BREAKING**] Add `exports` field to all `package.json`s ([#9921](https://github.com/facebook/jest/pull/9921))
7475
- `[*]` Make it easier for Jest's packages to use the VM escape hatch ([#10824](https://github.com/facebook/jest/pull/10824))
7576
- `[*]` [**BREAKING**] Remove deprecated `mapCoverage` ([#9968](https://github.com/facebook/jest/pull/9968))
77+
- `[babel-jest]` [**BREAKING**] Migrate to ESM ([#11193](https://github.com/facebook/jest/pull/11193))
7678
- `[docs]` Correct example using `browser-resolve` ([#11140](https://github.com/facebook/jest/pull/11140))
7779
- `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787))
7880
- `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126))

e2e/__tests__/__snapshots__/transform.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FAIL __tests__/ignoredFile.test.js
66
77
babel-jest: Babel ignores __tests__/ignoredFile.test.js - make sure to include the file in Jest's transformIgnorePatterns as well.
88
9-
at loadBabelConfig (../../../packages/babel-jest/build/index.js:190:13)
9+
at loadBabelConfig (../../../packages/babel-jest/build/index.js:195:13)
1010
`;
1111

1212
exports[`babel-jest instruments only specific files and collects coverage 1`] = `

e2e/transform/babel-jest-manual/transformer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const {createTransformer} = require('babel-jest');
8+
const {createTransformer} = require('babel-jest').default;
99

1010
module.exports = createTransformer({
1111
presets: ['@babel/preset-flow'],

packages/babel-jest/src/__tests__/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import {makeProjectConfig} from '@jest/test-utils';
9-
import babelJest = require('../index');
9+
import babelJest from '../index';
1010
import {loadPartialConfig} from '../loadBabelConfig';
1111

1212
jest.mock('../loadBabelConfig', () => {

packages/babel-jest/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ const transformer: SyncTransformer<TransformOptions> = {
167167
createTransformer,
168168
};
169169

170-
export = transformer;
170+
export default transformer;

packages/jest-repl/src/__tests__/jest_repl.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
*/
8-
'use strict';
98

109
import {spawnSync} from 'child_process';
1110
import path from 'path';
@@ -29,6 +28,7 @@ describe('Repl', () => {
2928
encoding: 'utf8',
3029
env: process.env,
3130
});
31+
expect(output.stderr.trim()).toBe('');
3232
expect(output.stdout.trim()).toMatch(//);
3333
});
3434
});

packages/jest-repl/src/cli/repl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as repl from 'repl';
1313
import {runInThisContext} from 'vm';
1414
import type {SyncTransformer} from '@jest/transform';
1515
import type {Config} from '@jest/types';
16+
import {interopRequireDefault} from 'jest-util';
1617

1718
// TODO: support async as well
1819
let transformer: SyncTransformer;
@@ -77,7 +78,7 @@ if (jestProjectConfig.transform) {
7778
}
7879
}
7980
if (transformerPath) {
80-
transformer = require(transformerPath);
81+
transformer = interopRequireDefault(require(transformerPath)).default;
8182
if (typeof transformer.process !== 'function') {
8283
throw new TypeError(
8384
'Jest: a transformer must export a `process` function.',

packages/jest-transform/src/ScriptTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class ScriptTransformer {
255255
let transformer: Transformer;
256256

257257
try {
258-
transformer = require(transformPath);
258+
transformer = interopRequireDefault(require(transformPath)).default;
259259
} catch (error) {
260260
if (error.code === 'ERR_REQUIRE_ESM') {
261261
const configUrl = pathToFileURL(transformPath);

0 commit comments

Comments
 (0)