From 04aebac8e97688ccb414d517cc6a4b09d52c4bc4 Mon Sep 17 00:00:00 2001 From: Carl-Erik Kopseng Date: Thu, 17 Feb 2022 15:25:02 +0100 Subject: [PATCH] Make jest-repl allow transformer modules with only createTransformer This aligns it with the jest-transform module --- packages/babel-jest/src/__tests__/index.ts | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/babel-jest/src/__tests__/index.ts b/packages/babel-jest/src/__tests__/index.ts index 03822efadc73..46dd4677eee3 100644 --- a/packages/babel-jest/src/__tests__/index.ts +++ b/packages/babel-jest/src/__tests__/index.ts @@ -20,6 +20,8 @@ jest.mock('../loadBabelConfig', () => { }; }); +const defaultBabelJestTransformer = babelJest.createTransformer(null); + //Mock data for all the tests const sourceString = ` const sum = (a, b) => a+b; @@ -38,11 +40,17 @@ beforeEach(() => { }); test('Returns source string with inline maps when no transformOptions is passed', () => { - const result = babelJest.process(sourceString, 'dummy_path.js', { - config: makeProjectConfig(), - configString: JSON.stringify(makeProjectConfig()), - instrument: false, - }) as any; + const result = defaultBabelJestTransformer.process( + sourceString, + 'dummy_path.js', + { + cacheFS: new Map(), + config: makeProjectConfig(), + configString: JSON.stringify(makeProjectConfig()), + instrument: false, + transformerConfig: {}, + }, + ) as any; expect(typeof result).toBe('object'); expect(result.code).toBeDefined(); expect(result.map).toBeDefined(); @@ -53,13 +61,15 @@ test('Returns source string with inline maps when no transformOptions is passed' }); test('Returns source string with inline maps when no transformOptions is passed async', async () => { - const result: any = await babelJest.processAsync!( + const result: any = await defaultBabelJestTransformer.processAsync!( sourceString, 'dummy_path.js', { + cacheFS: new Map(), config: makeProjectConfig(), configString: JSON.stringify(makeProjectConfig()), instrument: false, + transformerConfig: {}, }, ); expect(typeof result).toBe('object'); @@ -108,10 +118,12 @@ describe('caller option correctly merges from defaults and options', () => { }, ], ])('%j -> %j', (input, output) => { - babelJest.process(sourceString, 'dummy_path.js', { + defaultBabelJestTransformer.process(sourceString, 'dummy_path.js', { + cacheFS: new Map(), config: makeProjectConfig(), configString: JSON.stringify(makeProjectConfig()), instrument: false, + transformerConfig: {}, ...input, }); @@ -132,9 +144,11 @@ describe('caller option correctly merges from defaults and options', () => { test('can pass null to createTransformer', () => { const transformer = createTransformer(null); transformer.process(sourceString, 'dummy_path.js', { + cacheFS: new Map(), config: makeProjectConfig(), configString: JSON.stringify(makeProjectConfig()), instrument: false, + transformerConfig: {}, }); expect(loadPartialConfig).toHaveBeenCalledTimes(1);