Skip to content

Commit

Permalink
revert: 456099a
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd authored Mar 25, 2023
1 parent 3553f01 commit 335ef4f
Showing 1 changed file with 56 additions and 55 deletions.
111 changes: 56 additions & 55 deletions __tests__/init/init.test.ts
Original file line number Diff line number Diff line change
@@ -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 type { ViteDevServer } from 'vite'
import path from 'path'
import fs from 'fs-extra'
import {
ScaffoldThemeType,
scaffold,
build,
createServer,
scaffold,
serve
serve,
ScaffoldThemeType,
type ScaffoldOptions
} 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']!)
Expand All @@ -29,57 +29,30 @@ afterAll(async () => {

const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'temp')

const themes = [
ScaffoldThemeType.Default,
ScaffoldThemeType.DefaultCustom,
ScaffoldThemeType.Custom
]
const usingTs = [false, true]
async function testVariation(options: ScaffoldOptions) {
fs.removeSync(root)
scaffold({
...options,
root
})

const variations = themes.flatMap((theme) =>
usingTs.map((useTs) => ({ theme, useTs }))
)
let server: ViteDevServer | Server
const port = await getPort()

beforeEach(async () => {
fs.removeSync(root)
})
async function goto(path: string) {
await page.goto(`http://localhost:${port}${path}`)
await page.waitForSelector('#app div')
}

afterEach(async () => {
if ('ws' in server) {
await server.close()
if (process.env['VITE_TEST_BUILD']) {
await build(root)
server = (await serve({ root, port })).server
} else {
await new Promise<void>((resolve, reject) => {
server.close((error) => (error ? reject(error) : resolve()))
})
server = await createServer(root, { port })
await server!.listen()
}
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')

Expand All @@ -93,5 +66,33 @@ test.each(variations)(
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<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
}))
}
)
}

0 comments on commit 335ef4f

Please sign in to comment.