Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 3 commits intomasterfromfeature/test-output
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
refactor step tests
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedMay 31, 2020
commitf11a7abb6650533a3d93e7c2658e576d89b12605
29 changes: 5 additions & 24 deletionssrc/templates/coderoad.yaml
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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
149 changes: 75 additions & 74 deletionssrc/utils/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff 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,41 +97,41 @@ 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) {
level.steps = Object.keys(steps).map(
(stepId: string, stepIndex: number) => {
const step: T.Step = steps[stepId];
// 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]) {
Expand All@@ -156,16 +153,20 @@ export function parse(params: ParseParams): any {
step.solution.commits = params.commits[stepSolutionKey];
}

// add markdown
const stepMarkdown: Partial<T.Step> = mdContent.steps[step.id];
if (stepMarkdown) {
step = { ...step, ...stepMarkdown };
}

step.id = `${stepKey}`;
return step;
}
);
} else {
level.steps = [];
}

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

return parsed;
Expand Down
68 changes: 68 additions & 0 deletionstests/parse.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -359,6 +359,74 @@ The first step
expect(result.levels[0].setup).toEqual(expected.levels[0].setup);
});

it("should load the full config for a step", () => {
const md = `# Title

Description.

## L1 Title

First line

### L1S1 Step

The first step
`;
const config = {
levels: [
{
id: "L1",
steps: [
{
id: "L1S1",
setup: {
commands: ["npm install"],
files: ["someFile.js"],
watchers: ["someFile.js"],
filter: "someFilter",
subtasks: true,
},
},
],
},
],
};
const result = parse({
text: md,
config,
commits: {
L1S1Q: ["abcdefg1", "123456789"],
},
});
const expected = {
summary: {
description: "Description.",
},
levels: [
{
id: "L1",
summary: "First line",
content: "First line",
steps: [
{
id: "L1S1",
content: "The first step",
setup: {
commits: ["abcdefg1", "123456789"],
commands: ["npm install"],
files: ["someFile.js"],
watchers: ["someFile.js"],
filter: "someFilter",
subtasks: true,
},
},
],
},
],
};
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
});

// config
it("should parse the tutorial config", () => {
const md = `# Title
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp