Skip to content

Commit

Permalink
fix(config): fixes a bug in path resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 6, 2018
1 parent 5c7eb5f commit ceb0424
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/config/config-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function createConfigSet({
} = {}) {
const cs = new ConfigSet(fakers.jestConfig(jestConfig, tsJestConfig), parentConfig)
if (resolve) {
jest.spyOn(cs, 'resolvePath').mockImplementation(resolve)
cs.resolvePath = resolve
}
return cs
}
Expand Down Expand Up @@ -240,3 +240,13 @@ describe('typescript', () => {
})
})
})

describe('resolvePath', () => {
it('should resolve paths', () => {
const cs = createConfigSet({ jestConfig: { rootDir: '/root', cwd: '/cwd' } as any, resolve: null })
expect(normalizeSlashes(cs.resolvePath('bar.js', { throwIfMissing: false }))).toBe('/cwd/bar.js')
expect(normalizeSlashes(cs.resolvePath('./bar.js', { throwIfMissing: false }))).toBe('/cwd/bar.js')
expect(normalizeSlashes(cs.resolvePath('<rootDir>bar.js', { throwIfMissing: false }))).toBe('/root/bar.js')
expect(normalizeSlashes(cs.resolvePath('<rootDir>/bar.js', { throwIfMissing: false }))).toBe('/root/bar.js')
})
})
2 changes: 1 addition & 1 deletion src/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export class ConfigSet {
let path: string = inputPath
let nodeResolved = false
if (path.startsWith('<rootDir>')) {
path = resolve(this.rootDir, path.substr(9))
path = resolve(join(this.rootDir, path.substr(9)))
} else if (!isAbsolute(path)) {
if (!path.startsWith('.') && nodeResolve) {
try {
Expand Down

0 comments on commit ceb0424

Please sign in to comment.