|
| 1 | +import { mkdir, rm, writeFile } from 'node:fs/promises' |
| 2 | +import { afterAll, beforeAll, describe, expect, it } from 'vitest' |
| 3 | +import { join } from 'pathe' |
| 4 | +import { findWorkspaceDir } from 'pkg-types' |
| 5 | +import { x } from 'tinyexec' |
| 6 | + |
| 7 | +import { loadNuxt } from '../src' |
| 8 | + |
| 9 | +const repoRoot = await findWorkspaceDir() |
| 10 | + |
| 11 | +describe('loadNuxt', () => { |
| 12 | + const tempDir = join(repoRoot, 'temp') |
| 13 | + |
| 14 | + beforeAll(async () => { |
| 15 | + await mkdir(join(tempDir, 'nuxt'), { recursive: true }) |
| 16 | + await writeFile(join(tempDir, 'package.json'), '{"dependencies":{"nuxt":"file:./nuxt"}}') |
| 17 | + await writeFile(join(tempDir, 'nuxt', 'package.json'), '{"name":"nuxt","type":"module","exports":{".":"./index.js"}}') |
| 18 | + await writeFile(join(tempDir, 'nuxt', 'index.js'), 'export const loadNuxt = (opts) => ({ name: "it me" })') |
| 19 | + await x('npm', ['install'], { nodeOptions: { cwd: tempDir } }) |
| 20 | + }) |
| 21 | + |
| 22 | + afterAll(async () => { |
| 23 | + await rm(tempDir, { recursive: true, force: true }) |
| 24 | + }) |
| 25 | + |
| 26 | + it('respects correct directory', async () => { |
| 27 | + const nuxt = await loadNuxt({ cwd: tempDir }) |
| 28 | + expect(nuxt).toStrictEqual({ |
| 29 | + name: 'it me', |
| 30 | + }) |
| 31 | + }) |
| 32 | +}) |
0 commit comments