From 3becd2008c8898674548ac14e75c3747c9d10a54 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Wed, 6 Dec 2023 19:14:20 -0500 Subject: [PATCH] chore(test/browser): extract runVitest helper This is in preparation for adding a new test file which will run the tests with config.base set to confirm the fix for #4686. --- test/browser/specs/run-vitest.mjs | 30 +++++++++++++++++++++++++++ test/browser/specs/runner.test.mjs | 33 ++++++++---------------------- 2 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 test/browser/specs/run-vitest.mjs diff --git a/test/browser/specs/run-vitest.mjs b/test/browser/specs/run-vitest.mjs new file mode 100644 index 000000000000..79d2528201a7 --- /dev/null +++ b/test/browser/specs/run-vitest.mjs @@ -0,0 +1,30 @@ +import { readFile } from 'node:fs/promises' +import { execa } from 'execa' + +const browser = process.env.BROWSER || (process.env.PROVIDER === 'playwright' ? 'chromium' : 'chrome') + +export default async function runVitest(moreArgs = []) { + const argv = ['vitest', '--run', `--browser.name=${browser}`] + + if (browser !== 'safari') + argv.push('--browser.headless') + + const { stderr, stdout } = await execa('npx', argv.concat(moreArgs), { + env: { + ...process.env, + CI: 'true', + NO_COLOR: 'true', + }, + reject: false, + }) + const browserResult = await readFile('./browser.json', 'utf-8') + const browserResultJson = JSON.parse(browserResult) + + const getPassed = results => results.filter(result => result.status === 'passed') + const getFailed = results => results.filter(result => result.status === 'failed') + + const passedTests = getPassed(browserResultJson.testResults) + const failedTests = getFailed(browserResultJson.testResults) + + return { stderr, stdout, browserResultJson, passedTests, failedTests } +} diff --git a/test/browser/specs/runner.test.mjs b/test/browser/specs/runner.test.mjs index 556b749f2a14..ea67aee7c889 100644 --- a/test/browser/specs/runner.test.mjs +++ b/test/browser/specs/runner.test.mjs @@ -1,31 +1,14 @@ import assert from 'node:assert' -import { readFile } from 'node:fs/promises' import test from 'node:test' -import { execa } from 'execa' +import runVitest from './run-vitest.mjs' -const browser = process.env.BROWSER || (process.env.PROVIDER === 'playwright' ? 'chromium' : 'chrome') -const argv = ['vitest', '--run', `--browser.name=${browser}`] - -if (browser !== 'safari') - argv.push('--browser.headless') - -const { stderr, stdout } = await execa('npx', argv, { - env: { - ...process.env, - CI: 'true', - NO_COLOR: 'true', - }, - reject: false, -}) - -const browserResult = await readFile('./browser.json', 'utf-8') -const browserResultJson = JSON.parse(browserResult) - -const getPassed = results => results.filter(result => result.status === 'passed') -const getFailed = results => results.filter(result => result.status === 'failed') - -const passedTests = getPassed(browserResultJson.testResults) -const failedTests = getFailed(browserResultJson.testResults) +const { + stderr, + stdout, + browserResultJson, + passedTests, + failedTests, +} = await runVitest() await test('tests are actually running', async () => { assert.ok(browserResultJson.testResults.length === 10, 'Not all the tests have been run')