diff --git a/packages/core/src/resolver.js b/packages/core/src/resolver.js index bcded60ef6..087dacaeeb 100644 --- a/packages/core/src/resolver.js +++ b/packages/core/src/resolver.js @@ -105,8 +105,9 @@ export default class Resolver { return resolvedPath + '.' + ext } - if (isDirectory && fs.existsSync(resolvedPath + '/index.' + ext)) { - return resolvedPath + '/index.' + ext + const resolvedPathwithIndex = join(resolvedPath, 'index.' + ext) + if (isDirectory && fs.existsSync(resolvedPathwithIndex)) { + return resolvedPathwithIndex } } diff --git a/packages/core/test/resolver.test.js b/packages/core/test/resolver.test.js index 4b0deb4482..bf89d201a1 100644 --- a/packages/core/test/resolver.test.js +++ b/packages/core/test/resolver.test.js @@ -6,12 +6,14 @@ import { startsWithRootAlias, startsWithSrcAlias } from '@nuxt/utils' import Resolver from '../src/resolver' -jest.mock('path') jest.mock('esm', () => jest.fn(() => jest.fn())) jest.mock('fs-extra') jest.mock('@nuxt/utils') -describe('core: resolver', () => { +jest.spyOn(path, 'join') +jest.spyOn(path, 'resolve') + +describe.posix('core: resolver', () => { beforeEach(() => { jest.clearAllMocks() }) @@ -107,7 +109,7 @@ describe('core: resolver', () => { startsWithRootAlias.mockReturnValue(false) startsWithSrcAlias.mockReturnValue(false) - const aliasPath = { substr: jest.fn(p => String(p)) } + const aliasPath = 'x' resolver.resolveAlias(aliasPath) expect(path.resolve).toBeCalledTimes(1)