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:
Jeff See
2024-04-10 17:26:58 -07:00
committed by GitHub
parent b58dcc5733
commit cdfc879f69
5 changed files with 61 additions and 14 deletions

View File

@@ -0,0 +1,4 @@
---
---
Include test script to run when determining chunks for CI"

View File

@@ -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

View File

@@ -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",

View File

@@ -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"

56
utils/chunk-tests.js vendored
View File

@@ -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(