Skip to content

Commit

Permalink
feat: resolve rootDir (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza authored Apr 8, 2021
1 parent 07dccf5 commit f604dff
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/nuxt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { existsSync } from 'fs'
import { resolve } from 'path'
import { getContext } from './context'

Expand All @@ -8,10 +9,36 @@ export async function loadNuxt () {
ctx.nuxt = new Nuxt(ctx.options.config)
}

const isNuxtApp = (dir: string) => {
return existsSync(dir) && (
existsSync(resolve(dir, 'pages')) ||
existsSync(resolve(dir, 'nuxt.config.js')) ||
existsSync(resolve(dir, 'nuxt.config.ts'))
)
}

const resolveRootDir = () => {
const { options } = getContext()

const dirs = [
options.rootDir,
resolve(options.testDir, options.fixture),
process.cwd()
]

for (const dir of dirs) {
if (dir && isNuxtApp(dir)) {
return dir
}
}

throw new Error('Invalid nuxt app. (Please explicitly set `options.rootDir` pointing to a valid nuxt app)')
}

export async function loadFixture () {
const { options } = getContext()

options.rootDir = resolve(options.testDir, options.fixture)
options.rootDir = resolveRootDir()

const { loadNuxtConfig } = await loadNuxtPackage()
options.config = await loadNuxtConfig({
Expand Down

0 comments on commit f604dff

Please sign in to comment.