fix(builder): use path.resolve for pages dir (#8832)

This commit is contained in:
Sébastien Chopin 2021-02-15 21:53:03 +01:00 committed by GitHub
parent dcfb42b772
commit 8b1a70476a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -180,7 +180,7 @@ export default class Builder {
if (
!this._nuxtPages ||
await fsExtra.exists(path.join(this.options.srcDir, this.options.dir.pages))
await fsExtra.exists(path.resolve(this.options.srcDir, this.options.dir.pages))
) {
return
}

View File

@ -16,11 +16,13 @@ jest.mock('@nuxt/webpack')
describe('builder: builder build', () => {
beforeAll(() => {
jest.spyOn(path, 'join').mockImplementation((...args) => `join(${args.join(', ')})`)
jest.spyOn(path, 'resolve').mockImplementation((...args) => `resolve(${args.join(', ')})`)
r.mockImplementation((...args) => `r(${args.join(', ')})`)
})
afterAll(() => {
path.join.mockRestore()
path.resolve.mockRestore()
})
beforeEach(() => {
@ -143,11 +145,12 @@ describe('builder: builder build', () => {
await builder.validatePages()
expect(builder._nuxtPages).toEqual(true)
expect(path.join).toBeCalledTimes(2)
expect(path.join).nthCalledWith(1, '/var/nuxt/src', '/var/nuxt/src/pages')
expect(path.join).nthCalledWith(2, '/var/nuxt/src', '..', '/var/nuxt/src/pages')
expect(path.resolve).toBeCalledTimes(1)
expect(path.resolve).nthCalledWith(1, '/var/nuxt/src', '/var/nuxt/src/pages')
expect(path.join).toBeCalledTimes(1)
expect(path.join).nthCalledWith(1, '/var/nuxt/src', '..', '/var/nuxt/src/pages')
expect(fsExtra.exists).toBeCalledTimes(2)
expect(fsExtra.exists).nthCalledWith(1, 'join(/var/nuxt/src, /var/nuxt/src/pages)')
expect(fsExtra.exists).nthCalledWith(1, 'resolve(/var/nuxt/src, /var/nuxt/src/pages)')
expect(fsExtra.exists).nthCalledWith(2, 'join(/var/nuxt/src, .., /var/nuxt/src/pages)')
expect(builder._defaultPage).toEqual(true)
expect(consola.warn).toBeCalledTimes(1)
@ -168,11 +171,10 @@ describe('builder: builder build', () => {
)
expect(builder._nuxtPages).toEqual(true)
expect(path.join).toBeCalledTimes(2)
expect(path.join).nthCalledWith(1, '/var/nuxt/src', '/var/nuxt/src/pages')
expect(path.join).nthCalledWith(2, '/var/nuxt/src', '..', '/var/nuxt/src/pages')
expect(path.resolve).nthCalledWith(1, '/var/nuxt/src', '/var/nuxt/src/pages')
expect(path.join).nthCalledWith(1, '/var/nuxt/src', '..', '/var/nuxt/src/pages')
expect(fsExtra.exists).toBeCalledTimes(2)
expect(fsExtra.exists).nthCalledWith(1, 'join(/var/nuxt/src, /var/nuxt/src/pages)')
expect(fsExtra.exists).nthCalledWith(1, 'resolve(/var/nuxt/src, /var/nuxt/src/pages)')
expect(fsExtra.exists).nthCalledWith(2, 'join(/var/nuxt/src, .., /var/nuxt/src/pages)')
expect(builder._defaultPage).toBeUndefined()
})
@ -198,10 +200,10 @@ describe('builder: builder build', () => {
await builder.validatePages()
expect(builder._nuxtPages).toEqual(true)
expect(path.join).toBeCalledTimes(1)
expect(path.join).toBeCalledWith('/var/nuxt/src', '/var/nuxt/src/pages')
expect(path.resolve).toBeCalledTimes(1)
expect(path.resolve).toBeCalledWith('/var/nuxt/src', '/var/nuxt/src/pages')
expect(fsExtra.exists).toBeCalledTimes(1)
expect(fsExtra.exists).toBeCalledWith('join(/var/nuxt/src, /var/nuxt/src/pages)')
expect(fsExtra.exists).toBeCalledWith('resolve(/var/nuxt/src, /var/nuxt/src/pages)')
expect(builder._defaultPage).toBeUndefined()
})
})