Navigation Menu

Skip to content

Commit

Permalink
fix(config): resolve .babelrc file path before attempting to read it (
Browse files Browse the repository at this point in the history
#2071)

Closes #2064
  • Loading branch information
ahnpnl committed Oct 26, 2020
1 parent 57f7448 commit 681bfef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/config/config-set.spec.ts
Expand Up @@ -199,7 +199,7 @@ describe('customTransformers', () => {
} as any,
logger,
tsJestConfig: {
astTransformers: ['dummy-transformer'],
astTransformers: ['<rootDir>/__mocks__/dummy-transformer'],
},
resolve: null,
}).customTransformers,
Expand Down Expand Up @@ -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',
Expand All @@ -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,
})
Expand Down
5 changes: 3 additions & 2 deletions src/config/config-set.ts
Expand Up @@ -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') {
Expand Down

0 comments on commit 681bfef

Please sign in to comment.