From e850c689bfbb95f319e8c6e6392e773ad9505414 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 | 26 ++++++++++++++++++++++++++ test/browser/specs/runner.test.mjs | 29 ++++++++--------------------- 2 files changed, 34 insertions(+), 21 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..329659ad3e4a --- /dev/null +++ b/test/browser/specs/run-vitest.mjs @@ -0,0 +1,26 @@ +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}`, '--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 3c9619d31652..fe31f583f012 100644 --- a/test/browser/specs/runner.test.mjs +++ b/test/browser/specs/runner.test.mjs @@ -1,27 +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 { stderr, stdout } = await execa('npx', ['vitest', '--run', `--browser.name=${browser}`, '--browser.headless'], { - 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 === 8, 'Not all the tests have been run')