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