fix(tooling): return all superblocks containing a filtered block (#65968)

This commit is contained in:
Oliver Eyton-Williams
2026-03-04 21:00:37 +01:00
committed by GitHub
parent a6b34d01b7
commit 520d5dc32a
3 changed files with 40 additions and 7 deletions
+24
View File
@@ -120,6 +120,30 @@ describe('filterByBlock', () => {
]);
});
it('returns all superblocks containing that block', () => {
const superblocks = [
{
name: 'superblock-1',
blocks: [{ dashedName: 'block-1' }, { dashedName: 'block-2' }]
},
{
name: 'superblock-2',
blocks: [{ dashedName: 'block-1' }, { dashedName: 'block-2' }]
}
];
const filtered = filterByBlock(superblocks, { block: 'block-1' });
expect(filtered).toEqual([
{
name: 'superblock-1',
blocks: [{ dashedName: 'block-1' }]
},
{
name: 'superblock-2',
blocks: [{ dashedName: 'block-1' }]
}
]);
});
it('returns an empty array if no blocks match the specified block', () => {
const superblocks = [
{
+4 -4
View File
@@ -1,7 +1,7 @@
import comparison from 'string-similarity';
/**
* Filters the superblocks array to include, at most, a single superblock with the specified block.
* Filters the superblocks array to include any superblocks with the specified block.
* If no block is provided, returns the original superblocks array.
*
* @param {Array<Object>} superblocks - Array of superblock objects, each containing a blocks array.
@@ -15,14 +15,14 @@ export function filterByBlock<T extends { blocks: { dashedName: string }[] }>(
): T[] {
if (!block) return superblocks;
const superblock = superblocks
const remainingSuperblocks = superblocks
.map(superblock => ({
...superblock,
blocks: superblock.blocks.filter(({ dashedName }) => dashedName === block)
}))
.find(superblock => superblock.blocks.length > 0);
.filter(superblock => superblock.blocks.length > 0);
return superblock ? [superblock] : [];
return remainingSuperblocks;
}
/**
+12 -3
View File
@@ -79,11 +79,20 @@ async function newPageContext() {
}
export async function defineTestsForBlock(testFilter) {
const challenges = await getChallenges(CURRICULUM_LOCALE, testFilter);
const nonCertificationChallenges = challenges.filter(
const allChallenges = await getChallenges(CURRICULUM_LOCALE, testFilter);
const nonCertificationChallenges = allChallenges.filter(
({ challengeType }) => challengeType !== 7
);
if (isEmpty(nonCertificationChallenges)) {
// This is a bit of a dirty hack, but when we're testing, we only need to
// validate the challenges for the block we're testing once, rather than
// once for each superBlock the challenge appears in.
const firstSuperBlock = allChallenges[0]?.superBlock;
const challenges = nonCertificationChallenges.filter(
({ superBlock }) => superBlock === firstSuperBlock
);
if (isEmpty(challenges)) {
console.warn(
`No non-certification challenges to test for block ${testFilter.block}.`
);