Skip to content

Feature/test output #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
node_modules
node_modules
coverage
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"moduleFileExtensions": [
"js",
"ts"
]
],
"collectCoverage": true
}
}
29 changes: 5 additions & 24 deletions src/templates/coderoad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ config:
# - npm install
## App versions helps to ensure compatability with the Extension
appVersions:
{}
## Ensure compatability with a minimal VSCode CodeRoad version
# vscode: '>=0.7.0'
vscode: ">=0.7.0"
## Repo information to load code from
##
repo:
Expand Down Expand Up @@ -62,25 +61,16 @@ levels:
## Setup for the first task. Required.
setup:
## Files to open in a text editor when the task loads. Optional.
files: []
# - package.json
## Commits to load when the task loads. These should include failing tests. Required.
## The list will be filled by the parser
commits:
[]
# - a commit hash
files:
- package.json
## Solution for the first task. Required.
solution:
## Files to open when the solution loads. Optional.
files: []
# - package.json
## Commits that complete the task. All tests should pass when the commits load. These commits will not be loaded by the tutorial user in normal tutorial activity.
## The list will be filled by the parser
commits: []
files:
- package.json
## Example Two: Running commands
- id: L1S2
setup:
commits: []
## CLI commands that are run when the task loads. Optional.
commands:
- npm install
Expand All @@ -94,27 +84,18 @@ levels:
setup:
files:
- package.json
commits:
- commit7
## Listeners that run tests when a file or directory changes.
watchers:
- package.json
- node_modules/some-package
solution:
files:
- package.json
commits:
- commit8
## Example Four: Subtasks
- id: L1S4
setup:
commits:
- commit8
commands:
## A filter is a regex that limits the test results
- filter: "^Example 2"
## A feature that shows subtasks: all filtered active test names and the status of the tests (pass/fail).
- subtasks: true
solution:
commits:
- commit9
182 changes: 95 additions & 87 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import * as T from "../../typings/tutorial";

type TutorialFrame = {
summary: T.TutorialSummary;
levels: {
[levelKey: string]: T.Level;
};
steps: { [stepKey: string]: Partial<T.Step> };
};

export function parseMdContent(md: string): TutorialFrame | never {
Expand All @@ -24,73 +28,66 @@ export function parseMdContent(md: string): TutorialFrame | never {
}
});

const sections = {};
const mdContent: TutorialFrame = {
summary: {
title: "",
description: "",
},
levels: {},
steps: {},
};

