diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index 04e73e1c30..a174f39601 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -199,7 +199,7 @@ describe('customTransformers', () => { } as any, logger, tsJestConfig: { - astTransformers: ['dummy-transformer'], + astTransformers: ['/__mocks__/dummy-transformer'], }, resolve: null, }).customTransformers, @@ -241,7 +241,7 @@ describe('babelJestTransformer', () => { expect(babelJest).toBeUndefined() }) - it('should return babelJestTransformer with babalConfig is true', () => { + it('should return babelJestTransformer with babelConfig is true', () => { const cs = createConfigSet({ jestConfig: { rootDir: 'src', @@ -265,15 +265,24 @@ describe('babelJestTransformer', () => { expect(typeof babelJest.process).toBe('function') }) - it('should return babelJestTransformer with non javascript file path', () => { - const FILE = 'src/__mocks__/.babelrc-foo' + it.each([ + { + path: 'src/__mocks__/.babelrc-foo', + rootDir: './', + }, + { + path: '/.babelrc-foo', + rootDir: 'src/__mocks__/', + }, + ])('should return babelJestTransformer with non javascript file path', (data) => { const cs = createConfigSet({ jestConfig: { globals: { 'ts-jest': { - babelConfig: FILE, + babelConfig: data.path, }, }, + rootDir: data.rootDir, }, resolve: null, }) diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 35d3f6088f..a21bcc792f 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -219,15 +219,16 @@ export class ConfigSet { } else { const baseBabelCfg = { cwd: this.cwd } if (typeof options.babelConfig === 'string') { + const babelCfgPath = this.resolvePath(options.babelConfig) if (extname(options.babelConfig) === '.js') { this._babelConfig = { ...baseBabelCfg, - ...require(this.resolvePath(options.babelConfig, { nodeResolve: true })), + ...require(babelCfgPath), } } else { this._babelConfig = { ...baseBabelCfg, - ...json5.parse(readFileSync(options.babelConfig, 'utf-8')), + ...json5.parse(readFileSync(babelCfgPath, 'utf-8')), } } } else if (typeof options.babelConfig === 'object') {