forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 vitest-dev#4686.
- Loading branch information
Showing
2 changed files
with
34 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters