Skip to content

Commit ceb0424

Browse files
committed
fix(config): fixes a bug in path resolver
1 parent 5c7eb5f commit ceb0424

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/config/config-set.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function createConfigSet({
3333
} = {}) {
3434
const cs = new ConfigSet(fakers.jestConfig(jestConfig, tsJestConfig), parentConfig)
3535
if (resolve) {
36-
jest.spyOn(cs, 'resolvePath').mockImplementation(resolve)
36+
cs.resolvePath = resolve
3737
}
3838
return cs
3939
}
@@ -240,3 +240,13 @@ describe('typescript', () => {
240240
})
241241
})
242242
})
243+
244+
describe('resolvePath', () => {
245+
it('should resolve paths', () => {
246+
const cs = createConfigSet({ jestConfig: { rootDir: '/root', cwd: '/cwd' } as any, resolve: null })
247+
expect(normalizeSlashes(cs.resolvePath('bar.js', { throwIfMissing: false }))).toBe('/cwd/bar.js')
248+
expect(normalizeSlashes(cs.resolvePath('./bar.js', { throwIfMissing: false }))).toBe('/cwd/bar.js')
249+
expect(normalizeSlashes(cs.resolvePath('<rootDir>bar.js', { throwIfMissing: false }))).toBe('/root/bar.js')
250+
expect(normalizeSlashes(cs.resolvePath('<rootDir>/bar.js', { throwIfMissing: false }))).toBe('/root/bar.js')
251+
})
252+
})

src/config/config-set.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ export class ConfigSet {
512512
let path: string = inputPath
513513
let nodeResolved = false
514514
if (path.startsWith('<rootDir>')) {
515-
path = resolve(this.rootDir, path.substr(9))
515+
path = resolve(join(this.rootDir, path.substr(9)))
516516
} else if (!isAbsolute(path)) {
517517
if (!path.startsWith('.') && nodeResolve) {
518518
try {

0 commit comments

Comments
 (0)