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

Commit9b9c55f

Browse files
committed
collect passing success as well
1 parent267f752 commit9b9c55f

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

‎src/services/testRunner/parser.test.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ describe('parser', () => {
66
1..1
77
ok 1 - Should pass
88
`
9-
expect(parser(example)).toEqual({ok:true,fails:[]})
9+
expect(parser(example)).toEqual({ok:true,passed:[{message:'Should pass'}],failed:[]})
1010
})
1111
test('should detect multiple successes',()=>{
1212
constexample=`
1313
1..2
1414
ok 1 - Should pass
1515
ok 2 - Should also pass
1616
`
17-
expect(parser(example)).toEqual({ok:true,fails:[]})
17+
constresult=parser(example)
18+
expect(result).toEqual({
19+
ok:true,
20+
passed:[{message:'Should pass'},{message:'Should also pass'}],
21+
failed:[],
22+
})
1823
})
1924
test('should detect failure if no tests passed',()=>{
2025
constexample=`
@@ -44,7 +49,7 @@ not ok 2 - First to fail
4449
ok 3 - Also passes
4550
not ok 4 - Second to fail
4651
`
47-
expect(parser(example).fails).toEqual([{message:'First to fail'},{message:'Second to fail'}])
52+
expect(parser(example).failed).toEqual([{message:'First to fail'},{message:'Second to fail'}])
4853
})
4954

5055
test('should parse mocha tap example',()=>{
@@ -72,7 +77,7 @@ ok 3 sumItems should total numbers accurately
7277
# fail 1
7378
# skip 0
7479
`
75-
expect(parser(example).fails).toEqual([{message:"sumItems shouldn't return NaN"}])
80+
expect(parser(example).failed).toEqual([{message:"sumItems shouldn't return NaN"}])
7681
})
7782
test('should capture single error details',()=>{
7883
constexample=`
@@ -86,8 +91,8 @@ not ok 1 package.json should have a valid "author" key
8691
# skip 0
8792
`
8893
constresult=parser(example)
89-
expect(result.fails[0].message).toBe('package.json should have a valid "author" key')
90-
expect(result.fails[0].details).toBe(`AssertionError [ERR_ASSERTION]: no "author" key provided
94+
expect(result.failed[0].message).toBe('package.json should have a valid "author" key')
95+
expect(result.failed[0].details).toBe(`AssertionError [ERR_ASSERTION]: no "author" key provided
9196
at Context.<anonymous> (test/packagejson.test.js:11:12)
9297
at processImmediate (internal/timers.js:439:21)`)
9398
})
@@ -105,12 +110,12 @@ not ok 2 package.json should have a valid "description" key
105110
# skip 0
106111
`
107112
constresult=parser(example)
108-
expect(result.fails[0].message).toBe('package.json should have a valid "author" key')
109-
expect(result.fails[0].details).toBe(`AssertionError [ERR_ASSERTION]: no "author" key provided
113+
expect(result.failed[0].message).toBe('package.json should have a valid "author" key')
114+
expect(result.failed[0].details).toBe(`AssertionError [ERR_ASSERTION]: no "author" key provided
110115
at Context.<anonymous> (test/packagejson.test.js:11:12)
111116
at processImmediate (internal/timers.js:439:21)`)
112-
expect(result.fails[1].message).toBe('package.json should have a valid "description" key')
113-
expect(result.fails[1].details).toBe(`AssertionError [ERR_ASSERTION]: no "description" key provided`)
117+
expect(result.failed[1].message).toBe('package.json should have a valid "description" key')
118+
expect(result.failed[1].details).toBe(`AssertionError [ERR_ASSERTION]: no "description" key provided`)
114119
})
115120
test('should capture multiple error details between successes',()=>{
116121
constexample=`
@@ -129,11 +134,11 @@ ok 5 some passing test
129134
# skip 0
130135
`
131136
constresult=parser(example)
132-
expect(result.fails[0].message).toBe('package.json should have a valid "author" key')
133-
expect(result.fails[0].details).toBe(`AssertionError [ERR_ASSERTION]: no "author" key provided
137+
expect(result.failed[0].message).toBe('package.json should have a valid "author" key')
138+
expect(result.failed[0].details).toBe(`AssertionError [ERR_ASSERTION]: no "author" key provided
134139
at Context.<anonymous> (test/packagejson.test.js:11:12)
135140
at processImmediate (internal/timers.js:439:21)`)
136-
expect(result.fails[1].message).toBe('package.json should have a valid "description" key')
137-
expect(result.fails[1].details).toBe(`AssertionError [ERR_ASSERTION]: no "description" key provided`)
141+
expect(result.failed[1].message).toBe('package.json should have a valid "description" key')
142+
expect(result.failed[1].details).toBe(`AssertionError [ERR_ASSERTION]: no "description" key provided`)
138143
})
139144
})

‎src/services/testRunner/parser.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
interfaceParserOutput{
22
ok:boolean
3-
fails:Array<{message:string;details?:string}>
3+
passed:Array<{message:string}>
4+
failed:Array<{message:string;details?:string}>
45
}
56

67
constr={
78
fail:/^notok\d+\s(\-\s)?(.+)+$/,
8-
pass:/^ok/,
9+
pass:/^ok\d+\s(\-\s)?(.+)+$/,
910
details:/^#\s{2}(.+)$/,
1011
}
1112

@@ -15,17 +16,18 @@ const parser = (text: string): ParserOutput => {
1516
constlines=text.split('\n')
1617

1718
constresult:ParserOutput={
18-
ok:false,
19-
fails:[],
19+
ok:true,
20+
passed:[],
21+
failed:[],
2022
}
2123

2224
// temporary holder of error detail strings
2325
letcurrentDetails:string|null=null
2426

2527
constaddCurrentDetails=()=>{
26-
constfailLength:number=result.fails.length
28+
constfailLength:number=result.failed.length
2729
if(currentDetails&&!!failLength){
28-
result.fails[failLength-1].details=currentDetails
30+
result.failed[failLength-1].details=currentDetails
2931
currentDetails=null
3032
}
3133
}
@@ -35,20 +37,19 @@ const parser = (text: string): ParserOutput => {
3537
continue
3638
}
3739
// be optimistic! check for success
38-
if(!result.ok&&!result.fails.length){
39-
if(!!detect('pass',line)){
40-
result.ok=true
41-
addCurrentDetails()
42-
continue
43-
}
40+
constisPass=detect('pass',line)
41+
if(!!isPass){
42+
result.passed.push({message:isPass[2].trim()})
43+
addCurrentDetails()
44+
continue
4445
}
4546

4647
// check for failure
4748
constisFail=detect('fail',line)
4849
if(!!isFail){
4950
result.ok=false
5051
addCurrentDetails()
51-
result.fails.push({message:isFail[2]})
52+
result.failed.push({message:isFail[2].trim()})
5253
continue
5354
}
5455

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp