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

Commit0693ced

Browse files
authored
Merge pull request#55 from ShMcK/fix/test-runner
Fix/test runner
2 parentscef17a6 +d2b2b43 commit0693ced

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

‎src/editor/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }:
6161
},
6262
onFail:(payload:Payload,message:string)=>{
6363
// send test fail message back to client
64-
vscode.window.showWarningMessage(`FAIL:${message}`)
64+
vscode.window.showWarningMessage(`FAIL${message}`)
6565
webview.send({type:'TEST_FAIL', payload})
6666
},
6767
onError:(payload:Payload)=>{

‎src/services/testRunner/index.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
importnodefrom'../../services/node'
22
import{getOutputChannel}from'../../editor/outputChannel'
33
importparserfrom'./parser'
4-
import{setLatestProcess,isLatestProcess}from'./throttle'
4+
//import { setLatestProcess, isLatestProcess } from './throttle'
55

66
exportinterfacePayload{
77
stepId:string
@@ -22,7 +22,7 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
2222
constoutputChannelName='TEST_OUTPUT'
2323

2424
returnasync(payload:Payload,onSuccess?:()=>void):Promise<void>=>{
25-
console.log('-------------------run test------------------')
25+
console.log('-------------------RUN TEST -------------------')
2626

2727
// flag as running
2828
callbacks.onRun(payload)
@@ -31,41 +31,36 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
3131
try{
3232
result=awaitnode.exec(config.command)
3333
}catch(err){
34-
result=err
34+
result={stdout:err.stdout,stderr:err.stack}
3535
}
3636
const{ stdout, stderr}=result
3737

38-
// simple way to throttle requests
39-
if(!stdout){
40-
return
41-
}
42-
38+
consttap=parser(stdout||'')
4339
if(stderr){
44-
callbacks.onError(payload)
45-
46-
// open terminal with error string
47-
constchannel=getOutputChannel(outputChannelName)
48-
channel.show(false)
49-
channel.appendLine(stderr)
50-
return
40+
// failures also trigger stderr
41+
if(stdout&&stdout.length&&!tap.ok){
42+
constmessage=tap.message ?tap.message :''
43+
callbacks.onFail(payload,message)
44+
return
45+
}else{
46+
callbacks.onError(payload)
47+
// open terminal with error string
48+
constchannel=getOutputChannel(outputChannelName)
49+
channel.show(false)
50+
channel.appendLine(stderr)
51+
return
52+
}
5153
}
5254

53-
// pass or fail?
54-
consttap=parser(stdout)
55+
// success!
5556
if(tap.ok){
5657
callbacks.onSuccess(payload)
5758
if(onSuccess){
5859
onSuccess()
5960
}
6061
}else{
61-
// TODO: consider logging output to channel
62-
// open terminal with failed test string
63-
// const channel = getOutputChannel(outputChannelName)
64-
// channel.show(false)
65-
// channel.appendLine(tap.message)
66-
67-
constmessage=tap.message ?tap.message :''
68-
callbacks.onFail(payload,message)
62+
// should never get here
63+
callbacks.onError(payload)
6964
}
7065
}
7166
}

‎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