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

Commite61fdae

Browse files
committed
improve test parser
1 parentcef17a6 commite61fdae

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ ok 2 - Should also pass
1515
ok 1 - Should pass
1616
not ok 2 - This one fails
1717
ok 3 - Also passes
18+
`
19+
expect(parser(example).ok).toBe(false)
20+
})
21+
test('should detect failure if no tests passed',()=>{
22+
constexample=`
23+
# Starting...
24+
# 1 test suites found.
25+
26+
# FAIL __tests__/sum.test.js
27+
28+
not ok 1 ● sum › should add two numbers together
1829
`
1930
expect(parser(example).ok).toBe(false)
2031
})

‎src/services/testRunner/parser.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@ interface ParserOutput {
33
message?:string
44
}
55

6+
constfail=/^notok\d+.{1}(.+)+$/
7+
constok=/^ok\d+.{1}/
8+
69
constparser=(text:string):ParserOutput=>{
710
constlines=text.split('\n')
11+
lethasPass=false
812
for(constlineoflines){
9-
// parse failed test
10-
constmatch=line.match(/^notok\d+-(.+)+/)
11-
if(!!match){
12-
return{ok:false,message:match[1]}
13+
if(line.length){
14+
// parse failed test
15+
constfailRegex=fail.exec(line)
16+
if(!!failRegex){
17+
return{ok:false,message:failRegex[1]}
18+
}
19+
if(!hasPass){
20+
if(!!ok.exec(line)){
21+
hasPass=true
22+
}
23+
}
1324
}
1425
}
15-
return{ok:true}
26+
return{ok:hasPass}
1627
}
1728

1829
exportdefaultparser

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp