diff --git a/packages/babel-jest/src/__tests__/getCacheKey.test.ts b/packages/babel-jest/src/__tests__/getCacheKey.test.ts index 63e38cff3cb3..2d4b00c9dc8a 100644 --- a/packages/babel-jest/src/__tests__/getCacheKey.test.ts +++ b/packages/babel-jest/src/__tests__/getCacheKey.test.ts @@ -7,7 +7,9 @@ import type {TransformOptions as BabelTransformOptions} from '@babel/core'; import type {TransformOptions as JestTransformOptions} from '@jest/transform'; -import babelJest from '../index'; +import b from '../index'; + +const {getCacheKey} = b.createTransformer(); const processVersion = process.version; const nodeEnv = process.env.NODE_ENV; @@ -39,11 +41,7 @@ describe('getCacheKey', () => { instrument: true, } as JestTransformOptions; - const oldCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const oldCacheKey = getCacheKey(sourceText, sourcePath, transformOptions); test('returns cache key hash', () => { expect(oldCacheKey.length).toEqual(32); @@ -56,11 +54,9 @@ describe('getCacheKey', () => { const {default: babelJest}: typeof import('../index') = require('../index'); - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = babelJest + .createTransformer() + .getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); }); @@ -79,17 +75,15 @@ describe('getCacheKey', () => { const {default: babelJest}: typeof import('../index') = require('../index'); - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = babelJest + .createTransformer() + .getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); }); test('if `sourceText` value is changing', () => { - const newCacheKey = babelJest.getCacheKey( + const newCacheKey = getCacheKey( 'new source text', sourcePath, transformOptions, @@ -99,7 +93,7 @@ describe('getCacheKey', () => { }); test('if `sourcePath` value is changing', () => { - const newCacheKey = babelJest.getCacheKey( + const newCacheKey = getCacheKey( sourceText, 'new-source-path.js', transformOptions, @@ -109,7 +103,7 @@ describe('getCacheKey', () => { }); test('if `configString` value is changing', () => { - const newCacheKey = babelJest.getCacheKey(sourceText, sourcePath, { + const newCacheKey = getCacheKey(sourceText, sourcePath, { ...transformOptions, configString: 'new-config-string', }); @@ -131,11 +125,9 @@ describe('getCacheKey', () => { const {default: babelJest}: typeof import('../index') = require('../index'); - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = babelJest + .createTransformer() + .getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); }); @@ -154,17 +146,15 @@ describe('getCacheKey', () => { const {default: babelJest}: typeof import('../index') = require('../index'); - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = babelJest + .createTransformer() + .getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); }); test('if `instrument` value is changing', () => { - const newCacheKey = babelJest.getCacheKey(sourceText, sourcePath, { + const newCacheKey = getCacheKey(sourceText, sourcePath, { ...transformOptions, instrument: false, }); @@ -175,11 +165,7 @@ describe('getCacheKey', () => { test('if `process.env.NODE_ENV` value is changing', () => { process.env.NODE_ENV = 'NEW_NODE_ENV'; - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); }); @@ -187,11 +173,7 @@ describe('getCacheKey', () => { test('if `process.env.BABEL_ENV` value is changing', () => { process.env.BABEL_ENV = 'NEW_BABEL_ENV'; - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); }); @@ -200,11 +182,7 @@ describe('getCacheKey', () => { delete process.version; process.version = 'new-node-version'; - const newCacheKey = babelJest.getCacheKey( - sourceText, - sourcePath, - transformOptions, - ); + const newCacheKey = getCacheKey(sourceText, sourcePath, transformOptions); expect(oldCacheKey).not.toEqual(newCacheKey); });