From a5f23fc4a0700ecf26de5544c6ca0b3af2767e35 Mon Sep 17 00:00:00 2001 From: shmck Date: Tue, 3 Mar 2020 21:20:29 -0800 Subject: [PATCH] closes #116. Test output in editor --- src/editor/outputChannel.ts | 10 ---------- src/services/testRunner/index.ts | 9 +++------ src/services/testRunner/output.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 16 deletions(-) delete mode 100644 src/editor/outputChannel.ts create mode 100644 src/services/testRunner/output.ts diff --git a/src/editor/outputChannel.ts b/src/editor/outputChannel.ts deleted file mode 100644 index e43dbb25..00000000 --- a/src/editor/outputChannel.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as vscode from 'vscode' - -let channel: vscode.OutputChannel - -export const getOutputChannel = (name: string): vscode.OutputChannel => { - if (!channel) { - channel = vscode.window.createOutputChannel(name) - } - return channel -} diff --git a/src/services/testRunner/index.ts b/src/services/testRunner/index.ts index b11c13d1..93cb3a64 100644 --- a/src/services/testRunner/index.ts +++ b/src/services/testRunner/index.ts @@ -1,9 +1,9 @@ -import { getOutputChannel } from '../../editor/outputChannel' import node from '../../services/node' import logger from '../../services/logger' import parser from './parser' import { debounce, throttle } from './throttle' import onError from '../sentry/onError' +import displayOutput from './output' export interface Payload { stepId: string @@ -21,8 +21,6 @@ interface TestRunnerConfig { } const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => { - const outputChannelName = 'TEST_OUTPUT' - return async (payload: Payload, onSuccess?: () => void): Promise => { const startTime = throttle() // throttle time early @@ -58,13 +56,12 @@ const createTestRunner = (config: TestRunnerConfig, callbacks: Callbacks) => { if (stdout && stdout.length && !tap.ok) { const message = tap.message ? tap.message : '' callbacks.onFail(payload, message) + displayOutput(stdout) return } else { callbacks.onError(payload) // open terminal with error string - const channel = getOutputChannel(outputChannelName) - channel.show(false) - channel.appendLine(stderr) + displayOutput(stderr) return } } diff --git a/src/services/testRunner/output.ts b/src/services/testRunner/output.ts new file mode 100644 index 00000000..9640e328 --- /dev/null +++ b/src/services/testRunner/output.ts @@ -0,0 +1,31 @@ +import * as vscode from 'vscode' + +let channel: vscode.OutputChannel + +const getOutputChannel = (name: string): vscode.OutputChannel => { + if (!channel) { + channel = vscode.window.createOutputChannel(name) + } + return channel +} + +const outputChannelName = 'TEST_OUTPUT' + +const parseOutput = (text: string): string => { + let result = '' + for (const line of text.split(/\r?\n/)) { + if (line.match(/^#/) || line.match(/^not ok/)) { + result += line + '\n' + } + } + return result +} + +const displayOutput = (text: string) => { + const channel = getOutputChannel(outputChannelName) + channel.show(true) + const output = parseOutput(text) + channel.append(output) +} + +export default displayOutput