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')