From d9d993f1ba44124daeafa4ce4ad07ea369e52518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Mon, 28 Oct 2024 20:30:23 +0800 Subject: [PATCH] test: update e2e log --- __tests__/e2e.spec.ts | 14 ++++++++++---- vitest.config.ts | 15 --------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/__tests__/e2e.spec.ts b/__tests__/e2e.spec.ts index b1535af..4606a68 100644 --- a/__tests__/e2e.spec.ts +++ b/__tests__/e2e.spec.ts @@ -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') }) @@ -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) { @@ -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(fn: (args: { stop: () => void }) => R | Promise, options?: { delay?: number timeout?: number diff --git a/vitest.config.ts b/vitest.config.ts index 7783968..8207c11 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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) - }, }, })