Skip to content

Commit e5f140f

Browse files
committed
cleanup test tracking
Signed-off-by: shmck <[email protected]>
1 parent 7a56f9e commit e5f140f

File tree

9 files changed

+83
-57
lines changed

9 files changed

+83
-57
lines changed

Diff for: src/actions/setupActions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ interface SetupActions {
1414
}
1515

1616
export const setupActions = async ({ actions, send, path }: SetupActions): Promise<void> => {
17+
if (!actions) {
18+
return
19+
}
1720
const { commands, commits, files, watchers } = actions
1821

1922
// validate commit is new

Diff for: src/actions/utils/loadWatchers.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const loadWatchers = (watchers: string[]) => {
3737
fsWatcher.on('change', (path, event) => {
3838
const now = +new Date()
3939
if (!lastFire || lastFire - now > 1000) {
40-
vscode.commands.executeCommand(COMMANDS.RUN_TEST, null, () => {
41-
// cleanup watcher on success
42-
disposeWatcher(watcher)
40+
vscode.commands.executeCommand(COMMANDS.RUN_TEST, {
41+
onSuccess: () => {
42+
// cleanup watcher on success
43+
disposeWatcher(watcher)
44+
},
4345
})
4446
}
4547
})

Diff for: src/channel/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Channel implements Channel {
224224
alreadyConfigured: true,
225225
})
226226
// update the current stepId on startup
227-
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
227+
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
228228
} catch (e) {
229229
const error = {
230230
type: 'UnknownError',
@@ -286,14 +286,15 @@ class Channel implements Channel {
286286
return
287287
// load step actions (git commits, commands, open files)
288288
case 'SETUP_ACTIONS':
289-
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
290-
setupActions({ actions: action.payload, send: this.send })
289+
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
290+
setupActions({ actions: action.payload.actions, send: this.send })
291291
return
292292
// load solution step actions (git commits, commands, open files)
293293
case 'SOLUTION_ACTIONS':
294-
await solutionActions({ actions: action.payload, send: this.send })
294+
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
295+
await solutionActions({ actions: action.payload.actions, send: this.send })
295296
// run test following solution to update position
296-
vscode.commands.executeCommand(COMMANDS.RUN_TEST, action.payload)
297+
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
297298
return
298299

299300
default:
@@ -328,12 +329,13 @@ class Channel implements Channel {
328329

329330
switch (actionType) {
330331
case 'TEST_PASS':
332+
console.log('TEST_PASS', action)
331333
const tutorial = this.context.tutorial.get()
332334
if (!tutorial) {
333335
throw new Error('Error with current tutorial. Tutorial may be missing an id.')
334336
}
335337
// update local storage stepProgress
336-
const progress = this.context.progress.setStepComplete(tutorial, action.payload.stepId)
338+
const progress = this.context.progress.setStepComplete(tutorial, action.payload.position.stepId)
337339
this.context.position.setPositionFromProgress(tutorial, progress)
338340
saveCommit()
339341
}

Diff for: src/editor/commands.ts

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import * as T from 'typings'
12
import * as TT from 'typings/tutorial'
23
import * as vscode from 'vscode'
3-
import createTestRunner, { Payload } from '../services/testRunner'
4+
import createTestRunner from '../services/testRunner'
45
import { setupActions } from '../actions/setupActions'
56
import createWebView from '../webview'
7+
import logger from '../services/logger'
68

79
export const COMMANDS = {
810
START: 'coderoad.start',
911
OPEN_WEBVIEW: 'coderoad.open_webview',
1012
CONFIG_TEST_RUNNER: 'coderoad.config_test_runner',
1113
RUN_TEST: 'coderoad.run_test',
12-
SET_CURRENT_STEP: 'coderoad.set_current_step',
14+
SET_CURRENT_POSITION: 'coderoad.set_current_position',
1315
}
1416

1517
interface CreateCommandProps {
@@ -20,7 +22,7 @@ interface CreateCommandProps {
2022
export const createCommands = ({ extensionPath, workspaceState }: CreateCommandProps) => {
2123
// React panel webview
2224
let webview: any
23-
let currentStepId: string | null = ''
25+
let currentPosition: T.Position
2426
let testRunner: any
2527

2628
return {
@@ -55,32 +57,38 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
5557
await setupActions({ actions: config.actions, send: webview.send, path: config.path })
5658
}
5759
testRunner = createTestRunner(config, {
58-
onSuccess: (payload: Payload) => {
60+
onSuccess: (position: T.Position) => {
61+
logger('test pass position', position)
5962
// send test pass message back to client
60-
webview.send({ type: 'TEST_PASS', payload })
63+
webview.send({ type: 'TEST_PASS', payload: { position } })
6164
},
62-
onFail: (payload: Payload, message: string) => {
65+
onFail: (position: T.Position, message: string) => {
6366
// send test fail message back to client with failure message
64-
webview.send({ type: 'TEST_FAIL', payload: { ...payload, message } })
67+
webview.send({ type: 'TEST_FAIL', payload: { position, message } })
6568
},
66-
onError: (payload: Payload) => {
67-
// send test error message back to client
68-
webview.send({ type: 'TEST_ERROR', payload })
69+
onError: (position: T.Position) => {
70+
// TODO: send test error message back to client
71+
const message = 'Error with test runner'
72+
webview.send({ type: 'TEST_ERROR', payload: { position, message } })
6973
},
70-
onRun: (payload: Payload) => {
74+
onRun: (position: T.Position) => {
7175
// send test run message back to client
72-
webview.send({ type: 'TEST_RUNNING', payload })
76+
webview.send({ type: 'TEST_RUNNING', payload: { position } })
7377
},
7478
})
7579
},
76-
[COMMANDS.SET_CURRENT_STEP]: ({ stepId }: Payload) => {
80+
[COMMANDS.SET_CURRENT_POSITION]: (position: T.Position) => {
7781
// set from last setup stepAction
78-
currentStepId = stepId
82+
currentPosition = position
7983
},
80-
[COMMANDS.RUN_TEST]: (current: Payload | undefined, onSuccess: () => void) => {
84+
[COMMANDS.RUN_TEST]: (callback?: { onSuccess: () => void }) => {
85+
logger('run test current', currentPosition)
8186
// use stepId from client, or last set stepId
82-
const payload: Payload = { stepId: current && current.stepId?.length ? current.stepId : currentStepId }
83-
testRunner(payload, onSuccess)
87+
// const position: T.Position = {
88+
// ...current,
89+
// stepId: current && current.position.stepId?.length ? current.position.stepId : currentPosition.stepId,
90+
// }
91+
testRunner(currentPosition, callback?.onSuccess)
8492
},
8593
}
8694
}

Diff for: src/services/logger/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LOG } from '../../environment'
22

3-
export type Log = string | object | null
3+
export type Log = string | object | null | undefined
44

55
const logger = (...messages: Log[]): void => {
66
if (!LOG) {

Diff for: src/services/testRunner/index.ts

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { TutorialTestRunnerConfig } from 'typings/tutorial'
1+
import * as T from 'typings'
2+
import * as TT from 'typings/tutorial'
23
import { exec } from '../node'
34
import logger from '../logger'
45
import parser from './parser'
@@ -7,22 +8,19 @@ import onError from '../sentry/onError'
78
import { clearOutput, displayOutput } from './output'
89
import { formatFailOutput } from './formatOutput'
910

10-
export interface Payload {
11-
stepId: string | null
12-
}
13-
1411
interface Callbacks {
15-
onSuccess(payload: Payload): void
16-
onFail(payload: Payload, message: string): void
17-
onRun(payload: Payload): void
18-
onError(payload: Payload): void
12+
onSuccess(position: T.Position): void
13+
onFail(position: T.Position, message: string): void
14+
onRun(position: T.Position): void
15+
onError(position: T.Position): void
1916
}
2017

2118
const failChannelName = 'CodeRoad (Tests)'
2219
const logChannelName = 'CodeRoad (Logs)'
2320

24-
const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks) => {
25-
return async (payload: Payload, onSuccess?: () => void): Promise<void> => {
21+
const createTestRunner = (config: TT.TutorialTestRunnerConfig, callbacks: Callbacks) => {
22+
return async (position: T.Position, onSuccess?: () => void): Promise<void> => {
23+
logger('createTestRunner', position)
2624
const startTime = throttle()
2725
// throttle time early
2826
if (!startTime) {
@@ -32,7 +30,7 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
3230
logger('------------------- RUN TEST -------------------')
3331

3432
// flag as running
35-
callbacks.onRun(payload)
33+
callbacks.onRun(position)
3634

3735
let result: { stdout: string | undefined; stderr: string | undefined }
3836
try {
@@ -59,12 +57,12 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
5957
// FAIL also trigger stderr
6058
if (stdout && stdout.length && !tap.ok) {
6159
const firstFailMessage = tap.failed[0].message
62-
callbacks.onFail(payload, firstFailMessage)
60+
callbacks.onFail(position, firstFailMessage)
6361
const output = formatFailOutput(tap)
6462
displayOutput({ channel: failChannelName, text: output, show: true })
6563
return
6664
} else {
67-
callbacks.onError(payload)
65+
callbacks.onError(position)
6866
// open terminal with error string
6967
displayOutput({ channel: failChannelName, text: stderr, show: true })
7068
return
@@ -74,14 +72,14 @@ const createTestRunner = (config: TutorialTestRunnerConfig, callbacks: Callbacks
7472
// PASS
7573
if (tap.ok) {
7674
clearOutput(failChannelName)
77-
callbacks.onSuccess(payload)
75+
callbacks.onSuccess(position)
7876
if (onSuccess) {
7977
onSuccess()
8078
}
8179
} else {
8280
// should never get here
83-
onError(new Error(`Error with running test ${JSON.stringify(payload)}`))
84-
callbacks.onError(payload)
81+
onError(new Error(`Error with running test ${JSON.stringify(position)}`))
82+
callbacks.onError(position)
8583
}
8684
}
8785
}

Diff for: src/webview/render.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ async function render(panel: vscode.WebviewPanel, rootPath: string) {
3131
const createUri = (_filePath: string): any => {
3232
const filePath = (_filePath.startsWith('vscode') ? _filePath.substr(16) : _filePath).replace('///', '\\')
3333

34+
// @ts-ignore
3435
return panel.webview.asWebviewUri(vscode.Uri.file(path.join(rootPath, filePath)))
3536
}
3637

Diff for: web-app/src/services/state/actions/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
109109
// update progress by tracking completed
110110
const currentProgress: T.Progress = context.progress
111111

112-
const { stepId } = event.payload
112+
const { stepId } = event.payload.position
113113

114114
currentProgress.steps[stepId] = true
115115

Diff for: web-app/src/services/state/actions/editor.ts

+24-12
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@ export default (editorSend: any) => ({
2222
type: 'EDITOR_TUTORIAL_CONTINUE_CONFIG',
2323
payload: {
2424
// pass position because current stepId or first stepId will be empty
25-
stepId: context.position.stepId,
25+
position: context.position,
2626
},
2727
})
2828
},
2929
loadLevel(context: CR.MachineContext): void {
3030
const level: TT.Level = selectors.currentLevel(context)
31-
if (level.setup) {
32-
// load step actions
33-
editorSend({
34-
type: 'SETUP_ACTIONS',
35-
payload: level.setup,
36-
})
37-
}
31+
const step: TT.Step | null = selectors.currentStep(context)
32+
// load step actions
33+
editorSend({
34+
type: 'SETUP_ACTIONS',
35+
payload: {
36+
position: {
37+
stepId: step?.id || null,
38+
levelId: level.id,
39+
},
40+
actions: level.setup,
41+
},
42+
})
3843
},
3944
loadStep(context: CR.MachineContext): void {
4045
const step: TT.Step | null = selectors.currentStep(context)
@@ -43,8 +48,12 @@ export default (editorSend: any) => ({
4348
editorSend({
4449
type: 'SETUP_ACTIONS',
4550
payload: {
46-
stepId: step.id,
47-
...step.setup,
51+
// set position here
52+
position: {
53+
stepId: step.id,
54+
levelId: context.position.levelId,
55+
},
56+
actions: step.setup,
4857
},
4958
})
5059
}
@@ -56,8 +65,11 @@ export default (editorSend: any) => ({
5665
editorSend({
5766
type: 'SOLUTION_ACTIONS',
5867
payload: {
59-
stepId: step.id,
60-
...step.solution,
68+
position: {
69+
stepId: step.id,
70+
levelId: context.position.levelId,
71+
},
72+
actions: step.solution,
6173
},
6274
})
6375
}

0 commit comments

Comments
 (0)