Skip to content

Commit 50a3b76

Browse files
authored
Merge pull request #326 from coderoad/feature/run-save-configs
Feature/run save configs
2 parents a33089a + f53a941 commit 50a3b76

File tree

8 files changed

+52
-18
lines changed

8 files changed

+52
-18
lines changed

Diff for: src/actions/tutorialConfig.ts

+16-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as TT from 'typings/tutorial'
33
import * as vscode from 'vscode'
44
import { COMMANDS } from '../editor/commands'
55
import * as git from '../services/git'
6+
import { DISABLE_RUN_ON_SAVE } from '../environment'
67

78
interface TutorialConfigParams {
89
config: TT.TutorialConfig
@@ -53,21 +54,23 @@ const tutorialConfig = async ({ config, alreadyConfigured }: TutorialConfigParam
5354

5455
await vscode.commands.executeCommand(COMMANDS.CONFIG_TEST_RUNNER, config.testRunner)
5556

56-
// verify if file test should run based on document saved
57-
const shouldRunTest = (document: vscode.TextDocument): boolean => {
58-
// must be a file
59-
if (document.uri.scheme !== 'file') {
60-
return false
57+
if (!DISABLE_RUN_ON_SAVE) {
58+
// verify if file test should run based on document saved
59+
const shouldRunTest = (document: vscode.TextDocument): boolean => {
60+
// must be a file
61+
if (document.uri.scheme !== 'file') {
62+
return false
63+
}
64+
return true
6165
}
62-
return true
63-
}
6466

65-
// setup onSave hook
66-
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
67-
if (shouldRunTest(document)) {
68-
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
69-
}
70-
})
67+
// setup onSave hook
68+
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
69+
if (shouldRunTest(document)) {
70+
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
71+
}
72+
})
73+
}
7174
}
7275

7376
export default tutorialConfig

Diff for: src/channel/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,17 @@ class Channel implements Channel {
309309
// run test following solution to update position
310310
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
311311
return
312-
313312
case 'EDITOR_SYNC_PROGRESS':
314313
// update progress when a level is deemed complete in the client
315314
await this.context.progress.syncProgress(action.payload.progress)
316315
return
317316
case 'EDITOR_OPEN_LOGS':
318317
const channel = action.payload.channel
319318
await showOutput(channel)
319+
return
320+
case 'EDITOR_RUN_TEST':
321+
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
322+
return
320323
default:
321324
logger(`No match for action type: ${actionType}`)
322325
return

Diff for: src/environment.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ if (!supportedOS.includes(OS_PLATFORM)) {
3535
}
3636

3737
export const TUTORIAL_URL: string | null = process.env.CODEROAD_TUTORIAL_URL || null
38+
39+
export const DISABLE_RUN_ON_SAVE = (process.env.CODEROAD_DISABLE_RUN_ON_SAVE || '').toLowerCase() === 'true'

Diff for: web-app/src/containers/Tutorial/components/Level.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Markdown from '../../../components/Markdown'
99
import ProcessMessages from '../../../components/ProcessMessages'
1010
import NuxTutorial from '../../../components/NewUserExperience/NuxTutorial'
1111
import Step from './Step'
12+
import { DISPLAY_RUN_TEST_BUTTON } from '../../../environment'
1213

1314
const styles = {
1415
page: {
@@ -95,6 +96,7 @@ interface Props {
9596
processes: T.ProcessEvent[]
9697
testStatus: T.TestStatus | null
9798
onContinue(): void
99+
onRunTest(): void
98100
onLoadSolution(): void
99101
onOpenLogs(channel: string): void
100102
}
@@ -107,6 +109,7 @@ const Level = ({
107109
index,
108110
status,
109111
onContinue,
112+
onRunTest,
110113
onLoadSolution,
111114
onOpenLogs,
112115
processes,
@@ -181,10 +184,16 @@ const Level = ({
181184
</div>
182185

183186
<div css={styles.footer}>
184-
<span>
185-
{typeof index === 'number' ? `${index + 1}. ` : ''}
186-
{title}
187-
</span>
187+
{DISPLAY_RUN_TEST_BUTTON && status !== 'COMPLETE' ? (
188+
<Button type="primary" onClick={onRunTest} disabled={processes.length > 0}>
189+
Run
190+
</Button>
191+
) : (
192+
<span>
193+
{typeof index === 'number' ? `${index + 1}. ` : ''}
194+
{title}
195+
</span>
196+
)}
188197
<span>
189198
{status === 'COMPLETE' || !steps.length ? (
190199
<Button type="primary" onClick={onContinue}>

Diff for: web-app/src/containers/Tutorial/index.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const TutorialPage = (props: PageProps) => {
3232
props.send({ type: 'STEP_SOLUTION_LOAD' })
3333
}
3434

35+
const onRunTest = (): void => {
36+
props.send({ type: 'RUN_TEST' })
37+
}
38+
3539
const onOpenLogs = (channel: string): void => {
3640
props.send({ type: 'OPEN_LOGS', payload: { channel } })
3741
}
@@ -64,6 +68,7 @@ const TutorialPage = (props: PageProps) => {
6468
steps={steps}
6569
status={progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE'}
6670
onContinue={onContinue}
71+
onRunTest={onRunTest}
6772
onLoadSolution={onLoadSolution}
6873
onOpenLogs={onOpenLogs}
6974
processes={processes}

Diff for: web-app/src/environment.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ export const NODE_ENV: string = process.env.NODE_ENV || 'development'
1212
export const LOG: boolean = (process.env.REACT_APP_LOG || '').toLowerCase() === 'true'
1313
export const TUTORIAL_LIST_URL: string = process.env.REACT_APP_TUTORIAL_LIST_URL || ''
1414
export const SENTRY_DSN: string | null = process.env.REACT_APP_SENTRY_DSN || null
15+
16+
// config variables
17+
export const DISPLAY_RUN_TEST_BUTTON = (process.env.CODEROAD_DISPLAY_RUN_TEST_BUTTON || '').toLowerCase() === 'true'

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

+6
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ export default (editorSend: any) => ({
101101
payload: { channel: event.payload.channel },
102102
})
103103
},
104+
runTest(context: T.MachineContext) {
105+
editorSend({
106+
type: 'EDITOR_RUN_TEST',
107+
payload: { position: context.position },
108+
})
109+
},
104110
})

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

+3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export const createMachine = (options: any) => {
177177
OPEN_LOGS: {
178178
actions: ['editorOpenLogs'],
179179
},
180+
RUN_TEST: {
181+
actions: ['runTest'],
182+
},
180183
},
181184
},
182185
TestRunning: {

0 commit comments

Comments
 (0)