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

Commitf1353b3

Browse files
committed
test commits loading
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentc263369 commitf1353b3

File tree

2 files changed

+190
-40
lines changed

2 files changed

+190
-40
lines changed

‎src/utils/parse.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,36 @@ export function parse(params: ParseParams): any {
132132

133133
// add level step commits
134134
if(steps){
135-
steps.forEach((step:T.Step,stepIndex:number)=>{
136-
conststepSetupKey=`${levelSetupKey}S${stepIndex+`1`}Q`;
137-
if(params.commits[stepSetupKey]){
138-
if(!step.setup){
139-
step.setup={
140-
commits:[],
141-
};
135+
level.steps=Object.keys(steps).map(
136+
(stepId:string,stepIndex:number)=>{
137+
conststep:T.Step=steps[stepId];
138+
conststepKey=`${levelSetupKey}S${stepIndex+1}`;
139+
conststepSetupKey=`${stepKey}Q`;
140+
if(params.commits[stepSetupKey]){
141+
if(!step.setup){
142+
step.setup={
143+
commits:[],
144+
};
145+
}
146+
step.setup.commits=params.commits[stepSetupKey];
142147
}
143-
step.setup.commits=params.commits[stepSetupKey];
144-
}
145148

146-
conststepSolutionKey=`${levelSetupKey}S${stepIndex+`1`}A`;
147-
if(params.commits[stepSolutionKey]){
148-
if(!step.solution){
149-
step.solution={
150-
commits:[],
151-
};
149+
conststepSolutionKey=`${stepKey}A`;
150+
if(params.commits[stepSolutionKey]){
151+
if(!step.solution){
152+
step.solution={
153+
commits:[],
154+
};
155+
}
156+
step.solution.commits=params.commits[stepSolutionKey];
152157
}
153-
step.solution.commits=params.commits[stepSolutionKey];
154-
}
155158

156-
return_.merge(step,steps[step.id]);
157-
});
159+
step.id=`${stepKey}`;
160+
returnstep;
161+
}
162+
);
163+
}else{
164+
level.steps=[];
158165
}
159166

160167
_.merge(level,content);

‎tests/parse.test.ts

Lines changed: 164 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import{parse}from"../src/utils/parse";
22

33
describe("parse",()=>{
4+
// summary
45
it("should parse summary",()=>{
56
constmd=`# Insert Tutorial's Title here
67
@@ -23,6 +24,7 @@ describe("parse", () => {
2324
expect(result.summary).toEqual(expected.summary);
2425
});
2526

27+
// levels
2628
it("should parse a level with no steps",()=>{
2729
constmd=`# Title
2830
@@ -52,6 +54,7 @@ Some text
5254
summary:
5355
"Level's summary: a short description of the level's content in one line.",
5456
content:"Some text",
57+
steps:[],
5558
},
5659
],
5760
};
@@ -76,6 +79,7 @@ Some text
7679
id:"L1",
7780
setup:{files:[],commits:[]},
7881
solution:{files:[],commits:[]},
82+
steps:[],
7983
},
8084
],
8185
};
@@ -94,6 +98,7 @@ Some text
9498
content:"Some text",
9599
setup:{files:[],commits:[]},
96100
solution:{files:[],commits:[]},
101+
steps:[],
97102
},
98103
],
99104
};
@@ -123,6 +128,7 @@ Some text that becomes the summary
123128
title:"Put Level's title here",
124129
summary:"Some text that becomes the summary",
125130
content:"Some text that becomes the summary",
131+
steps:[],
126132
},
127133
],
128134
};
@@ -196,31 +202,168 @@ Third line
196202
expect(result.levels[0].content).toBe(expected.levels[0].content);
197203
});
198204

199-
it("should parse the tutorial config",()=>{
205+
it("should load a single commit for a step",()=>{
206+
constmd=`# Title
207+
208+
Description.
209+
210+
## L1 Title
211+
212+
First line
213+
214+
### L1S1 Step
215+
216+
The first step
217+
`;
218+
constconfig={
219+
levels:[
220+
{
221+
id:"L1",
222+
steps:[
223+
{
224+
id:"L1S1",
225+
},
226+
],
227+
},
228+
],
229+
};
230+
constresult=parse({
231+
text:md,
232+
config,
233+
commits:{
234+
L1S1Q:["abcdefg1"],
235+
},
236+
});
237+
constexpected={
238+
summary:{
239+
description:"Description.",
240+
},
241+
levels:[
242+
{
243+
id:"L1",
244+
summary:"First line",
245+
content:"First line",
246+
steps:[
247+
{
248+
id:"L1S1",
249+
content:"The first step",
250+
setup:{
251+
commits:["abcdefg1"],
252+
},
253+
},
254+
],
255+
},
256+
],
257+
};
258+
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
259+
});
260+
261+
it("should load multiple commits for a step",()=>{
200262
constmd=`# Title
201263
202264
Description.
265+
266+
## L1 Title
267+
268+
First line
269+
270+
### L1S1 Step
271+
272+
The first step
203273
`;
204-
constyaml=`
205-
config:
206-
testRunner:
207-
command: ./node_modules/.bin/mocha
208-
args:
209-
filter: --grep
210-
tap: --reporter=mocha-tap-reporter
211-
directory: coderoad
212-
setup:
213-
commits:
214-
- abcdefg1
215-
commands: []
216-
appVersions:
217-
vscode: '>=0.7.0'
218-
repo:
219-
uri: https://path.to/repo
220-
branch: aBranch
221-
dependencies:
222-
- name: node
223-
version: '>=10'
274+
constconfig={
275+
levels:[
276+
{
277+
id:"L1",
278+
steps:[
279+
{
280+
id:"L1S1",
281+
},
282+
],
283+
},
284+
],
285+
};
286+
constresult=parse({
287+
text:md,
288+
config,
289+
commits:{
290+
L1S1Q:["abcdefg1","123456789"],
291+
},
292+
});
293+
constexpected={
294+
summary:{
295+
description:"Description.",
296+
},
297+
levels:[
298+
{
299+
id:"L1",
300+
summary:"First line",
301+
content:"First line",
302+
steps:[
303+
{
304+
id:"L1S1",
305+
content:"The first step",
306+
setup:{
307+
commits:["abcdefg1","123456789"],
308+
},
309+
},
310+
],
311+
},
312+
],
313+
};
314+
expect(result.levels[0].steps[0]).toEqual(expected.levels[0].steps[0]);
315+
});
316+
317+
it("should load a single commit for a level",()=>{
318+
constmd=`# Title
319+
320+
Description.
321+
322+
## L1 Title
323+
324+
First line
325+
326+
### L1S1
327+
328+
The first step
329+
`;
330+
constconfig={
331+
levels:[
332+
{
333+
id:"L1",
334+
},
335+
],
336+
};
337+
constresult=parse({
338+
text:md,
339+
config,
340+
commits:{
341+
L1:["abcdefg1"],
342+
},
343+
});
344+
constexpected={
345+
summary:{
346+
description:"Description.",
347+
},
348+
levels:[
349+
{
350+
id:"L1",
351+
summary:"First line",
352+
content:"First line",
353+
setup:{
354+
commits:["abcdefg1"],
355+
},
356+
},
357+
],
358+
};
359+
expect(result.levels[0].setup).toEqual(expected.levels[0].setup);
360+
});
361+
362+
// config
363+
it("should parse the tutorial config",()=>{
364+
constmd=`# Title
365+
366+
Description.
224367
`;
225368

226369
constconfig={

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp