Skip to content
Permalink
Browse files

fix(config): resolve `.babelrc` file path before attempting to read it (

#2071)

Closes #2064
  • Loading branch information
ahnpnl committed Oct 26, 2020
1 parent 57f7448 commit 681bfef41744f09cd50b71072f4d001cb58da82e
Showing with 17 additions and 7 deletions.
  1. +14 −5 src/config/config-set.spec.ts
  2. +3 −2 src/config/config-set.ts
@@ -199,7 +199,7 @@ describe('customTransformers', () => {
} as any,
logger,
tsJestConfig: {
astTransformers: ['dummy-transformer'],
astTransformers: ['<rootDir>/__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: '<rootDir>/.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,
})
@@ -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') {

0 comments on commit 681bfef

Please sign in to comment.
You can’t perform that action at this time.