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 1 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
Next Next commit
test commits loading
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed May 31, 2020
commit f1353b388a2abd877082b5f753ec5abedf42f7f1
45 changes: 26 additions & 19 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,36 @@ export function parse(params: ParseParams): any {

// 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: [],
};
level.steps = Object.keys(steps).map(
(stepId: string, stepIndex: number) => {
const step: T.Step = steps[stepId];
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];
}
step.setup.commits = params.commits[stepSetupKey];
}

const stepSolutionKey = `${levelSetupKey}S${stepIndex + `1`}A`;
if (params.commits[stepSolutionKey]) {
if (!step.solution) {
step.solution = {
commits: [],
};
const stepSolutionKey = `${stepKey}A`;
if (params.commits[stepSolutionKey]) {
if (!step.solution) {
step.solution = {
commits: [],
};
}
step.solution.commits = params.commits[stepSolutionKey];
}
step.solution.commits = params.commits[stepSolutionKey];
}

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

_.merge(level, content);
Expand Down
185 changes: 164 additions & 21 deletions tests/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parse } from "../src/utils/parse";

describe("parse", () => {
// summary
it("should parse summary", () => {
const md = `# Insert Tutorial's Title here

Expand All @@ -23,6 +24,7 @@ describe("parse", () => {
expect(result.summary).toEqual(expected.summary);
});

// levels
it("should parse a level with no steps", () => {
const md = `# Title

Expand Down Expand Up @@ -52,6 +54,7 @@ Some text
summary:
"Level's summary: a short description of the level's content in one line.",
content: "Some text",
steps: [],
},
],
};
Expand All @@ -76,6 +79,7 @@ Some text
id: "L1",
setup: { files: [], commits: [] },
solution: { files: [], commits: [] },
steps: [],
},
],
};
Expand All @@ -94,6 +98,7 @@ Some text
content: "Some text",
setup: { files: [], commits: [] },
solution: { files: [], commits: [] },
steps: [],
},
],
};
Expand Down Expand Up @@ -123,6 +128,7 @@ Some text that becomes the summary
title: "Put Level's title here",
summary: "Some text that becomes the summary",
content: "Some text that becomes the summary",
steps: [],
},
],
};
Expand Down Expand Up @@ -196,31 +202,168 @@ Third line
expect(result.levels[0].content).toBe(expected.levels[0].content);
});

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

Description.

## L1 Title

First line

### L1S1 Step

The first step
`;
const config = {
levels: [
{
id: "L1",
steps: [
{
id: "L1S1",
},
],
},
],
};
const result = parse({
text: md,
config,
commits: {
L1S1Q: ["abcdefg1"],
},
});
const expected = {
summary: {
description: "Description.",
},
levels: [
{
id: "L1",
summary: "First line",
content: "First line",
steps: [
{
id: "L1S1",
content: "The first step",
setup: {
commits: ["abcdefg1"],
},
},
],
},
],
};
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
});

it("should load multiple commits for a step", () => {
const md = `# Title

Description.

## L1 Title

First line

### L1S1 Step

The first step
`;
const yaml = `
config:
testRunner:
command: ./node_modules/.bin/mocha
args:
filter: --grep
tap: --reporter=mocha-tap-reporter
directory: coderoad
setup:
commits:
- abcdefg1
commands: []
appVersions:
vscode: '>=0.7.0'
repo:
uri: https://path.to/repo
branch: aBranch
dependencies:
- name: node
version: '>=10'
const config = {
levels: [
{
id: "L1",
steps: [
{
id: "L1S1",
},
],
},
],
};
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"],
},
},
],
},
],
};
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
});

it("should load a single commit for a level", () => {
const md = `# Title

Description.

## L1 Title

First line

### L1S1

The first step
`;
const config = {
levels: [
{
id: "L1",
},
],
};
const result = parse({
text: md,
config,
commits: {
L1: ["abcdefg1"],
},
});
const expected = {
summary: {
description: "Description.",
},
levels: [
{
id: "L1",
summary: "First line",
content: "First line",
setup: {
commits: ["abcdefg1"],
},
},
],
};
expect(result.levels[0].setup).toEqual(expected.levels[0].setup);
});

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

Description.
`;

const config = {
Expand Down