|
|
@ -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 { chromium, type Browser, type Page } from 'playwright-chromium'
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
import path from 'path'
|
|
|
|
import type { ViteDevServer } from 'vite'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
scaffold,
|
|
|
|
ScaffoldThemeType,
|
|
|
|
build,
|
|
|
|
build,
|
|
|
|
createServer,
|
|
|
|
createServer,
|
|
|
|
serve,
|
|
|
|
scaffold,
|
|
|
|
ScaffoldThemeType,
|
|
|
|
serve
|
|
|
|
type ScaffoldOptions
|
|
|
|
|
|
|
|
} from 'vitepress'
|
|
|
|
} from 'vitepress'
|
|
|
|
import type { ViteDevServer } from 'vite'
|
|
|
|
|
|
|
|
import type { Server } from 'net'
|
|
|
|
|
|
|
|
import getPort from 'get-port'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let browser: Browser
|
|
|
|
let browser: Browser
|
|
|
|
let page: Page
|
|
|
|
let page: Page
|
|
|
|
|
|
|
|
let server: ViteDevServer | Server
|
|
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
browser = await chromium.connect(process.env['WS_ENDPOINT']!)
|
|
|
|
browser = await chromium.connect(process.env['WS_ENDPOINT']!)
|
|
|
@ -29,14 +29,42 @@ afterAll(async () => {
|
|
|
|
|
|
|
|
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'temp')
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'temp')
|
|
|
|
|
|
|
|
|
|
|
|
async function testVariation(options: ScaffoldOptions) {
|
|
|
|
const themes = [
|
|
|
|
|
|
|
|
ScaffoldThemeType.Default,
|
|
|
|
|
|
|
|
ScaffoldThemeType.DefaultCustom,
|
|
|
|
|
|
|
|
ScaffoldThemeType.Custom
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
const usingTs = [false, true]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const variations = themes.flatMap((theme) =>
|
|
|
|
|
|
|
|
usingTs.map((useTs) => ({ theme, useTs }))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
fs.removeSync(root)
|
|
|
|
fs.removeSync(root)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
|
|
|
|
if ('ws' in server) {
|
|
|
|
|
|
|
|
await server.close()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
|
|
|
|
|
|
server.close((error) => (error ? reject(error) : resolve()))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.removeSync(root)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test.each(variations)(
|
|
|
|
|
|
|
|
'$theme (TypeScript: $useTs)',
|
|
|
|
|
|
|
|
async ({ theme, useTs }) => {
|
|
|
|
scaffold({
|
|
|
|
scaffold({
|
|
|
|
...options,
|
|
|
|
root,
|
|
|
|
root
|
|
|
|
theme,
|
|
|
|
|
|
|
|
useTs,
|
|
|
|
|
|
|
|
injectNpmScripts: false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
let server: ViteDevServer | Server
|
|
|
|
|
|
|
|
const port = await getPort()
|
|
|
|
const port = await getPort()
|
|
|
|
|
|
|
|
|
|
|
|
async function goto(path: string) {
|
|
|
|
async function goto(path: string) {
|
|
|
@ -52,7 +80,6 @@ async function testVariation(options: ScaffoldOptions) {
|
|
|
|
await server!.listen()
|
|
|
|
await server!.listen()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await goto('/')
|
|
|
|
await goto('/')
|
|
|
|
expect(await page.textContent('h1')).toMatch('My Awesome Project')
|
|
|
|
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.click('a[href="/api-examples.html"]')
|
|
|
|
await page.waitForSelector('pre code')
|
|
|
|
await page.waitForSelector('pre code')
|
|
|
|
expect(await page.textContent('h1')).toMatch('Runtime API Examples')
|
|
|
|
expect(await page.textContent('h1')).toMatch('Runtime API Examples')
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
fs.removeSync(root)
|
|
|
|
|
|
|
|
if ('ws' in server) {
|
|
|
|
|
|
|
|
await server.close()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
await new Promise<void>((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
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|