Skip to content

Commit

Permalink
refactor: simplify test process
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jan 1, 2022
1 parent 8fc5d7f commit 6542594
Show file tree
Hide file tree
Showing 36 changed files with 1,398 additions and 1,219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
max_attempts: 2
command: npm --silent run test

coverage:
Expand Down
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
registry=https://registry.npmjs.org/
registry=https://registry.npmjs.org/
hoist=false
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
"eslint": "^7.20.0",
"eslint-config-alloy": "^3.10.0",
"execa": "^5.1.1",
"fast-json-stable-stringify": "^2.1.0",
"fs-extra": "^10.0.0",
"husky": "4.3.7",
"jest": "^27.0.4",
"jest-environment-node": "^26.0.0",
"jest-serializer-path": "^0.1.15",
"lint-staged": "^11.0.0",
"minimist": "^1.2.5",
Expand All @@ -57,7 +59,7 @@
"strip-ansi": "^7.0.0",
"ts-jest": "^27.0.3",
"typescript": "^4.2.2",
"vite": "^2.3.8",
"vite": "^2.7.9",
"vite-plugin-checker": "workspace:*",
"zx": "^1.14.2"
}
Expand Down

This file was deleted.

This file was deleted.

109 changes: 56 additions & 53 deletions packages/vite-plugin-checker/__tests__/e2e/Sandbox/Sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import execa from 'execa'
import path from 'path'
import playwright, { chromium } from 'playwright-chromium'
import type { ElementHandleForTag } from 'playwright-chromium/types/structs'
import playwright from 'playwright-chromium'
import strip from 'strip-ansi'
import invariant from 'tiny-invariant'
// import fs from 'fs'
// import os from 'os'
import { build, createServer, HMRPayload, ViteDevServer } from 'vite'
import { Checker } from 'vite-plugin-checker'

// @ts-ignore
// const page = global.page!
// const DIR = path.join(os.tmpdir(), 'jest_playwright_global_setup')
import { expectStdoutNotContains, sleep, testDir } from '../testUtils'

let devServer: any
let browser: playwright.Browser
// const page: playwright.Page
import type { ElementHandleForTag } from 'playwright-chromium/types/structs'
let devServer: ViteDevServer
let binPath: string

export let log = ''
export let stripedLog = ''

export function resetTerminalLog() {
export function proxyConsoleInTest() {
Checker.logger = [
(...args: any[]) => {
log = args[0].payload
stripedLog = strip(args[0].payload)
},
]
}

export async function sleepForServerReady(ratio = 1) {
await sleep(process.env.CI ? 10000 * ratio : 5000 * ratio)
}

export async function sleepForEdit() {
await sleep(process.env.CI ? 4000 : 2000)
}

export function resetReceivedLog() {
log = ''
stripedLog = ''
}
Expand All @@ -35,54 +46,46 @@ export async function viteServe({
cwd = process.cwd(),
port = 3000,
path: _path = '',
}: { cwd?: string; port?: number; path?: string } = {}) {
sleep(2000)
// @ts-ignore
// const devServer = global.devServer!
// browser = await chromium.launch({
// args: ['--no-sandbox', '--disable-setuid-sandbox'],
// })

// const wsEndpoint = fs.readFileSync(path.join(DIR, 'wsEndpoint'), 'utf-8')
// const browser = await chromium.connect({
// wsEndpoint,
// })

// // @ts-ignore
// global.page = await browser.newPage()

console.log('launching browser')
// page = await browser.newPage()

devServer = execa(binPath, {
cwd: cwd ?? testDir,
})
wsSend,
proxyConsole = proxyConsoleInTest,
launchPage = false,
}: {
cwd?: string
port?: number
path?: string
wsSend?: (payload: HMRPayload) => void
proxyConsole?: () => void
launchPage?: boolean
} = {}) {
await sleep(3000)
if (proxyConsole) {
proxyConsole()
}

await new Promise((resolve) => {
devServer.stdout.on('data', (data: Buffer) => {
log += data.toString()
stripedLog += strip(data.toString())
if (data.toString().match('running')) {
console.log('dev server running.')
resolve('')
}
})
devServer = await createServer({
root: cwd,
})
await devServer.listen()

await sleep(6000)
await page.goto(`http://localhost:${port}${_path}`)
await page.waitForLoadState('domcontentloaded')
// await page.waitForSelector('body', { state: 'attached' })
if (wsSend) {
devServer.ws.send = (payload) => {
wsSend(payload)
}
}

if (launchPage) {
console.log('-- launching page --')
await page.goto(`http://localhost:${port}${_path}`)
console.log('-- page launched --')
await page.waitForLoadState('domcontentloaded')
console.log('-- page loaded --')
}
}

export async function killServer() {
// @ts-ignore
// const devServer = global.devServer!
// if (page) await page.close()
if (devServer) {
devServer.kill('SIGTERM', {
forceKillAfterTimeout: 1,
})
await devServer.close()
console.log('-- dev server closed --')
}
}

Expand Down
90 changes: 0 additions & 90 deletions packages/vite-plugin-checker/__tests__/e2e/TestChecker/main.js

This file was deleted.

Loading

0 comments on commit 6542594

Please sign in to comment.