Skip to content

Commit

Permalink
feat: support transpiled transformers (#11193)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Mar 14, 2021
1 parent dd13096 commit 8717975
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- `[jest-transform]` Add support for transformers written in ESM ([#11163](https://github.com/facebook/jest/pull/11163))
- `[jest-transform]` [**BREAKING**] Do not export `ScriptTransformer` class, instead export the async function `createScriptTransformer` ([#11163](https://github.com/facebook/jest/pull/11163))
- `[jest-transform]` Async code transformations ([#9889](https://github.com/facebook/jest/pull/9889))
- `[jest-transform]` Support transpiled transformers ([#11193](https://github.com/facebook/jest/pull/11193))
- `[jest-worker]` Add support for custom task queues and adds a `PriorityQueue` implementation. ([#10921](https://github.com/facebook/jest/pull/10921))
- `[jest-worker]` Add in-order scheduling policy to jest worker ([10902](https://github.com/facebook/jest/pull/10902))

Expand Down Expand Up @@ -73,6 +74,7 @@
- `[*]` [**BREAKING**] Add `exports` field to all `package.json`s ([#9921](https://github.com/facebook/jest/pull/9921))
- `[*]` Make it easier for Jest's packages to use the VM escape hatch ([#10824](https://github.com/facebook/jest/pull/10824))
- `[*]` [**BREAKING**] Remove deprecated `mapCoverage` ([#9968](https://github.com/facebook/jest/pull/9968))
- `[babel-jest]` [**BREAKING**] Migrate to ESM ([#11193](https://github.com/facebook/jest/pull/11193))
- `[docs]` Correct example using `browser-resolve` ([#11140](https://github.com/facebook/jest/pull/11140))
- `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787))
- `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126))
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FAIL __tests__/ignoredFile.test.js
babel-jest: Babel ignores __tests__/ignoredFile.test.js - make sure to include the file in Jest's transformIgnorePatterns as well.
at loadBabelConfig (../../../packages/babel-jest/build/index.js:190:13)
at loadBabelConfig (../../../packages/babel-jest/build/index.js:195:13)
`;

exports[`babel-jest instruments only specific files and collects coverage 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion e2e/transform/babel-jest-manual/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

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

module.exports = createTransformer({
presets: ['@babel/preset-flow'],
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

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

jest.mock('../loadBabelConfig', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ const transformer: SyncTransformer<TransformOptions> = {
createTransformer,
};

export = transformer;
export default transformer;
2 changes: 1 addition & 1 deletion packages/jest-repl/src/__tests__/jest_repl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';

import {spawnSync} from 'child_process';
import path from 'path';
Expand All @@ -29,6 +28,7 @@ describe('Repl', () => {
encoding: 'utf8',
env: process.env,
});
expect(output.stderr.trim()).toBe('');
expect(output.stdout.trim()).toMatch(//);
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-repl/src/cli/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as repl from 'repl';
import {runInThisContext} from 'vm';
import type {SyncTransformer} from '@jest/transform';
import type {Config} from '@jest/types';
import {interopRequireDefault} from 'jest-util';

// TODO: support async as well
let transformer: SyncTransformer;
Expand Down Expand Up @@ -77,7 +78,7 @@ if (jestProjectConfig.transform) {
}
}
if (transformerPath) {
transformer = require(transformerPath);
transformer = interopRequireDefault(require(transformerPath)).default;
if (typeof transformer.process !== 'function') {
throw new TypeError(
'Jest: a transformer must export a `process` function.',
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class ScriptTransformer {
let transformer: Transformer;

try {
transformer = require(transformPath);
transformer = interopRequireDefault(require(transformPath)).default;
} catch (error) {
if (error.code === 'ERR_REQUIRE_ESM') {
const configUrl = pathToFileURL(transformPath);
Expand Down

0 comments on commit 8717975

Please sign in to comment.