Skip to content

Commit

Permalink
simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fpbrault committed Nov 14, 2024
1 parent 2d8b5eb commit 76fd46a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions scripts/ci/determine-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class PackageJsonChangeError extends Error {
}
}

class RunAllTestsInMergeQueueError extends Error {
constructor() {
super(`In a merge queue. Running all tests.`);
this.name = 'RunAllTestsInMergeQueueError';
}
}

/**
* Recursively finds all end-to-end test files with the `.e2e.ts` extension in a given directory.
*
Expand Down Expand Up @@ -181,16 +188,19 @@ const projectRoot = process.env.projectRoot;
const atomicSourceComponents = join('packages', 'atomic', 'src', 'components');

try {
if (runAllTests) {
throw new RunAllTestsInMergeQueue();
}

const testFiles = findAllTestFiles(atomicSourceComponents);
const testDependencies = createTestFileMappings(testFiles, projectRoot);
const testsToRun = runAllTests
? testFiles.join(' ')
: determineTestFilesToRun(changedFiles, testDependencies);
if (testsToRun === '' && !runAllTests) {
const testsToRun = determineTestFilesToRun(changedFiles, testDependencies);

if (testsToRun === '') {
throw new NoRelevantChangesError();
}
const maximumShards = parseInt(process.env.maximumShards, 10);

const maximumShards = parseInt(process.env.maximumShards, 10);
const [shardIndex, shardTotal] = allocateShards(
testsToRun.split(' ').length,
maximumShards
Expand All @@ -205,11 +215,10 @@ try {
setOutput(outputNameTestsToRun, '');
setOutput(outputNameShardIndex, [0]);
setOutput(outputNameShardTotal, [0]);
}

if (
} else if (
error instanceof DependentPackageChangeError ||
error instanceof PackageJsonChangeError
error instanceof PackageJsonChangeError ||
error instanceof RunAllTestsInMergeQueueError
) {
console.warn(error?.message || error);
setOutput(outputNameTestsToRun, '');
Expand All @@ -220,5 +229,8 @@ try {
setOutput(outputNameShardIndex, shardIndex);
const shardTotal = [process.env.maximumShards];
setOutput(outputNameShardTotal, shardTotal);
} else {
console.error('Unexpected error:', error);
process.exit(1);
}
}

0 comments on commit 76fd46a

Please sign in to comment.