From 95b4056e207cda3fb462bf5f91775249a807d205 Mon Sep 17 00:00:00 2001 From: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Date: Sat, 27 Sep 2025 20:22:21 +0700 Subject: [PATCH] test(challenge-parser): improve validate-sections test (#62385) --- .../parser/plugins/validate-sections.js | 2 + .../parser/plugins/validate-sections.test.js | 115 ++---------------- 2 files changed, 15 insertions(+), 102 deletions(-) diff --git a/tools/challenge-parser/parser/plugins/validate-sections.js b/tools/challenge-parser/parser/plugins/validate-sections.js index d20aa0b9c23..dd4100a9aa8 100644 --- a/tools/challenge-parser/parser/plugins/validate-sections.js +++ b/tools/challenge-parser/parser/plugins/validate-sections.js @@ -124,3 +124,5 @@ function validateSections() { } module.exports = validateSections; +module.exports.VALID_MARKERS = VALID_MARKERS; +module.exports.NON_HEADING_MARKERS = NON_HEADING_MARKERS; diff --git a/tools/challenge-parser/parser/plugins/validate-sections.test.js b/tools/challenge-parser/parser/plugins/validate-sections.test.js index cf7101ff1a9..d317f3dde65 100644 --- a/tools/challenge-parser/parser/plugins/validate-sections.test.js +++ b/tools/challenge-parser/parser/plugins/validate-sections.test.js @@ -4,7 +4,10 @@ import remark from 'remark-parse'; import frontmatter from 'remark-frontmatter'; import addFrontmatter from './add-frontmatter'; -import validateSections from './validate-sections'; +import validateSections, { + VALID_MARKERS, + NON_HEADING_MARKERS +} from './validate-sections'; const processor = unified() .use(remark) @@ -14,107 +17,15 @@ const processor = unified() describe('validate-sections plugin', () => { it('should pass when all section markers are valid', () => { - const file = `--- -id: test -title: Test ---- - -# --after-all-- -After all hook. - -# --after-each-- -After each hook. - -# --assignment-- -Assignment. - -# --before-all-- -Before all hook. - -# --before-each-- -Before each hook. - -# --description-- -Text content. - -# --explanation-- -Explanation. - -# --fillInTheBlank-- -Fill in blank. - -# --hints-- -Hints. - -# --instructions-- -More text. - -# --notes-- -Notes. - -# --questions-- -Video questions. - -# --quizzes-- -Quiz section. - -# --scene-- -Scene content. - -# --seed-- -Seed section. - -# --solutions-- -Solutions. - -# --transcript-- -Transcript. - -## --answers-- -Answers. - -## --blanks-- -Blanks. - -## --quiz-- -Individual quiz. - -## --seed-contents-- -Contents here. - -## --sentence-- -Sentence. - -## --text-- -Question text. - -## --video-solution-- -Video solution. - -## --after-user-code-- -After code. - -## --before-user-code-- -Before code. - -### --feedback-- -Feedback. - -### --question-- -Quiz question. - -#### --answer-- -Correct answer. - -#### --distractors-- -Distractors. - -#### --text-- -Question text. - ---fcc-editable-region-- -Editable region. -`; + const file = [ + '---', + 'id: test', + 'title: Test', + '---', + '', + ...VALID_MARKERS.map(marker => `${marker}\nDummy content.`), + ...NON_HEADING_MARKERS.map(marker => `${marker}\nDummy content.`) + ].join('\n'); expect(() => { processor.runSync(processor.parse(file));