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

Commit284e1f7

Browse files
committed
reconfigure test runner
1 parenta92f866 commit284e1f7

File tree

13 files changed

+170
-55
lines changed

13 files changed

+170
-55
lines changed

‎package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"watch":"tsc -watch -p ./"
3131
},
3232
"dependencies": {
33-
"jsdom":"^15.2.1"
33+
"jsdom":"^15.2.1",
34+
"tap-parser":"^10.0.1"
3435
},
3536
"devDependencies": {
3637
"@types/assert":"^1.4.3",

‎src/actions/runTest/index.ts

Whitespace-only changes.

‎src/actions/tutorialConfig.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asGfrom'typings/graphql'
22
import*asvscodefrom'vscode'
33
import*asgitfrom'../services/git'
4-
importlangaugeMapfrom'../editor/languageMap'
4+
importlanguageMapfrom'../editor/languageMap'
55

66
interfaceTutorialConfigParams{
77
config:G.TutorialConfig,
@@ -19,10 +19,27 @@ const tutorialConfig = async ({config, alreadyConfigured, }: TutorialConfigParam
1919
awaitgit.setupRemote(config.repo.uri)
2020
}
2121

22+
vscode.commands.executeCommand('coderoad.config_test_runner',config.testRunner)
23+
24+
constfileFormats=config.testRunner.fileFormats
25+
26+
// verify if file test should run based on document saved
27+
constshouldRun=(document:vscode.TextDocument):boolean=>{
28+
if(document.uri.scheme!=='file'){
29+
returnfalse
30+
}
31+
if(fileFormats&&fileFormats.length){
32+
constfileFormat:G.FileFormat=languageMap[document.languageId]
33+
if(!fileFormats.includes(fileFormat)){
34+
returnfalse
35+
}
36+
}
37+
returntrue
38+
}
39+
2240
// setup onSave hook
2341
vscode.workspace.onDidSaveTextDocument((document:vscode.TextDocument)=>{
24-
constfileFormat:G.FileFormat=langaugeMap[document.languageId]
25-
if(document.uri.scheme==='file'&&config.fileFormats.includes(fileFormat)){
42+
if(shouldRun(document)){
2643
vscode.commands.executeCommand('coderoad.run_test')
2744
}
2845
})

‎src/editor/ReactWebView.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class ReactWebView {
161161
}
162162
}
163163

164-
165164
// set CSP (content security policy) to grant permission to local files
166165
constcspMeta:HTMLMetaElement=document.createElement('meta')
167166
cspMeta.httpEquiv='Content-Security-Policy'

‎src/editor/commands.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import*asGfrom'typings/graphql'
12
import*asvscodefrom'vscode'
23
importReactWebViewfrom'./ReactWebView'
3-
importrunTestfrom'../actions/runTest'
4+
importcreateTestRunner,{Payload}from'../services/testRunner'
45

56
constCOMMANDS={
67
START:'coderoad.start',
78
OPEN_WEBVIEW:'coderoad.open_webview',
9+
CONFIG_TEST_RUNNER:'coderoad.config_test_runner',
810
RUN_TEST:'coderoad.run_test',
911
SET_CURRENT_STEP:'coderoad.set_current_step',
1012
}
@@ -19,6 +21,7 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
1921
// React panel webview
2022
letwebview:any
2123
letcurrentStepId=''
24+
lettestRunner:any
2225

2326
return{
2427
// initialize
@@ -49,37 +52,38 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
4952
// setup 1x1 horizontal layout
5053
webview.createOrShow()
5154
},
52-
[COMMANDS.SET_CURRENT_STEP]:({stepId}:{stepId:string})=>{
53-
// NOTE: as async, may sometimes be inaccurate
54-
// set from last setup stepAction
55-
currentStepId=stepId
56-
},
57-
[COMMANDS.RUN_TEST]:(current:{stepId:string}|undefined,onSuccess:()=>void)=>{
58-
console.log('-------- command.run_test ------ ')
59-
// use stepId from client, or last set stepId
60-
constpayload={stepId:current ?current.stepId :currentStepId}
61-
runTest({
62-
onSuccess:()=>{
55+
[COMMANDS.CONFIG_TEST_RUNNER]:(config:G.TutorialTestRunner)=>{
56+
testRunner=createTestRunner(config,{
57+
onSuccess:(payload:Payload)=>{
6358
// send test pass message back to client
64-
webview.send({type:'TEST_PASS', payload})
65-
onSuccess()
6659
vscode.window.showInformationMessage('PASS')
60+
webview.send({type:'TEST_PASS', payload})
6761
},
68-
onFail:()=>{
62+
onFail:(payload:Payload)=>{
6963
// send test fail message back to client
70-
webview.send({type:'TEST_FAIL', payload})
7164
vscode.window.showWarningMessage('FAIL')
65+
webview.send({type:'TEST_FAIL', payload})
7266
},
73-
onError:()=>{
74-
console.log('COMMAND TEST_ERROR')
67+
onError:(payload:Payload)=>{
7568
// send test error message back to client
7669
webview.send({type:'TEST_ERROR', payload})
7770
},
78-
onRun:()=>{
71+
onRun:(payload:Payload)=>{
7972
// send test run message back to client
8073
webview.send({type:'TEST_RUNNING', payload})
8174
}
8275
})
8376
},
77+
[COMMANDS.SET_CURRENT_STEP]:({stepId}:Payload)=>{
78+
// NOTE: as async, may sometimes be inaccurate
79+
// set from last setup stepAction
80+
currentStepId=stepId
81+
},
82+
[COMMANDS.RUN_TEST]:(current:Payload|undefined,onSuccess:()=>void)=>{
83+
console.log('-------- command.run_test ------ ')
84+
// use stepId from client, or last set stepId
85+
constpayload:Payload={stepId:current ?current.stepId :currentStepId}
86+
testRunner(payload,onSuccess)
87+
},
8488
}
8589
}

‎src/editor/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class Editor {
2929
}
3030

3131
privateactivateCommands=():void=>{
32-
3332
// set workspace root for node executions
3433
constworkspaceRoots:vscode.WorkspaceFolder[]|undefined=vscode.workspace.workspaceFolders
3534
if(!workspaceRoots||!workspaceRoots.length){
File renamed without changes.
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
importnodefrom'../../services/node'
2-
import{getOutputChannel}from'./channel'
2+
import{getOutputChannel}from'../../editor/outputChannel'
3+
importparserfrom'./parser'
34
import{setLatestProcess,isLatestProcess}from'./throttle'
45

5-
// TODO: use tap parser to make it easier to support other test runners
6-
// TODO: how to load test runner parser
7-
// TODO: where to instantiate test runner
8-
6+
exportinterfacePayload{
7+
stepId:string
8+
}
99

1010
interfaceCallbacks{
11-
onSuccess():void
12-
onFail():void
13-
onRun():void
14-
onError():void
11+
onSuccess(payload:Payload):void
12+
onFail(payload:Payload):void
13+
onRun(payload:Payload):void
14+
onError(payload:Payload):void
1515
}
1616

1717
interfaceTestRunnerConfig{
1818
command:string
19-
parser(output:string):Error|null
2019
}
2120

22-
exportconstcreateTestRunner=(config:TestRunnerConfig,callbacks:Callbacks)=>{
21+
constcreateTestRunner=(config:TestRunnerConfig,callbacks:Callbacks)=>{
2322

2423
constoutputChannelName='TEST_OUTPUT'
2524

26-
returnasync()=>{
25+
returnasync(payload:Payload,onSuccess?:()=>void)=>{
2726
console.log('------------------- run test ------------------')
2827

2928
// track processId to prevent multiple
3029
constprocessId=setLatestProcess()
3130
if(!isLatestProcess(processId)){return}
3231

3332
// flag as running
34-
callbacks.onRun()
33+
callbacks.onRun(payload)
3534

3635
letresult:{stdout:string|undefined,stderr:string|undefined}
3736
try{
@@ -45,7 +44,7 @@ export const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks)
4544
if(!stdout||!isLatestProcess(processId)){return}
4645

4746
if(stderr){
48-
callbacks.onError()
47+
callbacks.onError(payload)
4948

5049
// open terminal with error string
5150
constchannel=getOutputChannel(outputChannelName)
@@ -55,15 +54,19 @@ export const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks)
5554
}
5655

5756
// pass or fail?
58-
consttestsFailed=config.parser(stdout)
59-
if(testsFailed===null){
60-
callbacks.onSuccess()
57+
const{ok}=parser(stdout)
58+
if(ok){
59+
callbacks.onSuccess(payload)
60+
if(onSuccess){onSuccess()}
6161
}else{
62+
// TODO: parse failure message
6263
// open terminal with failed test string
63-
constchannel=getOutputChannel(outputChannelName)
64-
channel.show(false)
65-
channel.appendLine(testsFailed.message)
66-
callbacks.onFail()
64+
//const channel = getOutputChannel(outputChannelName)
65+
//channel.show(false)
66+
//channel.appendLine(testsFailed.message)
67+
callbacks.onFail(payload)
6768
}
6869
}
6970
}
71+
72+
exportdefaultcreateTestRunner

‎src/services/testRunner/parser.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
importTapParserfrom'tap-parser'
2+
3+
// https://github.com/tapjs/tap-parser#var-p--new-parseroptions-cb
4+
constoptions={
5+
bail:true,
6+
}
7+
8+
constparser=newTapParser(options)
9+
10+
exportdefaultparser

‎src/actions/runTest/throttle.tsrenamed to‎src/services/testRunner/throttle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export const setLatestProcess = () => currentId++
55

66
// quick solution to prevent processing multiple results
77
// NOTE: may be possible to kill child process early
8-
exportconstisLatestProcess=(processId:number):boolean=>currentId===processId
8+
exportconstisLatestProcess=(processId:number):boolean=>currentId===processId

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp