Skip to content

Commit b135dd9

Browse files
authored
Merge pull request #11 from coderoad/feature/test-output
Feature/test output
2 parents a6ae501 + d2e1097 commit b135dd9

File tree

2 files changed

+188
-8
lines changed

2 files changed

+188
-8
lines changed

src/utils/parse.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ export function parseMdContent(md: string): TutorialFrame | never {
4141
const summaryMatch = parts
4242
.shift()
4343
.match(/^#\s(?<tutorialTitle>.*)[\n\r]+(?<tutorialDescription>[^]*)/);
44-
if (!summaryMatch.groups.tutorialTitle) {
45-
throw new Error("Missing tutorial title");
44+
if (summaryMatch.groups.tutorialTitle) {
45+
mdContent.summary.title = summaryMatch.groups.tutorialTitle.trim();
4646
}
47-
mdContent.summary.title = summaryMatch.groups.tutorialTitle.trim();
4847

49-
if (!summaryMatch.groups.tutorialDescription) {
50-
throw new Error("Missing tutorial summary description");
48+
if (summaryMatch.groups.tutorialDescription) {
49+
mdContent.summary.description = summaryMatch.groups.tutorialDescription.trim();
5150
}
52-
mdContent.summary.description = summaryMatch.groups.tutorialDescription.trim();
5351

5452
// Identify each part of the content
5553
parts.forEach((section: string) => {
@@ -67,10 +65,10 @@ export function parseMdContent(md: string): TutorialFrame | never {
6765
// @ts-ignore
6866
mdContent.levels[levelId] = {
6967
id: levelId,
70-
title: levelTitle,
68+
title: levelTitle.trim(),
7169
summary: levelSummary
7270
? levelSummary.trim()
73-
: _.truncate(levelContent, { length: 80, omission: "..." }),
71+
: _.truncate(levelContent.trim(), { length: 80, omission: "..." }),
7472
content: levelContent.trim(),
7573
};
7674
} else {

tests/parse.test.ts

+182
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ The first step
386386
filter: "someFilter",
387387
subtasks: true,
388388
},
389+
solution: {
390+
commands: ["npm install"],
391+
files: ["someFile.js"],
392+
},
389393
},
390394
],
391395
},
@@ -396,6 +400,7 @@ The first step
396400
config,
397401
commits: {
398402
L1S1Q: ["abcdefg1", "123456789"],
403+
L1S1A: ["1gfedcba", "987654321"],
399404
},
400405
});
401406
const expected = {
@@ -419,6 +424,11 @@ The first step
419424
filter: "someFilter",
420425
subtasks: true,
421426
},
427+
solution: {
428+
commits: ["1gfedcba", "987654321"],
429+
commands: ["npm install"],
430+
files: ["someFile.js"],
431+
},
422432
},
423433
],
424434
},
@@ -427,6 +437,178 @@ The first step
427437
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
428438
});
429439

440+
it("should load the full config for a step", () => {
441+
const md = `# Title
442+
443+
Description.
444+
445+
## L1 Title 1
446+
447+
First level content.
448+
449+
### L1S1
450+
451+
The first step
452+
453+
### L1S2
454+
455+
The second step
456+
457+
## L2 Title 2
458+
459+
Second level content.
460+
461+
### L2S1
462+
463+
The third step
464+
`;
465+
const config = {
466+
levels: [
467+
{
468+
id: "L1",
469+
steps: [
470+
{
471+
id: "L1S1",
472+
setup: {
473+
commands: ["npm install"],
474+
files: ["someFile.js"],
475+
watchers: ["someFile.js"],
476+
filter: "someFilter",
477+
subtasks: true,
478+
},
479+
solution: {
480+
commands: ["npm install"],
481+
files: ["someFile.js"],
482+
},
483+
},
484+
{
485+
id: "L1S2",
486+
setup: {
487+
commands: ["npm install"],
488+
files: ["someFile.js"],
489+
watchers: ["someFile.js"],
490+
filter: "someFilter",
491+
subtasks: true,
492+
},
493+
solution: {
494+
commands: ["npm install"],
495+
files: ["someFile.js"],
496+
},
497+
},
498+
],
499+
},
500+
{
501+
id: "L2",
502+
summary: "Second level content.",
503+
content: "First level content.",
504+
steps: [
505+
{
506+
id: "L2S1",
507+
setup: {
508+
commands: ["npm install"],
509+
files: ["someFile.js"],
510+
watchers: ["someFile.js"],
511+
filter: "someFilter",
512+
subtasks: true,
513+
},
514+
solution: {
515+
commands: ["npm install"],
516+
files: ["someFile.js"],
517+
},
518+
},
519+
],
520+
},
521+
],
522+
};
523+
const result = parse({
524+
text: md,
525+
config,
526+
commits: {
527+
L1S1Q: ["abcdefg1", "123456789"],
528+
L1S1A: ["1gfedcba", "987654321"],
529+
L1S2Q: ["2abcdefg"],
530+
L1S2A: ["3abcdefg"],
531+
L2S1Q: ["4abcdefg"],
532+
L2S1A: ["5abcdefg"],
533+
},
534+
});
535+
const expected = {
536+
summary: {
537+
description: "Description.",
538+
},
539+
levels: [
540+
{
541+
id: "L1",
542+
title: "Title 1",
543+
summary: "First level content.",
544+
content: "First level content.",
545+
steps: [
546+
{
547+
id: "L1S1",
548+
content: "The first step",
549+
setup: {
550+
commits: ["abcdefg1", "123456789"],
551+
commands: ["npm install"],
552+
files: ["someFile.js"],
553+
watchers: ["someFile.js"],
554+
filter: "someFilter",
555+
subtasks: true,
556+
},
557+
solution: {
558+
commits: ["1gfedcba", "987654321"],
559+
commands: ["npm install"],
560+
files: ["someFile.js"],
561+
},
562+
},
563+
{
564+
id: "L1S2",
565+
content: "The second step",
566+
setup: {
567+
commits: ["2abcdefg"],
568+
commands: ["npm install"],
569+
files: ["someFile.js"],
570+
watchers: ["someFile.js"],
571+
filter: "someFilter",
572+
subtasks: true,
573+
},
574+
solution: {
575+
commits: ["3abcdefg"],
576+
commands: ["npm install"],
577+
files: ["someFile.js"],
578+
},
579+
},
580+
],
581+
},
582+
{
583+
id: "L2",
584+
title: "Title 2",
585+
summary: "Second level content.",
586+
content: "Second level content.",
587+
steps: [
588+
{
589+
id: "L2S1",
590+
content: "The third step",
591+
setup: {
592+
commits: ["4abcdefg"],
593+
commands: ["npm install"],
594+
files: ["someFile.js"],
595+
watchers: ["someFile.js"],
596+
filter: "someFilter",
597+
subtasks: true,
598+
},
599+
solution: {
600+
commits: ["5abcdefg"],
601+
commands: ["npm install"],
602+
files: ["someFile.js"],
603+
},
604+
},
605+
],
606+
},
607+
],
608+
};
609+
expect(result.levels).toEqual(expected.levels);
610+
});
611+
430612
// config
431613
it("should parse the tutorial config", () => {
432614
const md = `# Title

0 commit comments

Comments
 (0)