Skip to content

Commit a5f23fc

Browse files
committed
closes #116. Test output in editor
1 parent 6e08106 commit a5f23fc

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/editor/outputChannel.ts

-10
This file was deleted.

src/services/testRunner/index.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { getOutputChannel } from '../../editor/outputChannel'
21
import node from '../../services/node'
32
import logger from '../../services/logger'
43
import parser from './parser'
54
import { debounce, throttle } from './throttle'
65
import onError from '../sentry/onError'
6+
import displayOutput from './output'
77

88
export interface Payload {
99
stepId: string
@@ -21,8 +21,6 @@ interface TestRunnerConfig {
2121
}
2222

2323
const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
24-
const outputChannelName = 'TEST_OUTPUT'
25-
2624
return async (payload: Payload, onSuccess?: () => void): Promise<void> => {
2725
const startTime = throttle()
2826
// throttle time early
@@ -58,13 +56,12 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => {
5856
if (stdout && stdout.length && !tap.ok) {
5957
const message = tap.message ? tap.message : ''
6058
callbacks.onFail(payload, message)
59+
displayOutput(stdout)
6160
return
6261
} else {
6362
callbacks.onError(payload)
6463
// open terminal with error string
65-
const channel = getOutputChannel(outputChannelName)
66-
channel.show(false)
67-
channel.appendLine(stderr)
64+
displayOutput(stderr)
6865
return
6966
}
7067
}

src/services/testRunner/output.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as vscode from 'vscode'
2+
3+
let channel: vscode.OutputChannel
4+
5+
const getOutputChannel = (name: string): vscode.OutputChannel => {
6+
if (!channel) {
7+
channel = vscode.window.createOutputChannel(name)
8+
}
9+
return channel
10+
}
11+
12+
const outputChannelName = 'TEST_OUTPUT'
13+
14+
const parseOutput = (text: string): string => {
15+
let result = ''
16+
for (const line of text.split(/\r?\n/)) {
17+
if (line.match(/^#/) || line.match(/^not ok/)) {
18+
result += line + '\n'
19+
}
20+
}
21+
return result
22+
}
23+
24+
const displayOutput = (text: string) => {
25+
const channel = getOutputChannel(outputChannelName)
26+
channel.show(true)
27+
const output = parseOutput(text)
28+
channel.append(output)
29+
}
30+
31+
export default displayOutput

0 commit comments

Comments
 (0)