diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b7b43b370b..f8c09f0fe859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,8 +84,9 @@ - `[jest-reporters]` [**BREAKING**] Make `node-notifier` a peer dependency ([#10977](https://github.com/facebook/jest/pull/10977)) - `[jest-resolve, jest-runtime]` [**BREAKING**] Use `Map`s instead of objects for all cached resources ([#10968](https://github.com/facebook/jest/pull/10968)) - `[jest-runner]` [**BREAKING**] Migrate to ESM ([#10900](https://github.com/facebook/jest/pull/10900)) -- `[jest-runtime]` [**BREAKING**] Remove deprecated and unnused `getSourceMapInfo` from Runtime ([#9969](https://github.com/facebook/jest/pull/9969)) +- `[jest-runtime]` [**BREAKING**] Remove deprecated and unused `getSourceMapInfo` from Runtime ([#9969](https://github.com/facebook/jest/pull/9969)) - `[jest-runtime]` Detect reexports from CJS as named exports in ESM ([#10988](https://github.com/facebook/jest/pull/10988)) +- `[jest-transformer]` [**BREAKING**] Remove unused `isCoreModule` option ([#11166](https://github.com/facebook/jest/pull/11166)) - `[jest-util]` No longer checking `enumerable` when adding `process.domain` ([#10862](https://github.com/facebook/jest/pull/10862)) - `[jest-validate]` [**BREAKING**] Remove `recursiveBlacklist ` option in favor of previously introduced `recursiveDenylist` ([#10650](https://github.com/facebook/jest/pull/10650)) diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index 9e5704517000..bc2be3ed53e6 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -391,7 +391,7 @@ export default class ScriptTransformer { transformOptions: ReducedTransformOptions, fileSource?: string, ): TransformResult { - const {isCoreModule, isInternalModule} = options; + const {isInternalModule} = options; let fileContent = fileSource ?? this._cacheFS.get(filename); if (!fileContent) { fileContent = fs.readFileSync(filename, 'utf8'); @@ -404,7 +404,6 @@ export default class ScriptTransformer { const willTransform = !isInternalModule && - !isCoreModule && (transformOptions.instrument || this.shouldTransform(filename)); try { @@ -434,21 +433,17 @@ export default class ScriptTransformer { options: Options, fileSource?: string, ): TransformResult { - let scriptCacheKey = undefined; - let instrument = false; - - if (!options.isCoreModule) { - instrument = - options.coverageProvider === 'babel' && - shouldInstrument(filename, options, this._config); - scriptCacheKey = getScriptCacheKey(filename, instrument); - const result = this._cache.transformedFiles.get(scriptCacheKey); - if (result) { - return result; - } + const instrument = + options.coverageProvider === 'babel' && + shouldInstrument(filename, options, this._config); + const scriptCacheKey = getScriptCacheKey(filename, instrument); + + let result = this._cache.transformedFiles.get(scriptCacheKey); + if (result) { + return result; } - const result = this._transformAndBuildScript( + result = this._transformAndBuildScript( filename, options, {...options, instrument}, @@ -467,9 +462,8 @@ export default class ScriptTransformer { options: Options, fileSource: string, ): string { - const {isCoreModule, isInternalModule} = options; - const willTransform = - !isInternalModule && !isCoreModule && this.shouldTransform(filename); + const {isInternalModule} = options; + const willTransform = !isInternalModule && this.shouldTransform(filename); if (willTransform) { const {code: transformedJsonSource} = this.transformSource( diff --git a/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts b/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts index 88f4faddc9d7..51a92c4d277d 100644 --- a/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts +++ b/packages/jest-transform/src/__tests__/ScriptTransformer.test.ts @@ -278,25 +278,6 @@ describe('ScriptTransformer', () => { ); }); - it('does not transform Node core modules', () => { - jest.mock('../shouldInstrument'); - - const shouldInstrument = require('../shouldInstrument').default; - const scriptTransformer = new ScriptTransformer(config); - const fsSourceCode = 'muaha, fake source!'; - - const response = scriptTransformer.transform( - 'fs', - {...getCoverageOptions(), isCoreModule: true}, - fsSourceCode, - ); - - expect(response.code).toEqual(fsSourceCode); - - // Native files should never be transformed. - expect(shouldInstrument).toHaveBeenCalledTimes(0); - }); - it( "throws an error if `process` doesn't return a string or an object" + 'containing `code` key with processed string', diff --git a/packages/jest-transform/src/types.ts b/packages/jest-transform/src/types.ts index 97492c0f46b5..3738f4840a0e 100644 --- a/packages/jest-transform/src/types.ts +++ b/packages/jest-transform/src/types.ts @@ -8,23 +8,23 @@ import type {RawSourceMap} from 'source-map'; import type {Config, TransformTypes} from '@jest/types'; -export type ShouldInstrumentOptions = Pick< - Config.GlobalConfig, - | 'collectCoverage' - | 'collectCoverageFrom' - | 'collectCoverageOnlyFrom' - | 'coverageProvider' -> & { +export interface ShouldInstrumentOptions + extends Pick< + Config.GlobalConfig, + | 'collectCoverage' + | 'collectCoverageFrom' + | 'collectCoverageOnlyFrom' + | 'coverageProvider' + > { changedFiles?: Set; sourcesRelatedToTestsInChangedFiles?: Set; -}; +} -export type Options = ShouldInstrumentOptions & - Partial<{ - isCoreModule: boolean; - isInternalModule: boolean; - }> & - CallerTransformOptions; +export interface Options + extends ShouldInstrumentOptions, + CallerTransformOptions { + isInternalModule?: boolean; +} // This is fixed in source-map@0.7.x, but we can't upgrade yet since it's async interface FixedRawSourceMap extends Omit {