Skip to content

Commit e8d10b8

Browse files
authored
Merge pull request coderoad#311 from coderoad/feature/test-failure
Feature/test failure
2 parents 7fdc351 + 623c737 commit e8d10b8

File tree

20 files changed

+93
-36
lines changed

20 files changed

+93
-36
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ Resulting in a folder structure like the following:
101101
- Continue an incomplete tutorial started in the same workspace. Choose the "continue" path from the start screen. Progress is stored in local storage in the workspace.
102102

103103
![continue tutorial](./docs/images/continue-tutorial.png)
104+
105+
## [0.5.0]
106+
107+
- Show error messages in the webview UI
108+
109+
![fail message in webview](./docs/images/fail-message-in-webview.png)
96.9 KB
Loading

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/editor/commands.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as TT from 'typings/tutorial'
33
import * as vscode from 'vscode'
44
import createTestRunner from '../services/testRunner'
55
import { setupActions } from '../actions/setupActions'
6-
import createWebView from '../webview'
6+
import createWebView from '../services/webview'
77
import logger from '../services/logger'
88

99
export const COMMANDS = {
@@ -62,9 +62,9 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
6262
// send test pass message back to client
6363
webview.send({ type: 'TEST_PASS', payload: { position } })
6464
},
65-
onFail: (position: T.Position, message: string) => {
65+
onFail: (position: T.Position, failSummary: T.TestFail): void => {
6666
// send test fail message back to client with failure message
67-
webview.send({ type: 'TEST_FAIL', payload: { position, message } })
67+
webview.send({ type: 'TEST_FAIL', payload: { position, fail: failSummary } })
6868
},
6969
onError: (position: T.Position) => {
7070
// TODO: send test error message back to client

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/formatOutput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ParserOutput, Fail } from './parser'
44
// export const formatSuccessOutput = (tap: ParserOutput): string => {}
55

66
export const formatFailOutput = (tap: ParserOutput): string => {
7-
let output = `FAILED TESTS\n`
7+
let output = `FAILED TEST LOG\n`
88
tap.failed.forEach((fail: Fail) => {
99
const details = fail.details ? `\n${fail.details}\n` : ''
1010
const logs = fail.logs ? `\n${fail.logs.join('\n')}\n` : ''

src/services/testRunner/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ 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 {
1212
onSuccess(position: T.Position): void
13-
onFail(position: T.Position, message: string): void
13+
onFail(position: T.Position, failSummary: T.TestFail): void
1414
onRun(position: T.Position): void
1515
onError(position: T.Position): void
1616
}
@@ -51,20 +51,24 @@ 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
5858
if (stdout && stdout.length && !tap.ok) {
59-
const firstFailMessage = tap.failed[0].message
60-
callbacks.onFail(position, firstFailMessage)
59+
const firstFail = tap.failed[0]
60+
const failSummary = {
61+
title: firstFail.message || 'Test Failed',
62+
description: firstFail.details || 'Unknown error',
63+
}
64+
callbacks.onFail(position, failSummary)
6165
const output = formatFailOutput(tap)
62-
displayOutput({ channel: failChannelName, text: output, show: true })
66+
addOutput({ channel: failChannelName, text: output, show: true })
6367
return
6468
} else {
6569
callbacks.onError(position)
6670
// open terminal with error string
67-
displayOutput({ channel: failChannelName, text: stderr, show: true })
71+
addOutput({ channel: failChannelName, text: stderr, show: true })
6872
return
6973
}
7074
}

src/services/testRunner/output.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ 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()
21-
channel.show(params.show || false)
2221
channel.append(params.text)
2322
}
2423

24+
export const showOutput = (channelName: string) => {
25+
const channel = getOutputChannel(channelName)
26+
channel.show()
27+
}
28+
2529
export const clearOutput = (channelName: string) => {
2630
const channel = getOutputChannel(channelName)
27-
channel.show(false)
2831
channel.clear()
2932
channel.hide()
3033
}

src/webview/index.ts renamed to src/services/webview/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path'
22
import { Action } from 'typings'
33
import * as vscode from 'vscode'
4-
import Channel from '../channel'
4+
import Channel from '../../channel'
55
import render from './render'
66

77
interface ReactWebViewProps {

src/webview/render.ts renamed to src/services/webview/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JSDOM } from 'jsdom'
22
import * as path from 'path'
33
import * as vscode from 'vscode'
4-
import onError from '../services/sentry/onError'
4+
import onError from '../sentry/onError'
55

66
const getNonce = (): string => {
77
let text = ''

0 commit comments

Comments
 (0)