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:
|
env:
|
||||||
FORCE_COLOR: '1'
|
FORCE_COLOR: '1'
|
||||||
- name: Test ${{matrix.packageName}}
|
- 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
|
shell: bash
|
||||||
env:
|
env:
|
||||||
JEST_JUNIT_OUTPUT_FILE: ${{github.workspace}}/.junit-reports/${{matrix.scriptName}}-${{matrix.packageName}}-${{matrix.chunkNumber}}-${{ matrix.runner }}.xml
|
JEST_JUNIT_OUTPUT_FILE: ${{github.workspace}}/.junit-reports/${{matrix.scriptName}}-${{matrix.packageName}}-${{matrix.chunkNumber}}-${{ matrix.runner }}.xml
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest --reporters=default --reporters=jest-junit --env node --verbose --bail",
|
"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-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/",
|
"test-dev": "pnpm test test/dev/",
|
||||||
"coverage": "codecov",
|
"coverage": "codecov",
|
||||||
|
|||||||
@@ -12,6 +12,14 @@
|
|||||||
"outputMode": "new-only",
|
"outputMode": "new-only",
|
||||||
"outputs": ["dist/**"]
|
"outputs": ["dist/**"]
|
||||||
},
|
},
|
||||||
|
"vitest-unit": {
|
||||||
|
"dependsOn": ["build"],
|
||||||
|
"outputMode": "new-only"
|
||||||
|
},
|
||||||
|
"vitest-unit-run": {
|
||||||
|
"dependsOn": ["build"],
|
||||||
|
"outputMode": "new-only"
|
||||||
|
},
|
||||||
"test-unit": {
|
"test-unit": {
|
||||||
"dependsOn": ["build"],
|
"dependsOn": ["build"],
|
||||||
"outputMode": "new-only"
|
"outputMode": "new-only"
|
||||||
|
|||||||
56
utils/chunk-tests.js
vendored
56
utils/chunk-tests.js
vendored
@@ -3,24 +3,58 @@ const child_process = require('child_process');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const runnersMap = new Map([
|
const runnersMap = new Map([
|
||||||
|
[
|
||||||
|
'vitest-unit',
|
||||||
|
{
|
||||||
|
min: 1,
|
||||||
|
max: 1,
|
||||||
|
testScript: 'vitest-unit-run',
|
||||||
|
runners: ['ubuntu-latest', 'macos-latest', 'windows-latest'],
|
||||||
|
},
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'test-unit',
|
'test-unit',
|
||||||
{
|
{
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 1,
|
max: 1,
|
||||||
|
testScript: 'test',
|
||||||
runners: ['ubuntu-latest', 'macos-latest', 'windows-latest'],
|
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',
|
'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',
|
'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 = {
|
const packageOptionsOverrides = {
|
||||||
@@ -36,14 +70,13 @@ function getRunnerOptions(scriptName, packageName) {
|
|||||||
packageOptionsOverrides[packageName]
|
packageOptionsOverrides[packageName]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
if (!runnerOptions) {
|
||||||
runnerOptions || {
|
throw new Error(
|
||||||
min: 1,
|
`Unable to find runner options for package "${packageName}" and script ${scriptName}`
|
||||||
max: 1,
|
|
||||||
runners: ['ubuntu-latest'],
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return runnerOptions;
|
||||||
|
}
|
||||||
|
|
||||||
async function getChunkedTests() {
|
async function getChunkedTests() {
|
||||||
const scripts = [...runnersMap.keys()];
|
const scripts = [...runnersMap.keys()];
|
||||||
@@ -98,7 +131,7 @@ async function getChunkedTests() {
|
|||||||
const [packagePath, packageName] = packagePathAndName.split(',');
|
const [packagePath, packageName] = packagePathAndName.split(',');
|
||||||
return Object.entries(scriptNames).flatMap(([scriptName, testPaths]) => {
|
return Object.entries(scriptNames).flatMap(([scriptName, testPaths]) => {
|
||||||
const runnerOptions = getRunnerOptions(scriptName, packageName);
|
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));
|
const sortedTestPaths = testPaths.sort((a, b) => a.localeCompare(b));
|
||||||
return intoChunks(min, max, sortedTestPaths).flatMap(
|
return intoChunks(min, max, sortedTestPaths).flatMap(
|
||||||
@@ -109,6 +142,7 @@ async function getChunkedTests() {
|
|||||||
packagePath,
|
packagePath,
|
||||||
packageName,
|
packageName,
|
||||||
scriptName,
|
scriptName,
|
||||||
|
testScript,
|
||||||
nodeVersion,
|
nodeVersion,
|
||||||
testPaths: chunk.map(testFile =>
|
testPaths: chunk.map(testFile =>
|
||||||
path.relative(
|
path.relative(
|
||||||
|
|||||||
Reference in New Issue
Block a user