Skip to content

Commit 681bfef

Browse files
authored
fix(config): resolve .babelrc file path before attempting to read it (#2071)
Closes #2064
1 parent 57f7448 commit 681bfef

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/config/config-set.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ describe('customTransformers', () => {
199199
} as any,
200200
logger,
201201
tsJestConfig: {
202-
astTransformers: ['dummy-transformer'],
202+
astTransformers: ['<rootDir>/__mocks__/dummy-transformer'],
203203
},
204204
resolve: null,
205205
}).customTransformers,
@@ -241,7 +241,7 @@ describe('babelJestTransformer', () => {
241241
expect(babelJest).toBeUndefined()
242242
})
243243

244-
it('should return babelJestTransformer with babalConfig is true', () => {
244+
it('should return babelJestTransformer with babelConfig is true', () => {
245245
const cs = createConfigSet({
246246
jestConfig: {
247247
rootDir: 'src',
@@ -265,15 +265,24 @@ describe('babelJestTransformer', () => {
265265
expect(typeof babelJest.process).toBe('function')
266266
})
267267

268-
it('should return babelJestTransformer with non javascript file path', () => {
269-
const FILE = 'src/__mocks__/.babelrc-foo'
268+
it.each([
269+
{
270+
path: 'src/__mocks__/.babelrc-foo',
271+
rootDir: './',
272+
},
273+
{
274+
path: '<rootDir>/.babelrc-foo',
275+
rootDir: 'src/__mocks__/',
276+
},
277+
])('should return babelJestTransformer with non javascript file path', (data) => {
270278
const cs = createConfigSet({
271279
jestConfig: {
272280
globals: {
273281
'ts-jest': {
274-
babelConfig: FILE,
282+
babelConfig: data.path,
275283
},
276284
},
285+
rootDir: data.rootDir,
277286
},
278287
resolve: null,
279288
})

src/config/config-set.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,16 @@ export class ConfigSet {
219219
} else {
220220
const baseBabelCfg = { cwd: this.cwd }
221221
if (typeof options.babelConfig === 'string') {
222+
const babelCfgPath = this.resolvePath(options.babelConfig)
222223
if (extname(options.babelConfig) === '.js') {
223224
this._babelConfig = {
224225
...baseBabelCfg,
225-
...require(this.resolvePath(options.babelConfig, { nodeResolve: true })),
226+
...require(babelCfgPath),
226227
}
227228
} else {
228229
this._babelConfig = {
229230
...baseBabelCfg,
230-
...json5.parse(readFileSync(options.babelConfig, 'utf-8')),
231+
...json5.parse(readFileSync(babelCfgPath, 'utf-8')),
231232
}
232233
}
233234
} else if (typeof options.babelConfig === 'object') {

0 commit comments

Comments
 (0)