Skip to content

Commit

Permalink
test: update e2e log
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Oct 28, 2024
1 parent 2e8f90c commit d9d993f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
14 changes: 10 additions & 4 deletions __tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ if (process.platform === 'linux') {

describe('[create-electron-vite] e2e tests', async () => {
test('startup', async () => {
console.log('[e2e] npm-install.log:\n', readFileSync('npm-install.log'))
console.log('[e2e] vite-build.log:\n', readFileSync('vite-build.log'))

const title = await page.title()
expect(title).eq('Vite + Vue + TS')
})
Expand Down Expand Up @@ -98,15 +101,14 @@ async function createProject() {

// For local testing
function enableElectronMirror() {
const npmrc = path.join(generatePath, '.npmrc')
let npmrcContent = fs.readFileSync(npmrc, 'utf8')
let npmrcContent = readFileSync('.npmrc')

npmrcContent = npmrcContent
.split('\n')
.map((line) => line.includes('electron_mirror') ? line.replace('#', '').trim() : line)
.map((line) => line.includes('electron_mirror') ? line.replace('#', '').trimStart() : line)
.join('\n')

fs.writeFileSync(npmrc, npmrcContent)
writeFileSync('.npmrc', npmrcContent)
}

function execSync(command: string) {
Expand All @@ -117,6 +119,10 @@ function writeFileSync(file: string, content: string) {
return fs.writeFileSync(path.join(generatePath, file), content)
}

function readFileSync(file: string) {
return fs.readFileSync(path.join(generatePath, file), 'utf8')
}

function intervalTask<R>(fn: (args: { stop: () => void }) => R | Promise<R>, options?: {
delay?: number
timeout?: number
Expand Down
15 changes: 0 additions & 15 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
import fs from 'node:fs'
import path from 'node:path'
import { defineConfig } from 'vitest/config'

const logs = path.join(__dirname, 'logs')
const stdout = 'test-console.stdout.log'
const stderr = 'test-console.stderr.log'

fs.existsSync(logs) || fs.mkdirSync(logs, { recursive: true })
for (const log of [stdout, stderr]) {
// Clear cache logs
fs.rmSync(path.join(logs, log), { recursive: true, force: true })
}

export default defineConfig({
test: {
root: __dirname,
include: ['__tests__/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
onConsoleLog(log, type) {
fs.appendFileSync(path.join(logs, `test-console.${type}.log`), log)
},
},
})

0 comments on commit d9d993f

Please sign in to comment.