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

Commit369bd90

Browse files
committed
handle reset when no steps or earlier levels
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parente93ba24 commit369bd90

File tree

3 files changed

+102
-43
lines changed

3 files changed

+102
-43
lines changed

‎src/actions/onRunReset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const onRunReset = async (action: ResetAction, context: Context) => {
1717
constposition:T.Position=action.position ?action.position :context.position.get()
1818

1919
// get last pass commit
20-
consthash:string=getCommitHashByPosition(position,tutorial?.levels||[])
20+
consthash:string=getCommitHashByPosition(position,tutorial)
2121

2222
constbranch=tutorial?.config.repo.branch
2323

‎src/services/reset/lastHash.test.ts

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,83 @@ import getLastCommitHash from './lastHash'
55
describe('lastHash',()=>{
66
it('should grab the last passing hash from a step',()=>{
77
constposition:T.Position={levelId:'1',stepId:'1.2'}
8-
constlevels:TT.Level[]=[
9-
{
10-
id:'1',
11-
title:'',
12-
summary:'',
13-
content:'',
14-
steps:[
15-
{
16-
id:'1.1',
17-
content:'',
18-
setup:{commits:['abcdef1']},
19-
},
20-
{
21-
id:'1.2',
22-
content:'',
23-
setup:{commits:['abcdef2']},
24-
},
25-
],
26-
},
27-
]
28-
constresult=getLastCommitHash(position,levels)
8+
//@ts-ignore
9+
consttutorial:TT.Tutorial={
10+
levels:[
11+
{
12+
id:'1',
13+
title:'',
14+
summary:'',
15+
content:'',
16+
steps:[
17+
{
18+
id:'1.1',
19+
content:'',
20+
setup:{commits:['abcdef1']},
21+
},
22+
{
23+
id:'1.2',
24+
content:'',
25+
setup:{commits:['abcdef2']},
26+
},
27+
],
28+
},
29+
],
30+
}
31+
constresult=getLastCommitHash(position,tutorial)
2932
expect(result).toBe('abcdef2')
3033
})
3134
it('should grab the last passing hash from a step with several commits',()=>{
3235
constposition:T.Position={levelId:'1',stepId:'1.2'}
33-
constlevels:TT.Level[]=[
34-
{
35-
id:'1',
36-
title:'',
37-
summary:'',
38-
content:'',
39-
steps:[
40-
{
41-
id:'1.1',
42-
content:'',
43-
setup:{commits:['abcdef1']},
44-
},
45-
{
46-
id:'1.2',
47-
content:'',
48-
setup:{commits:['abcdef2','abcdef3']},
36+
//@ts-ignore
37+
consttutorial:TT.Tutorial={
38+
levels:[
39+
{
40+
id:'1',
41+
title:'',
42+
summary:'',
43+
content:'',
44+
steps:[
45+
{
46+
id:'1.1',
47+
content:'',
48+
setup:{commits:['abcdef1']},
49+
},
50+
{
51+
id:'1.2',
52+
content:'',
53+
setup:{commits:['abcdef2','abcdef3']},
54+
},
55+
],
56+
},
57+
],
58+
}
59+
constresult=getLastCommitHash(position,tutorial)
60+
expect(result).toBe('abcdef3')
61+
})
62+
it('should grab the last passing hash when level has no steps',()=>{
63+
constposition:T.Position={levelId:'1',stepId:null}
64+
//@ts-ignore
65+
consttutorial:TT.Tutorial={
66+
config:{
67+
//@ts-ignore
68+
testRunner:{
69+
setup:{
70+
commits:['abcdef2','abcdef3'],
4971
},
50-
],
72+
},
5173
},
52-
]
53-
constresult=getLastCommitHash(position,levels)
74+
levels:[
75+
{
76+
id:'1',
77+
title:'',
78+
summary:'',
79+
content:'',
80+
steps:[],
81+
},
82+
],
83+
}
84+
constresult=getLastCommitHash(position,tutorial)
5485
expect(result).toBe('abcdef3')
5586
})
5687
})

‎src/services/reset/lastHash.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
import*asTTfrom'../../../typings/tutorial'
22
import*asTfrom'../../../typings'
33

4-
constgetLastCommitHash=(position:T.Position,levels:TT.Level[])=>{
4+
constgetLastCommitHash=(position:T.Position,tutorial:TT.Tutorial|null)=>{
5+
if(!tutorial){
6+
thrownewError('No tutorial found')
7+
}
8+
const{ levels}=tutorial
59
// get previous position
610
const{ levelId, stepId}=position
711

8-
constlevel:TT.Level|undefined=levels.find((l)=>levelId===l.id)
12+
letlevel:TT.Level|undefined=levels.find((l)=>levelId===l.id)
913
if(!level){
1014
thrownewError(`No level found matching${levelId}`)
1115
}
16+
17+
// handle a level with no steps
18+
if(!level.steps||!level.steps.length){
19+
if(level.setup&&level.setup.commits){
20+
// return level commit
21+
constlevelCommits=level.setup.commits
22+
returnlevelCommits[levelCommits.length-1]
23+
}else{
24+
// is there a previous level?
25+
//@ts-ignore
26+
constlevelIndex=levels.findIndex((l:TT.Level)=>level.id===l.id)
27+
if(levelIndex>0){
28+
level=levels[levelIndex-1]
29+
}else{
30+
// use init commit
31+
constconfigCommits=tutorial.config.testRunner.setup?.commits
32+
if(!configCommits){
33+
thrownewError('No commits found to reset back to')
34+
}
35+
returnconfigCommits[configCommits.length-1]
36+
}
37+
}
38+
}
39+
1240
conststep=level.steps.find((s)=>stepId===s.id)
1341
if(!step){
1442
thrownewError(`No step found matching${stepId}`)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp