@@ -6,10 +6,10 @@ import { Logger } from "../../shared/interfaces";
66import { ErrorNotification , Group , GroupNotification , Notification , PrintNotification , Suite , SuiteNotification , Test , TestDoneNotification , TestStartNotification } from "../../shared/test_protocol" ;
77import { flatMap , notUndefined , uniq } from "../../shared/utils" ;
88import { sortBy } from "../../shared/utils/array" ;
9+ import { brightRed , yellow } from "../../shared/utils/colors" ;
910import { fsPath } from "../../shared/utils/fs" ;
1011import { getLaunchConfig } from "../../shared/utils/test" ;
1112import { extensionPath } from "../../shared/vscode/extension_utils" ;
12- import { getChannel } from "../commands/channels" ;
1313
1414// TODO: Refactor all of this crazy logic out of test_view into its own class, so that consuming the test results is much
1515// simpler and disconnected from the view!
@@ -24,6 +24,7 @@ export class TestResultsProvider implements vs.Disposable, vs.TreeDataProvider<T
2424 private onFirstFailureEmitter : vs . EventEmitter < TestItemTreeItem > = new vs . EventEmitter < TestItemTreeItem > ( ) ;
2525 public readonly onFirstFailure : vs . Event < TestItemTreeItem > = this . onFirstFailureEmitter . event ;
2626 private currentSelectedNode : TestItemTreeItem | undefined ;
27+ private currentTestTerminal : [ vs . Terminal , vs . EventEmitter < string > ] | undefined ;
2728
2829 // Set this flag we know when a new run starts so we can show the tree; however
2930 // we can't show it until we render a node (we can only call reveal on a node) so
@@ -129,33 +130,50 @@ export class TestResultsProvider implements vs.Disposable, vs.TreeDataProvider<T
129130 } ) ) ;
130131 }
131132
132- private writeTestOutput ( treeNode : TestTreeItem , forceShow = false ) {
133- const output = getChannel ( "Test Output" ) ;
134- output . clear ( ) ;
135- if ( forceShow )
136- output . show ( true ) ;
137-
138- output . appendLine ( `${ treeNode . test . name } :\n` ) ;
139-
140- if ( ! treeNode . outputEvents . length )
141- output . appendLine ( `(no output)` ) ;
142-
143- for ( const o of treeNode . outputEvents ) {
144- this . appendTestOutput ( o , output ) ;
133+ private async writeTestOutput ( treeNode : TestTreeItem , forceShow = false ) {
134+ if ( this . currentTestTerminal ) {
135+ this . currentTestTerminal [ 0 ] . dispose ( ) ;
136+ this . currentTestTerminal = undefined ;
145137 }
138+
139+ const emitter = new vs . EventEmitter < string > ( ) ;
140+ const pseudoterminal : vs . Pseudoterminal = {
141+ close : ( ) => { } ,
142+ onDidWrite : emitter . event ,
143+ open : ( ) => {
144+ emitter . fire ( `Output for ${ treeNode . fullName } \r\n` ) ;
145+
146+ if ( ! treeNode . outputEvents . length )
147+ emitter . fire ( `(no output)\r\n` ) ;
148+
149+ for ( const o of treeNode . outputEvents ) {
150+ this . appendTestOutput ( o , emitter ) ;
151+ }
152+ } ,
153+ } ;
154+ this . currentTestTerminal = [
155+ vs . window . createTerminal ( { name : "Test Output" , pty : pseudoterminal } ) ,
156+ emitter ,
157+ ] ;
158+ this . currentTestTerminal [ 0 ] . show ( ) ;
146159 }
147160
148- private appendTestOutput ( event : PrintNotification | ErrorNotification , output = getChannel ( "Test Output" ) ) {
161+ private appendTestOutput ( event : PrintNotification | ErrorNotification , emitter = this . currentTestTerminal ? this . currentTestTerminal [ 1 ] : undefined ) {
162+ if ( ! emitter )
163+ return ;
164+ let output : string | undefined ;
149165 if ( event . type === "error" ) {
150166 event = event as ErrorNotification ;
151- output . appendLine ( `ERROR: ${ event . error } ` ) ;
152- output . appendLine ( event . stackTrace ) ;
167+ output = brightRed ( `${ event . error } \n${ event . stackTrace } \n` ) ;
153168 } else if ( event . type === "print" ) {
154169 event = event as PrintNotification ;
155- output . appendLine ( event . message ) ;
170+ output = ` ${ event . message } \n` ;
156171 } else {
157- output . appendLine ( `Unknown message type '${ event . type } '.` ) ;
172+ output = yellow ( `Unknown message type '${ event . type } '.\n ` ) ;
158173 }
174+
175+ if ( output )
176+ emitter . fire ( output . replace ( / \n / g, "\r\n" ) ) ;
159177 }
160178
161179 public handleDebugSessionCustomEvent ( e : vs . DebugSessionCustomEvent ) {
0 commit comments