File tree 5 files changed +50
-8
lines changed
packages/testkit-backend/src
5 files changed +50
-8
lines changed Original file line number Diff line number Diff line change @@ -17,8 +17,7 @@ export default class WebSocketChannel extends Channel {
17
17
if ( ! this . _ws ) {
18
18
this . _ws = new WebSocket ( this . _adddress )
19
19
this . _ws . onmessage = ( { data : message } ) => {
20
- console . log ( message )
21
- console . debug ( '[WebSocketChannel] Received messsage' , message )
20
+ console . debug ( '[WebSocketChannel] Received message' , message )
22
21
const { messageType, contextId, data } = JSON . parse ( message )
23
22
24
23
switch ( messageType ) {
@@ -45,12 +44,16 @@ export default class WebSocketChannel extends Channel {
45
44
}
46
45
}
47
46
48
- writeResponse ( contextId , response ) {
47
+ writeResponse ( contextId , response , skipLogging ) {
49
48
if ( this . _ws ) {
50
- console . debug ( '[WebSocketChannel] Writing response' , { contextId, response } )
49
+ if ( ! skipLogging ) {
50
+ console . debug ( '[WebSocketChannel] Writing response' , { contextId, response } )
51
+ }
51
52
return this . _ws . send ( this . _serialize ( { contextId, response } ) )
52
53
}
53
- console . error ( '[WebSocketChannel] Websocket is not connected' )
54
+ if ( ! skipLogging ) {
55
+ console . error ( '[WebSocketChannel] Websocket is not connected' )
56
+ }
54
57
}
55
58
56
59
_serialize ( val ) {
Original file line number Diff line number Diff line change
1
+ import { response } from './responses'
2
+
3
+ const originalConsole = console
4
+
5
+ export default {
6
+ install : ( channel ) => {
7
+ // eslint-disable-next-line no-global-assign
8
+ console = new Proxy ( { } , {
9
+ get : ( _ , method ) => ( ...args ) => {
10
+ originalConsole [ method ] . apply ( originalConsole , args )
11
+ channel . writeResponse ( null , response ( 'Console' , {
12
+ method,
13
+ args
14
+ } ) , true )
15
+ }
16
+ } )
17
+ } ,
18
+ handleConsole : ( message ) => {
19
+ if ( message . response . name === 'Console' ) {
20
+ const { method, args } = message . response . data
21
+ args [ 0 ] = typeof args [ 0 ] === 'string' ? `[RemoteConsole] ${ args [ 0 ] } ` : args [ 0 ]
22
+ console [ method ] . apply ( console , args )
23
+ return true
24
+ }
25
+ return false
26
+ } ,
27
+ uninstall : ( ) => {
28
+ // eslint-disable-next-line no-global-assign
29
+ console = originalConsole
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import Controller from './interface'
2
2
import { WebSocketServer } from 'ws'
3
3
import { createServer } from 'http'
4
4
import { HttpStaticServer } from '../infrastructure'
5
+ import consoleRemote from '../console.remote'
5
6
6
7
/**
7
8
* RemoteController handles the requests by sending them a remote client.
@@ -81,7 +82,11 @@ export default class RemoteController extends Controller {
81
82
this . _ws = ws
82
83
this . _ws . on ( 'message' , safeRun ( buffer => {
83
84
const message = JSON . parse ( buffer . toString ( ) )
84
- console . debug ( '[RemoteController] Received messsage' , message )
85
+
86
+ if ( consoleRemote . handleConsole ( message ) ) {
87
+ return
88
+ }
89
+
85
90
const { contextId, response } = message
86
91
this . _writeResponse ( contextId , response )
87
92
} ) )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { getShouldRunTest } from './skipped-tests'
7
7
import { createGetFeatures } from './feature'
8
8
import * as REQUEST_HANDLERS from './request-handlers.js'
9
9
import * as RX_REQUEST_HANDLERS from './request-handlers-rx.js'
10
+ import remoteConsole from './console.remote.js'
10
11
11
12
const SUPPORTED_TLS = ( ( ) => {
12
13
if ( tls . DEFAULT_MAX_VERSION ) {
@@ -40,7 +41,9 @@ function main () {
40
41
41
42
const newChannel = ( ) => {
42
43
if ( channelType . toUpperCase ( ) === 'WEBSOCKET' ) {
43
- return new WebSocketChannel ( new URL ( `ws://localhost:${ backendPort } ` ) )
44
+ const channel = new WebSocketChannel ( new URL ( `ws://localhost:${ backendPort } ` ) )
45
+ remoteConsole . install ( channel )
46
+ return channel
44
47
}
45
48
return new SocketChannel ( backendPort )
46
49
}
Original file line number Diff line number Diff line change @@ -160,6 +160,6 @@ export function FakeTimeAck () {
160
160
return response ( 'FakeTimeAck' , { } )
161
161
}
162
162
163
- function response ( name , data ) {
163
+ export function response ( name , data ) {
164
164
return { name, data }
165
165
}
You can’t perform that action at this time.
0 commit comments