diff --git a/__tests__/init/init.test.ts b/__tests__/init/init.test.ts index a05bd820..2ab57fa3 100644 --- a/__tests__/init/init.test.ts +++ b/__tests__/init/init.test.ts @@ -1,21 +1,21 @@ +import fs from 'fs-extra' +import getPort from 'get-port' +import type { Server } from 'net' +import path from 'path' import { chromium, type Browser, type Page } from 'playwright-chromium' import { fileURLToPath } from 'url' -import path from 'path' -import fs from 'fs-extra' +import type { ViteDevServer } from 'vite' import { - scaffold, + ScaffoldThemeType, build, createServer, - serve, - ScaffoldThemeType, - type ScaffoldOptions + scaffold, + serve } from 'vitepress' -import type { ViteDevServer } from 'vite' -import type { Server } from 'net' -import getPort from 'get-port' let browser: Browser let page: Page +let server: ViteDevServer | Server beforeAll(async () => { browser = await chromium.connect(process.env['WS_ENDPOINT']!) @@ -29,30 +29,57 @@ afterAll(async () => { const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'temp') -async function testVariation(options: ScaffoldOptions) { - fs.removeSync(root) - scaffold({ - ...options, - root - }) +const themes = [ + ScaffoldThemeType.Default, + ScaffoldThemeType.DefaultCustom, + ScaffoldThemeType.Custom +] +const usingTs = [false, true] - let server: ViteDevServer | Server - const port = await getPort() +const variations = themes.flatMap((theme) => + usingTs.map((useTs) => ({ theme, useTs })) +) - async function goto(path: string) { - await page.goto(`http://localhost:${port}${path}`) - await page.waitForSelector('#app div') - } +beforeEach(async () => { + fs.removeSync(root) +}) - if (process.env['VITE_TEST_BUILD']) { - await build(root) - server = (await serve({ root, port })).server +afterEach(async () => { + if ('ws' in server) { + await server.close() } else { - server = await createServer(root, { port }) - await server!.listen() + await new Promise((resolve, reject) => { + server.close((error) => (error ? reject(error) : resolve())) + }) } + fs.removeSync(root) +}) + +test.each(variations)( + '$theme (TypeScript: $useTs)', + async ({ theme, useTs }) => { + scaffold({ + root, + theme, + useTs, + injectNpmScripts: false + }) + + const port = await getPort() + + async function goto(path: string) { + await page.goto(`http://localhost:${port}${path}`) + await page.waitForSelector('#app div') + } + + if (process.env['VITE_TEST_BUILD']) { + await build(root) + server = (await serve({ root, port })).server + } else { + server = await createServer(root, { port }) + await server!.listen() + } - try { await goto('/') expect(await page.textContent('h1')).toMatch('My Awesome Project') @@ -66,33 +93,5 @@ async function testVariation(options: ScaffoldOptions) { await page.click('a[href="/api-examples.html"]') await page.waitForSelector('pre code') expect(await page.textContent('h1')).toMatch('Runtime API Examples') - } finally { - fs.removeSync(root) - if ('ws' in server) { - await server.close() - } else { - await new Promise((resolve, reject) => { - server.close((error) => (error ? reject(error) : resolve())) - }) - } - } -} - -const themes = [ - ScaffoldThemeType.Default, - ScaffoldThemeType.DefaultCustom, - ScaffoldThemeType.Custom -] -const usingTs = [false, true] - -for (const theme of themes) { - for (const useTs of usingTs) { - test(`${theme}${useTs ? ` + TypeScript` : ``}`, () => - testVariation({ - root: '.', - theme, - useTs, - injectNpmScripts: false - })) } -} +) diff --git a/package.json b/package.json index 2ce1f970..512d52e7 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "format": "prettier --check --write .", "format-fail": "prettier --check .", "check": "run-s format-fail build test", - "test": "run-s test-unit test-e2e test-e2e-build", + "test": "run-s test-unit test-e2e test-e2e-build test-init test-init-build", "test-unit": "vitest run -r __tests__/unit", "test-e2e": "vitest run -r __tests__/e2e", "test-e2e-build": "VITE_TEST_BUILD=1 pnpm test-e2e", diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 0d05c021..2e0a7b11 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -127,7 +127,7 @@ export async function createVitePressPlugin( }, optimizeDeps: { // force include vue to avoid duplicated copies when linked + optimized - include: ['vue'], + include: ['vue', '@vue/devtools-api'], exclude: ['@docsearch/js', 'vitepress'] }, server: {