Skip to content

Commit 623c737

Browse files
committed
open logs from error message
Signed-off-by: shmck <[email protected]>
1 parent b6b750f commit 623c737

File tree

13 files changed

+65
-52
lines changed

13 files changed

+65
-52
lines changed

src/channel/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
1414
import { readFile } from 'fs'
1515
import { join } from 'path'
1616
import { promisify } from 'util'
17+
import { showOutput } from '../services/testRunner/output'
1718
import { WORKSPACE_ROOT } from '../environment'
1819

1920
const readFileAsync = promisify(readFile)
@@ -300,7 +301,9 @@ class Channel implements Channel {
300301
// update progress when a level is deemed complete in the client
301302
await this.context.progress.syncProgress(action.payload.progress)
302303
return
303-
304+
case 'EDITOR_OPEN_LOGS':
305+
const channel = action.payload.channel
306+
await showOutput(channel)
304307
default:
305308
logger(`No match for action type: ${actionType}`)
306309
return

src/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type Env = 'test' | 'local' | 'development' | 'production'
1010
export const NODE_ENV: Env = process.env.NODE_ENV || 'production'
1111

1212
// toggle logging in development
13-
export const LOG = false
13+
export const LOG = true
1414

1515
// error logging tool
1616
export const SENTRY_DSN: string | null = null

src/services/testRunner/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import logger from '../logger'
55
import parser from './parser'
66
import { debounce, throttle } from './throttle'
77
import onError from '../sentry/onError'
8-
import { clearOutput, displayOutput } from './output'
8+
import { clearOutput, addOutput } from './output'
99
import { formatFailOutput } from './formatOutput'
1010

1111
interface Callbacks {
@@ -51,7 +51,7 @@ const createTestRunner = (config: TT.TutorialTestRunnerConfig, callbacks: Callba
5151

5252
const tap = parser(stdout || '')
5353

54-
displayOutput({ channel: logChannelName, text: tap.logs.join('\n'), show: false })
54+
addOutput({ channel: logChannelName, text: tap.logs.join('\n'), show: false })
5555

5656
if (stderr) {
5757
// FAIL also trigger stderr
@@ -63,12 +63,12 @@ const createTestRunner = (config: TT.TutorialTestRunnerConfig, callbacks: Callba
6363
}
6464
callbacks.onFail(position, failSummary)
6565
const output = formatFailOutput(tap)
66-
displayOutput({ channel: failChannelName, text: output, show: true })
66+
addOutput({ channel: failChannelName, text: output, show: true })
6767
return
6868
} else {
6969
callbacks.onError(position)
7070
// open terminal with error string
71-
displayOutput({ channel: failChannelName, text: stderr, show: true })
71+
addOutput({ channel: failChannelName, text: stderr, show: true })
7272
return
7373
}
7474
}

src/services/testRunner/output.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ const getOutputChannel = (name: string): vscode.OutputChannel => {
99
return channels[name]
1010
}
1111

12-
interface DisplayOutput {
12+
interface ChannelOutput {
1313
channel: string
1414
text: string
1515
show?: boolean
1616
}
1717

18-
export const displayOutput = (params: DisplayOutput) => {
18+
export const addOutput = (params: ChannelOutput) => {
1919
const channel = getOutputChannel(params.channel)
2020
channel.clear()
2121
channel.append(params.text)
2222
}
2323

24+
export const showOutput = (channelName: string) => {
25+
const channel = getOutputChannel(channelName)
26+
channel.show()
27+
}
28+
2429
export const clearOutput = (channelName: string) => {
2530
const channel = getOutputChannel(channelName)
2631
channel.clear()

web-app/src/components/Message/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props {
1111
closeable?: boolean
1212
onClose?: () => void
1313
handleClose?: () => void
14+
children?: React.ReactElement | null
1415
}
1516

1617
const Message = (props: Props) => {
@@ -30,7 +31,10 @@ const Message = (props: Props) => {
3031
onClose={onClose}
3132
shape={props.shape}
3233
>
33-
{props.content}
34+
<div>
35+
<div>{props.content}</div>
36+
<div>{props.children}</div>
37+
</div>
3438
</AlifdMessage>
3539
)
3640
}

web-app/src/components/ProcessMessages/TestMessage.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const useTimeout = ({ duration, key }: { duration: number; key: string }) => {
2424
return timeoutClose
2525
}
2626

27-
const TestMessage = (props: T.TestStatus) => {
27+
const TestMessage = (props: T.TestStatus & { children?: React.ReactElement | null }) => {
2828
const duration = durations[props.type]
2929
const timeoutClose = useTimeout({ duration, key: props.title })
3030
return (
@@ -36,7 +36,9 @@ const TestMessage = (props: T.TestStatus) => {
3636
size="medium"
3737
closeable={props.type !== 'loading'}
3838
content={props.content}
39-
/>
39+
>
40+
{props.children}
41+
</Message>
4042
)
4143
}
4244

web-app/src/components/ProcessMessages/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Message from '../Message'
22
import * as React from 'react'
33
import * as T from 'typings'
4+
import Button from '../Button'
45
import { css, jsx } from '@emotion/core'
56
import TestMessage from './TestMessage'
67

78
interface Props {
89
testStatus?: T.TestStatus | null
910
processes: T.ProcessEvent[]
11+
onOpenLogs?: (channel: string) => void
1012
}
1113

1214
const styles = {
@@ -17,9 +19,21 @@ const styles = {
1719
}
1820

1921
// display a list of active processes
20-
const ProcessMessages = ({ processes, testStatus }: Props) => {
22+
const ProcessMessages = ({ processes, testStatus, onOpenLogs }: Props) => {
2123
if (testStatus) {
22-
return <TestMessage {...testStatus} />
24+
return (
25+
<TestMessage {...testStatus}>
26+
{testStatus.type === 'warning' ? (
27+
<Button
28+
onClick={() => onOpenLogs && onOpenLogs('CodeRoad (Tests)')}
29+
type="normal"
30+
style={{ marginTop: '0.8rem' }}
31+
>
32+
Open Logs
33+
</Button>
34+
) : null}
35+
</TestMessage>
36+
)
2337
}
2438
if (!processes.length) {
2539
return null

web-app/src/components/TestFail/index.tsx

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

web-app/src/containers/Tutorial/components/Level.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ interface Props {
9696
testStatus: T.TestStatus | null
9797
onContinue(): void
9898
onLoadSolution(): void
99+
onOpenLogs(channel: string): void
99100
}
100101

101102
const Level = ({
@@ -107,6 +108,7 @@ const Level = ({
107108
status,
108109
onContinue,
109110
onLoadSolution,
111+
onOpenLogs,
110112
processes,
111113
testStatus,
112114
}: Props) => {
@@ -170,7 +172,7 @@ const Level = ({
170172

171173
{(testStatus || processes.length > 0) && (
172174
<div css={styles.processes}>
173-
<ProcessMessages processes={processes} testStatus={testStatus} />
175+
<ProcessMessages processes={processes} testStatus={testStatus} onOpenLogs={onOpenLogs} />
174176
</div>
175177
)}
176178

web-app/src/containers/Tutorial/index.tsx

Lines changed: 5 additions & 0 deletions
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 onOpenLogs = (channel: string): void => {
36+
props.send({ type: 'OPEN_LOGS', payload: { channel } })
37+
}
38+
3539
const steps = levelData.steps.map((step: TT.Step) => {
3640
// label step status for step component
3741
let status: T.ProgressStatus = 'INCOMPLETE'
@@ -61,6 +65,7 @@ const TutorialPage = (props: PageProps) => {
6165
status={progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE'}
6266
onContinue={onContinue}
6367
onLoadSolution={onLoadSolution}
68+
onOpenLogs={onOpenLogs}
6469
processes={processes}
6570
testStatus={testStatus}
6671
/>

0 commit comments

Comments
 (0)