// Identify and remove the header
// Capture summary
const summaryMatch = parts
.shift()
.match(/^#\s(?<tutorialTitle>.*)[\n\r]+(?<tutorialDescription>[^]*)/);

if (!summaryMatch.groups.tutorialTitle) {
throw new Error("Missing tutorial title");
}
mdContent.summary.title = summaryMatch.groups.tutorialTitle.trim();

if (!summaryMatch.groups.tutorialDescription) {
throw new Error("Missing tutorial summary description");
}

sections["summary"] = {
title: summaryMatch.groups.tutorialTitle.trim(),
description: summaryMatch.groups.tutorialDescription.trim(),
};
mdContent.summary.description = summaryMatch.groups.tutorialDescription.trim();

// Identify each part of the content
parts.forEach((section) => {
parts.forEach((section: string) => {
// match level
const levelRegex = /^(##\s(?<levelId>L\d+)\s(?<levelTitle>.*)[\n\r]*(>\s*(?<levelSummary>.*))?[\n\r]+(?<levelContent>[^]*))/;
const stepRegex = /^(###\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;

const levelMatch = section.match(levelRegex);
const stepMatch = section.match(stepRegex);

if (levelMatch) {
const levelMatch: RegExpMatchArray | null = section.match(levelRegex);
if (levelMatch && levelMatch.groups) {
const {
levelId,
levelTitle,
levelSummary,
levelContent,
} = levelMatch.groups;

const level = {
[levelId]: {
id: levelId,
title: levelTitle,
summary: levelSummary
? levelSummary.trim()
: _.truncate(levelContent, { length: 80, omission: "..." }),
content: levelContent.trim(),
},
};

_.merge(sections, level);
} else if (stepMatch) {
const step = {
[stepMatch.groups.levelId]: {
steps: {
[stepMatch.groups.stepId]: {
id: stepMatch.groups.stepId,
// title: stepMatch.groups.stepTitle, //Not using at this momemnt
content: stepMatch.groups.stepContent.trim(),
},
},
},
// @ts-ignore
mdContent.levels[levelId] = {
id: levelId,
title: levelTitle,
summary: levelSummary
? levelSummary.trim()
: _.truncate(levelContent, { length: 80, omission: "..." }),
content: levelContent.trim(),
};

_.merge(sections, step);
} else {
// match step
const stepRegex = /^(###\s(?<stepId>(?<levelId>L\d+)S\d+)\s(?<stepTitle>.*)[\n\r]+(?<stepContent>[^]*))/;
const stepMatch: RegExpMatchArray | null = section.match(stepRegex);
if (stepMatch && stepMatch.groups) {
const { stepId, stepContent } = stepMatch.groups;
mdContent.steps[stepId] = {
id: stepId,
content: stepContent.trim(),
};
}
}
});

// @ts-ignore
return sections;
return mdContent;
}

type ParseParams = {
Expand All @@ -100,65 +97,76 @@ type ParseParams = {
};

export function parse(params: ParseParams): any {
const parsed = { ...params.config };

const mdContent: TutorialFrame = parseMdContent(params.text);

// Add the summary to the tutorial file
parsed["summary"] = mdContent.summary;
const parsed: Partial<T.Tutorial> = {
summary: mdContent.summary,
config: params.config.config,
levels: [],
};

// merge content and tutorial
if (parsed.levels) {
parsed.levels.forEach((level: T.Level, levelIndex: number) => {
const levelContent = mdContent[level.id];
if (params.config.levels && params.config.levels.length) {
parsed.levels = params.config.levels.map(
(level: T.Level, levelIndex: number) => {
const levelContent = mdContent.levels[level.id];

if (!levelContent) {
console.log(`Markdown content not found for ${level.id}`);
return;
}

if (!levelContent) {
console.log(`Markdown content not found for ${level.id}`);
return;
}
level = { ...level, ...levelContent };

// add level setup commits
const levelSetupKey = `L${levelIndex + 1}`;
if (params.commits[levelSetupKey]) {
if (!level.setup) {
level.setup = {
commits: [],
};
// add level setup commits
const levelSetupKey = level.id;
if (params.commits[levelSetupKey]) {
if (!level.setup) {
level.setup = {
commits: [],
};
}
level.setup.commits = params.commits[levelSetupKey];
}
level.setup.commits = params.commits[levelSetupKey];
}

const { steps, ...content } = levelContent;

// add level step commits
if (steps) {
steps.forEach((step: T.Step, stepIndex: number) => {
const stepSetupKey = `${levelSetupKey}S${stepIndex + `1`}Q`;
if (params.commits[stepSetupKey]) {
if (!step.setup) {
step.setup = {
commits: [],
};
// add level step commits
level.steps = (level.steps || []).map(
(step: T.Step, stepIndex: number) => {
const stepKey = `${levelSetupKey}S${stepIndex + 1}`;
const stepSetupKey = `${stepKey}Q`;
if (params.commits[stepSetupKey]) {
if (!step.setup) {
step.setup = {
commits: [],
};
}
step.setup.commits = params.commits[stepSetupKey];
}

const stepSolutionKey = `${stepKey}A`;
if (params.commits[stepSolutionKey]) {
if (!step.solution) {
step.solution = {
commits: [],
};
}
step.solution.commits = params.commits[stepSolutionKey];
}
step.setup.commits = params.commits[stepSetupKey];
}

const stepSolutionKey = `${levelSetupKey}S${stepIndex + `1`}A`;
if (params.commits[stepSolutionKey]) {
if (!step.solution) {
step.solution = {
commits: [],
};
// add markdown
const stepMarkdown: Partial<T.Step> = mdContent.steps[step.id];
if (stepMarkdown) {
step = { ...step, ...stepMarkdown };
}
step.solution.commits = params.commits[stepSolutionKey];

step.id = `${stepKey}`;
return step;
}
);

return _.merge(step, steps[step.id]);
});
return level;
}

_.merge(level, content);
});
);
}

return parsed;
Expand Down
Loading