Skip to content

Feature/run save configs #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/actions/tutorialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as TT from 'typings/tutorial'
import * as vscode from 'vscode'
import { COMMANDS } from '../editor/commands'
import * as git from '../services/git'
import { DISABLE_RUN_ON_SAVE } from '../environment'

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

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

// verify if file test should run based on document saved
const shouldRunTest = (document: vscode.TextDocument): boolean => {
// must be a file
if (document.uri.scheme !== 'file') {
return false
if (!DISABLE_RUN_ON_SAVE) {
// verify if file test should run based on document saved
const shouldRunTest = (document: vscode.TextDocument): boolean => {
// must be a file
if (document.uri.scheme !== 'file') {
return false
}
return true
}
return true
}

// setup onSave hook
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
if (shouldRunTest(document)) {
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
}
})
// setup onSave hook
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
if (shouldRunTest(document)) {
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
}
})
}
}

export default tutorialConfig
5 changes: 4 additions & 1 deletion src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,17 @@ class Channel implements Channel {
// run test following solution to update position
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
return

case 'EDITOR_SYNC_PROGRESS':
// update progress when a level is deemed complete in the client
await this.context.progress.syncProgress(action.payload.progress)
return
case 'EDITOR_OPEN_LOGS':
const channel = action.payload.channel
await showOutput(channel)
return
case 'EDITOR_RUN_TEST':
vscode.commands.executeCommand(COMMANDS.RUN_TEST)
return
default:
logger(`No match for action type: ${actionType}`)
return
Expand Down
2 changes: 2 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ if (!supportedOS.includes(OS_PLATFORM)) {
}

export const TUTORIAL_URL: string | null = process.env.CODEROAD_TUTORIAL_URL || null

export const DISABLE_RUN_ON_SAVE = (process.env.CODEROAD_DISABLE_RUN_ON_SAVE || '').toLowerCase() === 'true'
17 changes: 13 additions & 4 deletions web-app/src/containers/Tutorial/components/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Markdown from '../../../components/Markdown'
import ProcessMessages from '../../../components/ProcessMessages'
import NuxTutorial from '../../../components/NewUserExperience/NuxTutorial'
import Step from './Step'
import { DISPLAY_RUN_TEST_BUTTON } from '../../../environment'

const styles = {
page: {
Expand Down Expand Up @@ -95,6 +96,7 @@ interface Props {
processes: T.ProcessEvent[]
testStatus: T.TestStatus | null
onContinue(): void
onRunTest(): void
onLoadSolution(): void
onOpenLogs(channel: string): void
}
Expand All @@ -107,6 +109,7 @@ const Level = ({
index,
status,
onContinue,
onRunTest,
onLoadSolution,
onOpenLogs,
processes,
Expand Down Expand Up @@ -181,10 +184,16 @@ const Level = ({
</div>

<div css={styles.footer}>
<span>
{typeof index === 'number' ? `${index + 1}. ` : ''}
{title}
</span>
{DISPLAY_RUN_TEST_BUTTON && status !== 'COMPLETE' ? (
<Button type="primary" onClick={onRunTest} disabled={processes.length > 0}>
Run
</Button>
) : (
<span>
{typeof index === 'number' ? `${index + 1}. ` : ''}
{title}
</span>
)}
<span>
{status === 'COMPLETE' || !steps.length ? (
<Button type="primary" onClick={onContinue}>
Expand Down
5 changes: 5 additions & 0 deletions web-app/src/containers/Tutorial/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const TutorialPage = (props: PageProps) => {
props.send({ type: 'STEP_SOLUTION_LOAD' })
}

const onRunTest = (): void => {
props.send({ type: 'RUN_TEST' })
}

const onOpenLogs = (channel: string): void => {
props.send({ type: 'OPEN_LOGS', payload: { channel } })
}
Expand Down Expand Up @@ -64,6 +68,7 @@ const TutorialPage = (props: PageProps) => {
steps={steps}
status={progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE'}
onContinue={onContinue}
onRunTest={onRunTest}
onLoadSolution={onLoadSolution}
onOpenLogs={onOpenLogs}
processes={processes}
Expand Down
3 changes: 3 additions & 0 deletions web-app/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ export const NODE_ENV: string = process.env.NODE_ENV || 'development'
export const LOG: boolean = (process.env.REACT_APP_LOG || '').toLowerCase() === 'true'
export const TUTORIAL_LIST_URL: string = process.env.REACT_APP_TUTORIAL_LIST_URL || ''
export const SENTRY_DSN: string | null = process.env.REACT_APP_SENTRY_DSN || null

// config variables
export const DISPLAY_RUN_TEST_BUTTON = (process.env.CODEROAD_DISPLAY_RUN_TEST_BUTTON || '').toLowerCase() === 'true'
6 changes: 6 additions & 0 deletions web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,10 @@ export default (editorSend: any) => ({
payload: { channel: event.payload.channel },
})
},
runTest(context: T.MachineContext) {
editorSend({
type: 'EDITOR_RUN_TEST',
payload: { position: context.position },
})
},
})
3 changes: 3 additions & 0 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ export const createMachine = (options: any) => {
OPEN_LOGS: {
actions: ['editorOpenLogs'],
},
RUN_TEST: {
actions: ['runTest'],
},
},
},
TestRunning: {
Expand Down