From 2411699b199d441b3ac59684c2d926cc2e42ae78 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 14 Mar 2021 10:44:02 +0100 Subject: [PATCH 1/5] feat: support transpiled transformers --- CHANGELOG.md | 2 ++ packages/babel-jest/src/index.ts | 2 +- packages/jest-transform/src/ScriptTransformer.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bddfa129c71..2c18e8419413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 - `[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)) @@ -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 - `[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)) diff --git a/packages/babel-jest/src/index.ts b/packages/babel-jest/src/index.ts index c0bff0b5d336..c7048c37a395 100644 --- a/packages/babel-jest/src/index.ts +++ b/packages/babel-jest/src/index.ts @@ -167,4 +167,4 @@ const transformer: SyncTransformer = { createTransformer, }; -export = transformer; +export default transformer; diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 7ce6c8d1554f..249f72b43188 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -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); From 0fdd60b6339b78d7e04b015b442f08513c536abf Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 14 Mar 2021 10:48:00 +0100 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c18e8419413..2305497c06f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +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 +- `[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)) @@ -74,7 +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 +- `[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)) From 4182cccf86f5dda99e1189b51703902b00643dd7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 14 Mar 2021 10:55:48 +0100 Subject: [PATCH 3/5] fix import in test --- packages/babel-jest/src/__tests__/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-jest/src/__tests__/index.ts b/packages/babel-jest/src/__tests__/index.ts index 445a50d8dec8..9d79de986d36 100644 --- a/packages/babel-jest/src/__tests__/index.ts +++ b/packages/babel-jest/src/__tests__/index.ts @@ -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', () => { From fa68cfe3551bb8b420f8fb16c500f5f4eae771ad Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 14 Mar 2021 11:02:28 +0100 Subject: [PATCH 4/5] fix test again --- e2e/__tests__/__snapshots__/transform.test.ts.snap | 2 +- e2e/transform/babel-jest-manual/transformer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/__tests__/__snapshots__/transform.test.ts.snap b/e2e/__tests__/__snapshots__/transform.test.ts.snap index a68d884e885c..c7310e6bfd8a 100644 --- a/e2e/__tests__/__snapshots__/transform.test.ts.snap +++ b/e2e/__tests__/__snapshots__/transform.test.ts.snap @@ -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`] = ` diff --git a/e2e/transform/babel-jest-manual/transformer.js b/e2e/transform/babel-jest-manual/transformer.js index 597b36bc9ae5..016f7dd30d62 100644 --- a/e2e/transform/babel-jest-manual/transformer.js +++ b/e2e/transform/babel-jest-manual/transformer.js @@ -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'], From 76b2b750712973106731172dd0c5d24250f9f63b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 14 Mar 2021 11:07:36 +0100 Subject: [PATCH 5/5] fix repl --- packages/jest-repl/src/__tests__/jest_repl.test.js | 2 +- packages/jest-repl/src/cli/repl.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/jest-repl/src/__tests__/jest_repl.test.js b/packages/jest-repl/src/__tests__/jest_repl.test.js index b94a29b606c0..ebf51b028caf 100644 --- a/packages/jest-repl/src/__tests__/jest_repl.test.js +++ b/packages/jest-repl/src/__tests__/jest_repl.test.js @@ -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'; @@ -29,6 +28,7 @@ describe('Repl', () => { encoding: 'utf8', env: process.env, }); + expect(output.stderr.trim()).toBe(''); expect(output.stdout.trim()).toMatch(/›/); }); }); diff --git a/packages/jest-repl/src/cli/repl.ts b/packages/jest-repl/src/cli/repl.ts index 6dde9dad8c18..313b4988b36a 100644 --- a/packages/jest-repl/src/cli/repl.ts +++ b/packages/jest-repl/src/cli/repl.ts @@ -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; @@ -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.',