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

Commit699e8b6

Browse files
authored
Merge pull request#53 from ShMcK/feature/refactor-test-runner
Feature/refactor test runner
2 parentsb8d01ea +ea29d23 commit699e8b6

File tree

16 files changed

+234
-194
lines changed

16 files changed

+234
-194
lines changed

‎src/actions/runTest.ts

Lines changed: 0 additions & 138 deletions
This file was deleted.

‎src/actions/setupActions.ts

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@ import * as vscode from 'vscode'
44
import*asgitfrom'../services/git'
55
importnodefrom'../services/node'
66

7-
interfaceErrorMessageFilter{
8-
[lang:string]:{
9-
[key:string]:string
10-
}
11-
}
7+
//interface ErrorMessageFilter {
8+
//[lang: string]: {
9+
//[key: string]: string
10+
//}
11+
//}
1212

1313
// TODO: should be loaded on startup based on language
14-
constcommandErrorMessageFilter:ErrorMessageFilter={
15-
JAVASCRIPT:{
16-
'node-gyp':'Error running npm setup command'
17-
}
18-
}
14+
//const commandErrorMessageFilter: ErrorMessageFilter = {
15+
//#"diff-47d0c00fa3c186f7fc510aad6c9706e5d40404c1952033d7c544d0317de2b80b-18-16-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
16+
//'node-gyp': 'Error running npm setup command'
17+
//}
18+
//}
1919

2020

2121
// TODO: pass command and command name down for filtering. Eg. JAVASCRIPT, 'npm install'
22-
construnCommands=async(commands:string[],language:string='JAVASCRIPT')=>{
22+
construnCommands=async(commands:string[])=>{
2323
for(constcommandofcommands){
2424
const{stdout, stderr}=awaitnode.exec(command)
2525
if(stderr){
2626
console.error(stderr)
2727
// language specific error messages from running commands
28-
constfilteredMessages=Object.keys(commandErrorMessageFilter[language])
29-
for(constmessageoffilteredMessages){
30-
if(stderr.match(message)){
31-
// ignored error
32-
thrownewError('Error running setup command')
33-
}
34-
}
28+
//const filteredMessages = Object.keys(commandErrorMessageFilter[language])
29+
//for (const message of filteredMessages) {
30+
//if (stderr.match(message)) {
31+
//// ignored error
32+
//throw new Error('Error running setup command')
33+
//}
34+
//}
3535
}
3636
console.log(`run command:${command}`,stdout)
3737
}
@@ -45,7 +45,8 @@ const disposeWatcher = (listener: string) => {
4545
deletewatchers[listener]
4646
}
4747

48-
constsetupActions=async(workspaceRoot:vscode.WorkspaceFolder,{commands, commits, files, listeners}:G.StepActions):Promise<void>=>{
48+
constsetupActions=async(workspaceRoot:vscode.WorkspaceFolder,actions:G.StepActions):Promise<void>=>{
49+
const{commands, commits, files, listeners}=actions
4950
// run commits
5051
if(commits){
5152
for(constcommitofcommits){
@@ -55,16 +56,36 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co
5556

5657
// run file watchers (listeners)
5758
if(listeners){
59+
console.log('listeners')
5860
for(constlisteneroflisteners){
5961
if(!watchers[listener]){
6062
constpattern=newvscode.RelativePattern(
6163
vscode.workspace.getWorkspaceFolder(workspaceRoot.uri)!,
6264
listener
6365
)
64-
watchers[listener]=vscode.workspace.createFileSystemWatcher(
66+
console.log(pattern)
67+
constlisten=vscode.workspace.createFileSystemWatcher(
6568
pattern
6669
)
70+
watchers[listener]=listen
6771
watchers[listener].onDidChange(()=>{
72+
console.log('onDidChange')
73+
// trigger save
74+
vscode.commands.executeCommand('coderoad.run_test',null,()=>{
75+
// cleanup watcher on success
76+
disposeWatcher(listener)
77+
})
78+
})
79+
watchers[listener].onDidCreate(()=>{
80+
console.log('onDidCreate')
81+
// trigger save
82+
vscode.commands.executeCommand('coderoad.run_test',null,()=>{
83+
// cleanup watcher on success
84+
disposeWatcher(listener)
85+
})
86+
})
87+
watchers[listener].onDidDelete(()=>{
88+
console.log('onDidDelete')
6889
// trigger save
6990
vscode.commands.executeCommand('coderoad.run_test',null,()=>{
7091
// cleanup watcher on success

‎src/actions/tutorialConfig.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import*asGfrom'typings/graphql'
22
import*asvscodefrom'vscode'
33
import*asgitfrom'../services/git'
4-
importlangaugeMapfrom'../editor/languageMap'
4+
importlanguageMapfrom'../editor/languageMap'
5+
import{COMMANDS}from'../editor/commands'
56

67
interfaceTutorialConfigParams{
78
config:G.TutorialConfig,
@@ -19,10 +20,29 @@ const tutorialConfig = async ({config, alreadyConfigured, }: TutorialConfigParam
1920
awaitgit.setupRemote(config.repo.uri)
2021
}
2122

23+
vscode.commands.executeCommand(COMMANDS.CONFIG_TEST_RUNNER,config.testRunner)
24+
25+
constfileFormats=config.testRunner.fileFormats
26+
27+
// verify if file test should run based on document saved
28+
constshouldRunTest=(document:vscode.TextDocument):boolean=>{
29+
// must be a file
30+
if(document.uri.scheme!=='file'){
31+
returnfalse
32+
}
33+
// must configure with file formatss
34+
if(fileFormats&&fileFormats.length){
35+
constfileFormat:G.FileFormat=languageMap[document.languageId]
36+
if(!fileFormats.includes(fileFormat)){
37+
returnfalse
38+
}
39+
}
40+
returntrue
41+
}
42+
2243
// setup onSave hook
2344
vscode.workspace.onDidSaveTextDocument((document:vscode.TextDocument)=>{
24-
constfileFormat:G.FileFormat=langaugeMap[document.languageId]
25-
if(document.uri.scheme==='file'&&config.fileFormats.includes(fileFormat)){
45+
if(shouldRunTest(document)){
2646
vscode.commands.executeCommand('coderoad.run_test')
2747
}
2848
})

‎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 & 20 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

5-
constCOMMANDS={
6+
exportconstCOMMANDS={
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,37 @@ 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+
// use stepId from client, or last set stepId
84+
constpayload:Payload={stepId:current ?current.stepId :currentStepId}
85+
testRunner(payload,onSuccess)
86+
},
8487
}
8588
}

‎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){

‎src/editor/outputChannel.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import*asvscodefrom'vscode'
2+
3+
letchannel:vscode.OutputChannel
4+
5+
exportconstgetOutputChannel=(name:string):vscode.OutputChannel=>{
6+
if(!channel){
7+
channel=vscode.window.createOutputChannel(name)
8+
}
9+
returnchannel
10+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp