mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
Specify npm script to run during Find Changes step (#11409)
Add a new vitest-unit test type and specify which npm script to run for a given chunks tests. Currently the CLI unit tests are actually running as part of the Find Changes action, because vitest ignores the `--listTests` flag and just runs the tests immediately.
This commit is contained in:
4
.changeset/fresh-pans-vanish.md
Normal file
4
.changeset/fresh-pans-vanish.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
---
|
||||
|
||||
Include test script to run when determining chunks for CI"
|
||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -85,7 +85,7 @@ jobs:
|
||||
env:
|
||||
FORCE_COLOR: '1'
|
||||
- name: Test ${{matrix.packageName}}
|
||||
run: node utils/gen.js && node_modules/.bin/turbo run test --summarize --cache-dir=".turbo" --log-order=stream --scope=${{matrix.packageName}} --no-deps -- ${{ join(matrix.testPaths, ' ') }}
|
||||
run: node utils/gen.js && node_modules/.bin/turbo run ${{matrix.testScript}} --summarize --cache-dir=".turbo" --log-order=stream --scope=${{matrix.packageName}} --no-deps -- ${{ join(matrix.testPaths, ' ') }}
|
||||
shell: bash
|
||||
env:
|
||||
JEST_JUNIT_OUTPUT_FILE: ${{github.workspace}}/.junit-reports/${{matrix.scriptName}}-${{matrix.packageName}}-${{matrix.chunkNumber}}-${{ matrix.runner }}.xml
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail",
|
||||
"test-unit": "pnpm vitest test/unit/",
|
||||
"vitest-unit-run": "pnpm vitest",
|
||||
"vitest-unit": "pnpm jest test/unit/ --listTests",
|
||||
"test-e2e": "rimraf test/fixtures/integration && pnpm test test/integration-1.test.ts test/integration-2.test.ts test/integration-3.test.ts",
|
||||
"test-dev": "pnpm test test/dev/",
|
||||
"coverage": "codecov",
|
||||
|
||||
@@ -12,6 +12,14 @@
|
||||
"outputMode": "new-only",
|
||||
"outputs": ["dist/**"]
|
||||
},
|
||||
"vitest-unit": {
|
||||
"dependsOn": ["build"],
|
||||
"outputMode": "new-only"
|
||||
},
|
||||
"vitest-unit-run": {
|
||||
"dependsOn": ["build"],
|
||||
"outputMode": "new-only"
|
||||
},
|
||||
"test-unit": {
|
||||
"dependsOn": ["build"],
|
||||
"outputMode": "new-only"
|
||||
|
||||
58
utils/chunk-tests.js
vendored
58
utils/chunk-tests.js
vendored
@@ -3,24 +3,58 @@ const child_process = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const runnersMap = new Map([
|
||||
[
|
||||
'vitest-unit',
|
||||
{
|
||||
min: 1,
|
||||
max: 1,
|
||||
testScript: 'vitest-unit-run',
|
||||
runners: ['ubuntu-latest', 'macos-latest', 'windows-latest'],
|
||||
},
|
||||
],
|
||||
[
|
||||
'test-unit',
|
||||
{
|
||||
min: 1,
|
||||
max: 1,
|
||||
testScript: 'test',
|
||||
runners: ['ubuntu-latest', 'macos-latest', 'windows-latest'],
|
||||
},
|
||||
],
|
||||
['test-e2e', { min: 1, max: 7, runners: ['ubuntu-latest'] }],
|
||||
[
|
||||
'test-e2e',
|
||||
{ min: 1, max: 7, testScript: 'test', runners: ['ubuntu-latest'] },
|
||||
],
|
||||
[
|
||||
'test-next-local',
|
||||
{ min: 1, max: 5, runners: ['ubuntu-latest'], nodeVersion: '18' },
|
||||
{
|
||||
min: 1,
|
||||
max: 5,
|
||||
runners: ['ubuntu-latest'],
|
||||
testScript: 'test',
|
||||
nodeVersion: '18',
|
||||
},
|
||||
],
|
||||
[
|
||||
'test-next-local-legacy',
|
||||
{ min: 1, max: 5, runners: ['ubuntu-latest'], nodeVersion: '16' },
|
||||
{
|
||||
min: 1,
|
||||
max: 5,
|
||||
runners: ['ubuntu-latest'],
|
||||
|
||||
testScript: 'test',
|
||||
nodeVersion: '16',
|
||||
},
|
||||
],
|
||||
[
|
||||
'test-dev',
|
||||
{
|
||||
min: 1,
|
||||
max: 7,
|
||||
testScript: 'test',
|
||||
runners: ['ubuntu-latest', 'macos-latest'],
|
||||
},
|
||||
],
|
||||
['test-dev', { min: 1, max: 7, runners: ['ubuntu-latest', 'macos-latest'] }],
|
||||
]);
|
||||
|
||||
const packageOptionsOverrides = {
|
||||
@@ -36,13 +70,12 @@ function getRunnerOptions(scriptName, packageName) {
|
||||
packageOptionsOverrides[packageName]
|
||||
);
|
||||
}
|
||||
return (
|
||||
runnerOptions || {
|
||||
min: 1,
|
||||
max: 1,
|
||||
runners: ['ubuntu-latest'],
|
||||
}
|
||||
);
|
||||
if (!runnerOptions) {
|
||||
throw new Error(
|
||||
`Unable to find runner options for package "${packageName}" and script ${scriptName}`
|
||||
);
|
||||
}
|
||||
return runnerOptions;
|
||||
}
|
||||
|
||||
async function getChunkedTests() {
|
||||
@@ -98,7 +131,7 @@ async function getChunkedTests() {
|
||||
const [packagePath, packageName] = packagePathAndName.split(',');
|
||||
return Object.entries(scriptNames).flatMap(([scriptName, testPaths]) => {
|
||||
const runnerOptions = getRunnerOptions(scriptName, packageName);
|
||||
const { runners, min, max, nodeVersion } = runnerOptions;
|
||||
const { runners, min, max, testScript, nodeVersion } = runnerOptions;
|
||||
|
||||
const sortedTestPaths = testPaths.sort((a, b) => a.localeCompare(b));
|
||||
return intoChunks(min, max, sortedTestPaths).flatMap(
|
||||
@@ -109,6 +142,7 @@ async function getChunkedTests() {
|
||||
packagePath,
|
||||
packageName,
|
||||
scriptName,
|
||||
testScript,
|
||||
nodeVersion,
|
||||
testPaths: chunk.map(testFile =>
|
||||
path.relative(
|
||||
|
||||
Reference in New Issue
Block a user