From 91a8f0eb771c4a08fc23270399a20cf577ad20e4 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Thu, 17 Feb 2022 15:38:41 +0100 Subject: [PATCH] Update tests to account for babel-jest not having default process/processAsync exports --- .../src/__tests__/getCacheKey.test.ts | 66 +++++++------------ 1 file changed, 22 insertions(+), 44 deletions(-) diff --git a/packages/babel-jest/src/__tests__/getCacheKey.test.ts b/packages/babel-jest/src/__tests__/getCacheKey.test.ts index 63e38cff3cb3..7ab404603fa9 100644 --- a/packages/babel-jest/src/__tests__/getCacheKey.test.ts +++ b/packages/babel-jest/src/__tests__/getCacheKey.test.ts @@ -9,6 +9,8 @@ import type {TransformOptions as BabelTransformOptions} from '@babel/core'; import type {TransformOptions as JestTransformOptions} from '@jest/transform'; import babelJest from '../index'; +const {getCacheKey} = babelJest.createTransformer(); + const processVersion = process.version; const nodeEnv = process.env.NODE_ENV; const babelEnv = process.env.BABEL_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); });