Skip to content

Commit

Permalink
test: use separate temp path for init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Nov 11, 2023
1 parent 7eea613 commit a582a84
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions __tests__/init/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import fs from 'fs-extra'
import getPort from 'get-port'
import { nanoid } from 'nanoid'
import path from 'path'
import { chromium } from 'playwright-chromium'
import { fileURLToPath, URL } from 'url'
import { createServer, scaffold, ScaffoldThemeType } from 'vitepress'

const root = fileURLToPath(new URL('./.temp', import.meta.url))
const tempDir = fileURLToPath(new URL('./.temp', import.meta.url))
const getTempRoot = () => path.join(tempDir, nanoid())

const browser = await chromium.launch({
headless: !process.env.DEBUG,
Expand All @@ -30,9 +33,11 @@ const variations = themes.flatMap((theme) =>
afterAll(async () => {
await page.close()
await browser.close()
await fs.remove(tempDir)
})

test.each(variations)('init %s', async (_, { theme, useTs }) => {
const root = getTempRoot()
await fs.remove(root)
scaffold({ root, theme, useTs, injectNpmScripts: false })

Expand Down Expand Up @@ -62,7 +67,6 @@ test.each(variations)('init %s', async (_, { theme, useTs }) => {

// teardown
} finally {
await fs.remove(root)
await server.close()
}
})

0 comments on commit a582a84

Please sign in to comment.