Skip to content

Commit

Permalink
chore(ci): disable playwright test detection script on merge queue (#…
Browse files Browse the repository at this point in the history
…4651)

This PR ensures that all playwright tests run for the merge queue
instead of just those related to the files that where changed.

https://coveord.atlassian.net/browse/KIT-3702
  • Loading branch information
fpbrault authored Nov 15, 2024
1 parent 9771d76 commit 7153914
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/prbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ jobs:
- run: npm run build
- name: Identify E2E Test Files to run
id: determine-tests
run: node ./scripts/ci/determine-tests.mjs testsToRun shardIndex shardTotal
run: |
runAllTests=$([ "${{ github.event_name }}" == "merge_group" ] && echo true || echo false)
node ./scripts/ci/determine-tests.mjs testsToRun shardIndex shardTotal $runAllTests
env:
projectRoot: ${{ github.workspace }}
maximumShards: ${{ env.maximumShards }}
Expand Down
25 changes: 20 additions & 5 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 @@ -176,18 +183,24 @@ const changedFiles = getChangedFiles(base, head).split(EOL);
const outputNameTestsToRun = process.argv[2];
const outputNameShardIndex = process.argv[3];
const outputNameShardTotal = process.argv[4];
const runAllTests = process.argv[5] === 'true';
const projectRoot = process.env.projectRoot;
const atomicSourceComponents = join('packages', 'atomic', 'src', 'components');

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

const testFiles = findAllTestFiles(atomicSourceComponents);
const testDependencies = createTestFileMappings(testFiles, projectRoot);
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 @@ -202,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 @@ -217,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 7153914

Please sign in to comment.