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

Commitab13f52

Browse files
committed
createTestRunner in progress
1 parent03e7216 commitab13f52

File tree

5 files changed

+118
-94
lines changed

5 files changed

+118
-94
lines changed

‎src/actions/runTest.tsrenamed to‎src/actions/runTest/index.ts

Lines changed: 64 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asvscodefrom'vscode'
2-
importnodefrom'../services/node'
2+
importnodefrom'../../services/node'
33

44
// TODO: use tap parser to make it easier to support other test runners
55

@@ -21,31 +21,49 @@ const getOutputChannel = (name: string): vscode.OutputChannel => {
2121
returnchannel
2222
}
2323

24-
interfaceProps{
24+
interfaceCallbacks{
2525
onSuccess():void
2626
onFail():void
2727
onRun():void
2828
onError():void
2929
}
3030

31-
asyncfunctionrunTest({onSuccess, onFail, onRun, onError}:Props):Promise<void>{
32-
console.log('------------------- run test ------------------')
33-
// increment process id
34-
constprocessId=++currentId
31+
interfaceTestRunnerConfig{
32+
command:string
33+
parser(output:string):boolean
34+
}
35+
36+
exportconstcreateTestRunner=(config:TestRunnerConfig,callbacks:Callbacks)=>{
37+
38+
constoutputChannelName='TEST_OUTPUT'
39+
40+
return{
41+
run(){
42+
console.log('------------------- run test ------------------')
43+
constprocessId=++currentId
44+
callbacks.onRun()
45+
46+
try{
47+
const{stdout}=awaitnode.exec(config.command)
48+
}
49+
}
50+
}
51+
}
52+
53+
asyncfunctionrunTest({onSuccess, onFail, onRun, onError}:Callbacks):Promise<void>{
54+
3555

36-
onRun()
3756

38-
constoutputChannelName='Test Output'
3957

4058
// TODO: verify test runner for args
4159
// jest CLI docs https://jestjs.io/docs/en/cli
42-
consttestArgs=[
43-
'--json',
44-
'--onlyChanged',
45-
'--env=node',
46-
'--maxConcurrency=4',
47-
'--maxWorkers=4'
48-
]
60+
//const testArgs = [
61+
//'--json',
62+
//'--onlyChanged',
63+
//'--env=node',
64+
//'--maxConcurrency=4',
65+
//'--maxWorkers=4'
66+
//]
4967

5068
constcommandLine=`npm test --${testArgs.join(' ')}`
5169

@@ -61,23 +79,22 @@ async function runTest({onSuccess, onFail, onRun, onError}: Props): Promise<void
6179
if(stdout){
6280
constlines=stdout.split(/\r{0,1}\n/)
6381
for(constlineoflines){
64-
if(line.length===0){
65-
continue
66-
}
67-
68-
constregExp=/^{\"numFailedTestSuites/
69-
constmatches=regExp.exec(line)
70-
if(matches&&matches.length){
71-
constresult=JSON.parse(line)
72-
73-
if(result.success){
74-
if(shouldExitEarly(processId)){
75-
// exit early
76-
return
82+
if(line.length>0){
83+
constregExp=/^{\"numFailedTestSuites/
84+
constmatches=regExp.exec(line)
85+
if(matches&&matches.length){
86+
constresult=JSON.parse(line)
87+
88+
if(result.success){
89+
if(shouldExitEarly(processId)){
90+
// exit early
91+
return
92+
}
93+
console.log('success!')
94+
onSuccess()
95+
}else{
96+
console.log('NOT SUCCESS?')
7797
}
78-
onSuccess()
79-
}else{
80-
console.log('NOT SUCCESS?')
8198
}
8299
}
83100
}
@@ -104,25 +121,23 @@ async function runTest({onSuccess, onFail, onRun, onError}: Props): Promise<void
104121
constlines=stdout.split(/\r{0,1}\n/)
105122

106123
for(constlineoflines){
107-
if(line.length===0){
108-
continue
109-
}
110-
111-
constdataRegExp=/^{\"numFailedTestSuites"/
112-
constmatches=dataRegExp.exec(line)
113-
114-
if(matches&&matches.length){
115-
constresult=JSON.parse(line)
116-
constfirstError=result.testResults.find((t:any)=>t.status==='failed')
117-
118-
if(firstError){
119-
if(shouldExitEarly(processId)){
120-
// exit early
121-
return
124+
if(line.length>0){
125+
constdataRegExp=/^{\"numFailedTestSuites"/
126+
constmatches=dataRegExp.exec(line)
127+
128+
if(matches&&matches.length){
129+
constresult=JSON.parse(line)
130+
constfirstError=result.testResults.find((t:any)=>t.status==='failed')
131+
132+
if(firstError){
133+
if(shouldExitEarly(processId)){
134+
// exit early
135+
return
136+
}
137+
onFail()
138+
}else{
139+
console.error('NOTE: PARSER DID NOT WORK FOR ',line)
122140
}
123-
onFail()
124-
}else{
125-
console.error('NOTE: PARSER DID NOT WORK FOR ',line)
126141
}
127142
}
128143
}

‎src/actions/setupActions.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,50 +55,51 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.St
5555
}
5656

5757
// run file watchers (listeners)
58-
// if (listeners) {
59-
// console.log('listeners')
60-
// for (const listener of listeners) {
61-
// if (!watchers[listener]) {
62-
// const pattern = new vscode.RelativePattern(
63-
// vscode.workspace.getWorkspaceFolder(workspaceRoot.uri)!,
64-
// listener
65-
// )
66-
// console.log(pattern)
67-
// watchers[listener] = vscode.workspace.createFileSystemWatcher(
68-
// pattern
69-
// )
70-
// watchers[listener].onDidChange(() => {
71-
// console.log('onDidChange')
72-
// // trigger save
73-
// vscode.commands.executeCommand('coderoad.run_test', null, () => {
74-
// // cleanup watcher on success
75-
// disposeWatcher(listener)
76-
// })
77-
// })
78-
// watchers[listener].onDidCreate(() => {
79-
// console.log('onDidCreate')
80-
// // trigger save
81-
// vscode.commands.executeCommand('coderoad.run_test', null, () => {
82-
// // cleanup watcher on success
83-
// disposeWatcher(listener)
84-
// })
85-
// })
86-
// watchers[listener].onDidDelete(() => {
87-
// console.log('onDidDelete')
88-
// // trigger save
89-
// vscode.commands.executeCommand('coderoad.run_test', null, () => {
90-
// // cleanup watcher on success
91-
// disposeWatcher(listener)
92-
// })
93-
// })
94-
// }
95-
// }
96-
// } else {
97-
// // remove all watchers
98-
// for (const listener of Object.keys(watchers)) {
99-
// disposeWatcher(listener)
100-
// }
101-
// }
58+
if(listeners){
59+
console.log('listeners')
60+
for(constlisteneroflisteners){
61+
if(!watchers[listener]){
62+
constpattern=newvscode.RelativePattern(
63+
vscode.workspace.getWorkspaceFolder(workspaceRoot.uri)!,
64+
listener
65+
)
66+
console.log(pattern)
67+
constlisten=vscode.workspace.createFileSystemWatcher(
68+
pattern
69+
)
70+
watchers[listener]=listen
71+
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')
89+
// trigger save
90+
vscode.commands.executeCommand('coderoad.run_test',null,()=>{
91+
// cleanup watcher on success
92+
disposeWatcher(listener)
93+
})
94+
})
95+
}
96+
}
97+
}else{
98+
// remove all watchers
99+
for(constlistenerofObject.keys(watchers)){
100+
disposeWatcher(listener)
101+
}
102+
}
102103

103104
// run command
104105
if(commands){

‎typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface MachineStateSchema {
7474
TestRunning:{}
7575
TestPass:{}
7676
TestFail:{}
77+
TestError:{}
7778
StepNext:{}
7879
LevelComplete:{}
7980
}

‎web-app/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

‎web-app/src/services/state/machine.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
134134
actions:['updateStepProgress']
135135
},
136136
TEST_FAIL:'TestFail',
137-
TEST_ERROR:'Normal'
137+
TEST_ERROR:'TestError'
138138
},
139139
},
140+
TestError:{
141+
onEntry:['testFail'],
142+
after:{
143+
0:'Normal'
144+
}
145+
},
140146
TestPass:{
141147
onExit:['updateStepPosition'],
142148
after:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp