MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / defineTestsForBlock

Function defineTestsForBlock

curriculum/src/test/test-challenges.js:92–139  ·  view source on GitHub ↗
(testFilter)

Source from the content-addressed store, hash-verified

90}
91
92export async function defineTestsForBlock(testFilter) {
93 const allChallenges = await getChallenges(CURRICULUM_LOCALE, testFilter);
94 const nonCertificationChallenges = allChallenges.filter(
95 ({ challengeType }) => challengeType !== 7
96 );
97
98 // This is a bit of a dirty hack, but when we're testing, we only need to
99 // validate the challenges for the block we're testing once, rather than
100 // once for each superBlock the challenge appears in.
101 const firstSuperBlock = allChallenges[0]?.superBlock;
102 const challenges = nonCertificationChallenges.filter(
103 ({ superBlock }) => superBlock === firstSuperBlock
104 );
105
106 if (isEmpty(challenges)) {
107 console.warn(
108 `No non-certification challenges to test for block ${testFilter.block}.`
109 );
110 describe('Check challenges', () => {
111 it('No non-certification challenges to test', () => {});
112 });
113 return;
114 }
115 const meta = {};
116 for (const challenge of challenges) {
117 const dashedBlockName = challenge.block;
118 if (dashedBlockName && !meta[dashedBlockName]) {
119 meta[dashedBlockName] = getBlockStructure(dashedBlockName);
120 describe(`Meta structure for block ${dashedBlockName}`, () => {
121 it('Has valid structure', () => {
122 const result = validateMetaSchema(meta[dashedBlockName]);
123 expect(result.error).toBeUndefined();
124 });
125 });
126 }
127 }
128
129 const challengeData = { meta, challenges, lang: CURRICULUM_LOCALE };
130
131 describe('Check challenges', async () => {
132 beforeAll(async () => {
133 page = await newPageContext();
134 global.Worker = createPseudoWorker(page);
135 });
136
137 await populateTestsForLang(challengeData, () => page);
138 });
139}
140
141export async function getChallenges(lang, filters) {
142 const challenges = await getChallengesForLang(lang, filters).then(

Callers

nothing calls this directly

Calls 5

getBlockStructureFunction · 0.85
newPageContextFunction · 0.85
createPseudoWorkerFunction · 0.85
populateTestsForLangFunction · 0.85
getChallengesFunction · 0.70

Tested by

no test coverage detected