8000 configure test failure message · crabbedbushel/coderoad-vscode@95f9621 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95f9621

Browse files
committed
configure test failure message
1 parent 59f27f6 commit 95f9621

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

src/editor/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const createCommands = ({extensionPath, workspaceState, workspaceRoot}: C
5959
vscode.window.showInformationMessage('PASS')
6060
webview.send({type: 'TEST_PASS', payload})
6161
},
62-
onFail: (payload: Payload) => {
62+
onFail: (payload: Payload, message: string) => {
6363
// send test fail message back to client
64-
vscode.window.showWarningMessage('FAIL')
64+
vscode.window.showWarningMessage(`FAIL: ${message}`)
6565
webview.send({type: 'TEST_FAIL', payload})
6666
},
6767
onError: (payload: Payload) => {

src/services/testRunner/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Payload {
99

1010
interface Callbacks {
1111
onSuccess(payload: Payload): void
12-
onFail(payload: Payload): void
12+
onFail(payload: Payload, message: string): void
1313
onRun(payload: Payload): void
1414
onError(payload: Payload): void
1515
}
@@ -55,12 +55,16 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
5555
callbacks.onSuccess(payload)
5656
if (onSuccess) {onSuccess()}
5757
} else {
58-
// TODO: parse failure message
58+
59+
// TODO: consider logging output to channel
5960
// open terminal with failed test string
6061
// const channel = getOutputChannel(outputChannelName)
6162
// channel.show(false)
62-
// channel.appendLine(testsFailed.message)
63-
callbacks.onFail(payload)
63+
// channel.appendLine(tap.message)
64+
65+
66+
const message = tap.message ? tap.message : ''
67+
callbacks.onFail(payload, message)
6468
}
6569
}
6670
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import parser from './parser'
2+
3+
4+
5+
describe('parser', () => {
6+
test('should detect success', () => {
7+
const example = `
8+
1..2
9+
ok 1 - Should pass
10+
ok 2 - Should also pass
11+
`
12+
expect(parser(example)).toEqual({ok: true})
13+
})
14+
test('should detect failure', () => {
15+
const example = `
16+
1..3
17+
ok 1 - Should pass
18+
not ok 2 - This one fails
19+
ok 3 - Also passes
20+
`
21+
expect(parser(example).ok).toBe(false)
22+
})
23+
test('should return failure message', () => {
24+
const example = `
25+
1..4
26+
ok 1 - Should pass
27+
not ok 2 - First to fail
28+
ok 3 - Also passes
29+
not ok 4 - Second to fail
30+
`
31+
expect(parser(example).message).toBe('First to fail')
32+
})
33+
})

src/services/testRunner/parser.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
interface ParserOutput {
22
ok: boolean
3+
message?: string
34
}
45

56
const parser = (text: string): ParserOutput => {
67
const lines = text.split('\n')
78
for (const line of lines) {
8-
if (line.match(/^not ok /)) {
9-
return {ok: false}
9+
// parse failed test
10+
const match = line.match(/^not ok \d+ - (.+)+/)
11+
if (!!match) {
12+
return {ok: false, message: match[1]}
1013
}
1114
}
1215
return {ok: true}

0 commit comments

Comments
 (0)
0