mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
test: use expect for clearer errors (#62965)
This commit is contained in:
committed by
GitHub
parent
8380c7c01f
commit
0c04e1a9ed
@@ -41,13 +41,12 @@
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.23.7",
|
||||
"@babel/register": "7.23.7",
|
||||
"@types/polka": "^0.5.7",
|
||||
"@total-typescript/ts-reset": "^0.6.1",
|
||||
"@types/debug": "^4.1.12",
|
||||
"@types/js-yaml": "4.0.5",
|
||||
"@types/polka": "^0.5.7",
|
||||
"@types/string-similarity": "^4.0.2",
|
||||
"@vitest/ui": "^3.2.4",
|
||||
"chai": "4.4.1",
|
||||
"glob": "8.1.0",
|
||||
"joi": "17.12.2",
|
||||
"joi-objectid": "3.0.1",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { describe, it, beforeAll, expect } from 'vitest';
|
||||
import { assert, AssertionError } from 'chai';
|
||||
import jsdom from 'jsdom';
|
||||
import lodash from 'lodash';
|
||||
|
||||
@@ -151,33 +150,28 @@ function populateTestsForLang({ lang, challenges, meta }) {
|
||||
const index = meta[dashedBlockName]?.challengeOrder?.findIndex(
|
||||
({ id }) => id === challenge.id
|
||||
);
|
||||
|
||||
if (index < 0) {
|
||||
throw new AssertionError(
|
||||
`Cannot find ID "${challenge.id}" in meta.json file for block "${dashedBlockName}"`
|
||||
);
|
||||
}
|
||||
expect(
|
||||
index,
|
||||
`Cannot find ID "${challenge.id}" in meta.json file for block "${dashedBlockName}"`
|
||||
).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('Common checks', function () {
|
||||
const result = validateChallenge(challenge);
|
||||
|
||||
if (result.error) {
|
||||
throw new AssertionError(result.error);
|
||||
}
|
||||
expect(result.error).toBeUndefined();
|
||||
const { id, block, dashedName } = challenge;
|
||||
assert.exists(
|
||||
dashedName,
|
||||
`Missing dashedName for challenge ${id} in ${block}.`
|
||||
);
|
||||
|
||||
expect(dashedName).toBeDefined();
|
||||
|
||||
const pathAndTitle = `${block}/${dashedName}`;
|
||||
const idVerificationMessage = mongoIds.check(id, block);
|
||||
assert.isNull(idVerificationMessage, idVerificationMessage);
|
||||
expect(idVerificationMessage).toBeNull();
|
||||
const dupeTitleCheck = challengeTitles.check(dashedName, block);
|
||||
assert.isTrue(
|
||||
expect(
|
||||
dupeTitleCheck,
|
||||
`All challenges within a block must have a unique dashed name. ${dashedName} (at ${pathAndTitle}) is already assigned`
|
||||
);
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
const { challengeType } = challenge;
|
||||
@@ -231,10 +225,7 @@ function populateTestsForLang({ lang, challenges, meta }) {
|
||||
}
|
||||
}
|
||||
console.error = oldConsoleError;
|
||||
assert(
|
||||
fails,
|
||||
'Test suite does not fail on the initial contents'
|
||||
);
|
||||
expect(fails, 'Test suite should fail on the initial contents');
|
||||
},
|
||||
timePerTest * tests.length + 20000
|
||||
);
|
||||
|
||||
Generated
+3
-6
@@ -730,9 +730,6 @@ importers:
|
||||
'@vitest/ui':
|
||||
specifier: ^3.2.4
|
||||
version: 3.2.4(vitest@3.2.4)
|
||||
chai:
|
||||
specifier: 4.4.1
|
||||
version: 4.4.1
|
||||
glob:
|
||||
specifier: 8.1.0
|
||||
version: 8.1.0
|
||||
@@ -777,7 +774,7 @@ importers:
|
||||
version: 4.0.4
|
||||
vitest:
|
||||
specifier: ^3.2.4
|
||||
version: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0)
|
||||
version: 3.2.4(@types/debug@4.1.12)(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0)
|
||||
|
||||
shared:
|
||||
devDependencies:
|
||||
@@ -20163,7 +20160,7 @@ snapshots:
|
||||
sirv: 3.0.2
|
||||
tinyglobby: 0.2.14
|
||||
tinyrainbow: 2.0.0
|
||||
vitest: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@26.1.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.7.3))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0)
|
||||
vitest: 3.2.4(@types/debug@4.1.12)(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0)
|
||||
|
||||
'@vitest/utils@3.2.4':
|
||||
dependencies:
|
||||
@@ -31143,7 +31140,7 @@ snapshots:
|
||||
- debug
|
||||
- typescript
|
||||
|
||||
vitest@3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0):
|
||||
vitest@3.2.4(@types/debug@4.1.12)(@types/node@20.12.8)(@vitest/ui@3.2.4)(jiti@2.6.1)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0):
|
||||
dependencies:
|
||||
'@types/chai': 5.2.2
|
||||
'@vitest/expect': 3.2.4
|
||||
|
||||
Reference in New Issue
Block a user