Skip to content

Commit 33d1f9e

Browse files
committed
load init commits
Signed-off-by: shmck <[email protected]>
1 parent 0dc9353 commit 33d1f9e

File tree

2 files changed

+87
-10
lines changed

2 files changed

+87
-10
lines changed

src/utils/parse.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ export function parse(params: ParseParams): any {
100100
const parsed: Partial<T.Tutorial> = {
101101
version: params.config.version,
102102
summary: mdContent.summary,
103-
config: params.config.config,
103+
config: params.config.config || {},
104104
levels: [],
105105
};
106106

107+
// add init commits
108+
if (params.commits.INIT && params.commits.INIT.length) {
109+
console.log(JSON.stringify(parsed.config?.testRunner));
110+
// @ts-ignore
111+
parsed.config.testRunner.setup = {
112+
...(parsed.config?.testRunner?.setup || {}),
113+
commits: params.commits.INIT,
114+
};
115+
}
116+
107117
// merge content and tutorial
108118
if (params.config.levels && params.config.levels.length) {
109119
parsed.levels = params.config.levels
@@ -119,12 +129,10 @@ export function parse(params: ParseParams): any {
119129
// add level setup commits
120130
const levelSetupKey = level.id;
121131
if (params.commits[levelSetupKey]) {
122-
if (!level.setup) {
123-
level.setup = {
124-
commits: [],
125-
};
126-
}
127-
level.setup.commits = params.commits[levelSetupKey];
132+
level.setup = {
133+
...(level.setup || {}),
134+
commits: params.commits[levelSetupKey],
135+
};
128136
}
129137

130138
// add level step commits

tests/parse.test.ts

+72-3
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ The third step
524524
text: md,
525525
config,
526526
commits: {
527-
INIT: [""],
528527
L1S1Q: ["abcdef1", "123456789"],
529528
L1S1A: ["1fedcba", "987654321"],
530529
L1S2Q: ["2abcdef"],
@@ -685,7 +684,6 @@ Description.
685684
},
686685
directory: "coderoad",
687686
setup: {
688-
commits: ["abcdef1"],
689687
commands: [],
690688
},
691689
},
@@ -722,7 +720,6 @@ Description.
722720
},
723721
directory: "coderoad",
724722
setup: {
725-
commits: ["abcdef1"],
726723
commands: [],
727724
},
728725
},
@@ -743,4 +740,76 @@ Description.
743740
};
744741
expect(result.config).toEqual(expected.config);
745742
});
743+
744+
it("should parse the tutorial config with INIT commits", () => {
745+
const md = `# Title
746+
747+
Description.
748+
`;
749+
750+
const config = {
751+
config: {
752+
testRunner: {
753+
command: "./node_modules/.bin/mocha",
754+
args: {
755+
filter: "--grep",
756+
tap: "--reporter=mocha-tap-reporter",
757+
},
758+
directory: "coderoad",
759+
},
760+
appVersions: {
761+
vscode: ">=0.7.0",
762+
},
763+
repo: {
764+
uri: "https://path.to/repo",
765+
branch: "aBranch",
766+
},
767+
dependencies: [
768+
{
769+
name: "node",
770+
version: ">=10",
771+
},
772+
],
773+
},
774+
};
775+
const result = parse({
776+
text: md,
777+
config,
778+
commits: {
779+
INIT: ["abcdef1", "123456789"],
780+
},
781+
});
782+
const expected = {
783+
summary: {
784+
description: "Description.\n\nSecond description line",
785+
},
786+
config: {
787+
testRunner: {
788+
command: "./node_modules/.bin/mocha",
789+
args: {
790+
filter: "--grep",
791+
tap: "--reporter=mocha-tap-reporter",
792+
},
793+
directory: "coderoad",
794+
setup: {
795+
commits: ["abcdef1", "123456789"],
796+
},
797+
},
798+
repo: {
799+
uri: "https://path.to/repo",
800+
branch: "aBranch",
801+
},
802+
dependencies: [
803+
{
804+
name: "node",
805+
version: ">=10",
806+
},
807+
],
808+
appVersions: {
809+
vscode: ">=0.7.0",
810+
},
811+
},
812+
};
813+
expect(result.config).toEqual(expected.config);
814+
});
746815
});

0 commit comments

Comments
 (0)