Skip to content

Commit

Permalink
chore: update e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed Jun 30, 2022
1 parent cd62a41 commit 135c9ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
9 changes: 5 additions & 4 deletions test/e2e/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { resolve } from 'path'
import { copyFile, rm } from 'fs/promises'
import { createServer } from 'vite'
import { getBrowser, getViteConfig } from './utils'
import { chromium } from 'playwright'
import { getViteConfig, stopServer } from './utils'
import type { Browser, Page } from 'playwright'
import type { ViteDevServer } from 'vite'

Expand All @@ -16,14 +17,14 @@ describe('react e2e test', () => {

beforeAll(async() => {
server = await createServer(getViteConfig(vueRoot))
await server.listen()
browser = await getBrowser()
await server.listen(0)
browser = await chromium.launch()
page = await browser.newPage()
})

afterAll(async() => {
await browser.close()
server.httpServer?.close()
await stopServer(server)
})

const getUrl = (path: string) => `http://localhost:${server.config.server.port}${path}`
Expand Down
9 changes: 5 additions & 4 deletions test/e2e/solid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { resolve } from 'path'
import { copyFile, rm } from 'fs/promises'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { createServer } from 'vite'
import { getBrowser, getViteConfig } from './utils'
import { chromium } from 'playwright'
import { getViteConfig, stopServer } from './utils'
import type { Browser, Page } from 'playwright'
import type { ViteDevServer } from 'vite'

Expand All @@ -17,14 +18,14 @@ describe('solid e2e test', () => {

beforeAll(async() => {
server = await createServer(getViteConfig(solidRoot))
await server.listen()
browser = await getBrowser()
await server.listen(0)
browser = await chromium.launch()
page = await browser.newPage()
})

afterAll(async() => {
await browser.close()
server.httpServer?.close()
await stopServer(server)
})

const getUrl = (path: string) => `http://localhost:${server.config.server.port}${path}`
Expand Down
16 changes: 6 additions & 10 deletions test/e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { chromium } from 'playwright'
import type { Browser } from 'playwright'
import type { UserConfig } from 'vite'
import type { UserConfig, ViteDevServer } from 'vite'

export const getViteConfig = (root: string): UserConfig => ({
root,
Expand All @@ -19,11 +17,9 @@ export const getViteConfig = (root: string): UserConfig => ({
},
})

let browser: Browser

export const getBrowser = async() => {
if (!browser)
browser = await chromium.launch()

return browser
export const stopServer = async(server: ViteDevServer) => {
return new Promise<void>((resolve, reject) => server.httpServer?.close((err) => {
if (err) reject(err)
resolve()
}))
}
9 changes: 5 additions & 4 deletions test/e2e/vue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { resolve } from 'path'
import { copyFile, rm } from 'fs/promises'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { createServer } from 'vite'
import { getBrowser, getViteConfig } from './utils'
import { chromium } from 'playwright'
import { getViteConfig, stopServer } from './utils'
import type { Browser, Page } from 'playwright'
import type { ViteDevServer } from 'vite'

Expand All @@ -17,14 +18,14 @@ describe('vue e2e test', () => {

beforeAll(async() => {
server = await createServer(getViteConfig(vueRoot))
await server.listen()
browser = await getBrowser()
await server.listen(0)
browser = await chromium.launch()
page = await browser.newPage()
})

afterAll(async() => {
await browser.close()
server.httpServer?.close()
await stopServer(server)
})

const getUrl = (path: string) => `http://localhost:${server.config.server.port}${path}`
Expand Down

0 comments on commit 135c9ad

Please sign in to comment.