fix: ensure daily challenge tests run (#62260)

This commit is contained in:
Oliver Eyton-Williams
2025-09-19 10:48:29 +02:00
committed by GitHub
parent 3a41a6137a
commit 39164ca87f

View File

@@ -1,9 +1,12 @@
import { assert, describe, it } from 'vitest';
import { assert, describe, it, vi } from 'vitest';
import { testedLang } from '../utils';
import { getChallenges } from './test-challenges';
// Daily coding challenges are upcoming changes, so this test does nothing
// unless SHOW_UPCOMING_CHANGES is true.
vi.stubEnv('SHOW_UPCOMING_CHANGES', 'true');
// We need to use dynamic import here to ensure the environment variable is set
// before the module is loaded.
const { getChallenges } = await import('./test-challenges.js');
describe('Daily Coding Challenges', async () => {
const lang = testedLang();
const challenges = await getChallenges(lang, {
@@ -18,6 +21,19 @@ describe('Daily Coding Challenges', async () => {
c => c.block === 'daily-coding-challenges-python'
);
it('should have some daily challenges', function () {
assert.isAbove(
jsDailyChallenges.length,
0,
'No JavaScript daily challenges found'
);
assert.isAbove(
pyDailyChallenges.length,
0,
'No Python daily challenges found'
);
});
it('should have matching number of JavaScript and Python challenges', function () {
assert.equal(
jsDailyChallenges.length,
@@ -26,44 +42,41 @@ describe('Daily Coding Challenges', async () => {
);
});
for (let i = 0; i < jsDailyChallenges.length; i++) {
describe(`Challenge ${i + 1} Parity`, function () {
const jsChallenge = jsDailyChallenges[i];
const pyChallenge = pyDailyChallenges[i];
it('should have matching properties for all challenges', function () {
const challengePairs = jsDailyChallenges.map((jsChallenge, i) => ({
jsChallenge,
pyChallenge: pyDailyChallenges[i]
}));
const errors = [];
it("should have matching ID's", function () {
assert.equal(
jsChallenge.id,
pyChallenge.id,
`Challenge ${i + 1} ID mismatch - JS: ${jsChallenge.id}, Python: ${pyChallenge.id}`
for (const { jsChallenge, pyChallenge } of challengePairs) {
if (jsChallenge.id !== pyChallenge.id) {
errors.push(
`Challenge ID mismatch - JS: ${jsChallenge.id}, Python: ${pyChallenge.id}`
);
});
}
it(`should have matching titles`, function () {
assert.equal(
jsChallenge.title,
pyChallenge.title,
`Challenge ${i + 1} title mismatch - JS: ${jsChallenge.title}, Python: ${pyChallenge.title}`
if (jsChallenge.title !== pyChallenge.title) {
errors.push(
`Challenge title mismatch - JS: ${jsChallenge.title}, Python: ${pyChallenge.title} (id: ${jsChallenge.id})`
);
});
}
it('should have matching descriptions', function () {
assert.equal(
jsChallenge.description,
pyChallenge.description,
`Challenge ${i + 1} description mismatch`
);
});
if (jsChallenge.description !== pyChallenge.description) {
errors.push(`Challenge description mismatch (id: ${jsChallenge.id})`);
}
it('should have the same number of tests', function () {
const jsTestCount = jsChallenge.tests.length;
const pyTestCount = pyChallenge.tests.length;
assert.equal(
jsTestCount,
pyTestCount,
`Challenge ${i + 1} test count mismatch - JS: ${jsTestCount}, Python: ${pyTestCount}`
const jsTestCount = jsChallenge.tests.length;
const pyTestCount = pyChallenge.tests.length;
if (jsTestCount !== pyTestCount) {
errors.push(
`Challenge test count mismatch - JS: ${jsTestCount}, Python: ${pyTestCount} (id: ${jsChallenge.id})`
);
});
});
}
}
}
if (errors.length > 0) {
assert.fail(`Found ${errors.length} mismatch(es):\n${errors.join('\n')}`);
}
});
});