diff --git a/tools/challenge-parser/parser/plugins/add-video-question.js b/tools/challenge-parser/parser/plugins/add-video-question.js index 6e7706543be..2c2cb404ac1 100644 --- a/tools/challenge-parser/parser/plugins/add-video-question.js +++ b/tools/challenge-parser/parser/plugins/add-video-question.js @@ -110,6 +110,8 @@ function plugin() { questionNode.children?.[0]?.value === '--text--'; if (isStartOfQuestion) { questionTrees.push([questionNode]); + } else if (questionTrees.length === 0) { + throw Error('question text is missing in questions section'); } else { questionTrees[questionTrees.length - 1].push(questionNode); } diff --git a/tools/challenge-parser/parser/plugins/add-video-question.test.js b/tools/challenge-parser/parser/plugins/add-video-question.test.js index a9d1f5651d7..629e0c1cff8 100644 --- a/tools/challenge-parser/parser/plugins/add-video-question.test.js +++ b/tools/challenge-parser/parser/plugins/add-video-question.test.js @@ -104,7 +104,9 @@ describe('add-video-question plugin', () => { // 'The md is missing "x"', so it's obvious how to fix things. it('should throw if the subheadings are outside the question heading', () => { expect.assertions(1); - expect(() => plugin(videoOutOfOrderAST)).toThrow(); + expect(() => plugin(videoOutOfOrderAST, file)).toThrow( + 'question text is missing in questions section' + ); }); it('should NOT throw if there is no question', () => {