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

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