File tree Expand file tree Collapse file tree 5 files changed +50
-8
lines changed
packages/testkit-backend/src Expand file tree Collapse file tree 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 {
1717 if ( ! this . _ws ) {
1818 this . _ws = new WebSocket ( this . _adddress )
1919 this . _ws . onmessage = ( { data : message } ) => {
20- console . log ( message )
21- console . debug ( '[WebSocketChannel] Received messsage' , message )
20+ console . debug ( '[WebSocketChannel] Received message' , message )
2221 const { messageType, contextId, data } = JSON . parse ( message )
2322
2423 switch ( messageType ) {
@@ -45,12 +44,16 @@ export default class WebSocketChannel extends Channel {
4544 }
4645 }
4746
48- writeResponse ( contextId , response ) {
47+ writeResponse ( contextId , response , skipLogging ) {
4948 if ( this . _ws ) {
50- console . debug ( '[WebSocketChannel] Writing response' , { contextId, response } )
49+ if ( ! skipLogging ) {
50+ console . debug ( '[WebSocketChannel] Writing response' , { contextId, response } )
51+ }
5152 return this . _ws . send ( this . _serialize ( { contextId, response } ) )
5253 }
53- console . error ( '[WebSocketChannel] Websocket is not connected' )
54+ if ( ! skipLogging ) {
55+ console . error ( '[WebSocketChannel] Websocket is not connected' )
56+ }
5457 }
5558
5659 _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'
22import { WebSocketServer } from 'ws'
33import { createServer } from 'http'
44import { HttpStaticServer } from '../infrastructure'
5+ import consoleRemote from '../console.remote'
56
67/**
78 * RemoteController handles the requests by sending them a remote client.
@@ -81,7 +82,11 @@ export default class RemoteController extends Controller {
8182 this . _ws = ws
8283 this . _ws . on ( 'message' , safeRun ( buffer => {
8384 const message = JSON . parse ( buffer . toString ( ) )
84- console . debug ( '[RemoteController] Received messsage' , message )
85+
86+ if ( consoleRemote . handleConsole ( message ) ) {
87+ return
88+ }
89+
8590 const { contextId, response } = message
8691 this . _writeResponse ( contextId , response )
8792 } ) )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { getShouldRunTest } from './skipped-tests'
77import { createGetFeatures } from './feature'
88import * as REQUEST_HANDLERS from './request-handlers.js'
99import * as RX_REQUEST_HANDLERS from './request-handlers-rx.js'
10+ import remoteConsole from './console.remote.js'
1011
1112const SUPPORTED_TLS = ( ( ) => {
1213 if ( tls . DEFAULT_MAX_VERSION ) {
@@ -40,7 +41,9 @@ function main () {
4041
4142 const newChannel = ( ) => {
4243 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
4447 }
4548 return new SocketChannel ( backendPort )
4649 }
Original file line number Diff line number Diff line change @@ -160,6 +160,6 @@ export function FakeTimeAck () {
160160 return response ( 'FakeTimeAck' , { } )
161161}
162162
163- function response ( name , data ) {
163+ export function response ( name , data ) {
164164 return { name, data }
165165}
You can’t perform that action at this time.
0 commit comments