@@ -15,18 +15,13 @@ const optimist = require('optimist')
1515 . describe ( 'browser' , 'browser in which integration tests should run' ) . string ( 'browser' ) . default ( 'browser' , 'chromium' )
1616 . describe ( 'help' , 'show the help' ) . alias ( 'help' , 'h' ) ;
1717
18- let serverProcess : cp . ChildProcess | undefined = undefined ;
19-
20- function teardownServer ( ) {
21- if ( serverProcess ) {
22- serverProcess . kill ( ) ;
23- serverProcess = undefined ;
24- }
25- }
18+ const width = 1200 ;
19+ const height = 800 ;
2620
2721async function runTestsInBrowser ( browserType : string , endpoint : string ) : Promise < void > {
2822 const browser = await playwright [ browserType ] . launch ( { headless : ! Boolean ( optimist . argv . debug ) } ) ;
2923 const page = ( await browser . defaultContext ( ) . pages ( ) ) [ 0 ] ;
24+ await page . setViewport ( { width, height } ) ;
3025
3126 const host = url . parse ( endpoint ) . host ;
3227 const protocol = 'vscode-remote' ;
@@ -41,24 +36,22 @@ async function runTestsInBrowser(browserType: string, endpoint: string): Promise
4136
4237 await page . goto ( `${ endpoint } &folder=${ folderParam } &payload=${ payloadParam } ` ) ;
4338
44- // const emitter = new events.EventEmitter();
45- // await page.exposeFunction('mocha_report', (type, data1, data2) => {
46- // emitter.emit(type, data1, data2)
47- // });
39+ await page . exposeFunction ( 'codeAutomationLog' , ( type : string , args : any [ ] ) => {
40+ console [ type ] ( ...args ) ;
41+ } ) ;
4842
4943 page . on ( 'console' , async ( msg : playwright . ConsoleMessage ) => {
5044 const msgText = msg . text ( ) ;
51- console [ msg . type ( ) ] ( msgText , await Promise . all ( msg . args ( ) . map ( async arg => await arg . jsonValue ( ) ) ) ) ;
52-
5345 if ( msgText . indexOf ( 'vscode:exit' ) >= 0 ) {
54- browser . close ( ) ;
55- teardownServer ( ) ;
56- setTimeout ( ( ) => process . exit ( msgText === 'vscode:exit 0' ? 0 : 1 ) , 10 ) ;
46+ await browser . close ( ) ;
47+ process . exit ( msgText === 'vscode:exit 0' ? 0 : 1 ) ;
5748 }
5849 } ) ;
5950}
6051
6152async function launchServer ( ) : Promise < string > {
53+
54+ // Ensure a tmp user-data-dir is used for the tests
6255 const tmpDir = tmp . dirSync ( { prefix : 't' } ) ;
6356 const testDataPath = tmpDir . name ;
6457 process . once ( 'exit' , ( ) => rimraf . sync ( testDataPath ) ) ;
@@ -70,7 +63,7 @@ async function launchServer(): Promise<string> {
7063 ...process . env
7164 } ;
7265
73- let serverLocation ;
66+ let serverLocation : string ;
7467 if ( process . env . VSCODE_REMOTE_SERVER_PATH ) {
7568 serverLocation = path . join ( process . env . VSCODE_REMOTE_SERVER_PATH , `server.${ process . platform === 'win32' ? 'cmd' : 'sh' } ` ) ;
7669 } else {
@@ -79,24 +72,33 @@ async function launchServer(): Promise<string> {
7972 process . env . VSCODE_DEV = '1' ;
8073 }
8174
82- serverProcess = cp . spawn (
75+ let serverProcess = cp . spawn (
8376 serverLocation ,
8477 [ '--browser' , 'none' , '--driver' , 'web' ] ,
8578 { env }
8679 ) ;
8780
88- serverProcess ?. stderr ?. on ( 'data' , e => console . log ( `Server stderr: ${ e } ` ) ) ;
89- serverProcess ?. stdout ?. on ( 'data' , e => console . log ( `Server stdout: ${ e } ` ) ) ;
81+ serverProcess ?. stderr ?. on ( 'data' , error => console . log ( `Server stderr: ${ error } ` ) ) ;
82+
83+ if ( optimist . argv . debug ) {
84+ serverProcess ?. stdout ?. on ( 'data' , data => console . log ( `Server stdout: ${ data } ` ) ) ;
85+ }
86+
87+ function teardownServer ( ) {
88+ if ( serverProcess ) {
89+ serverProcess . kill ( ) ;
90+ }
91+ }
9092
9193 process . on ( 'exit' , teardownServer ) ;
9294 process . on ( 'SIGINT' , teardownServer ) ;
9395 process . on ( 'SIGTERM' , teardownServer ) ;
9496
95- return new Promise ( r => {
96- serverProcess ?. stdout ?. on ( 'data' , d => {
97- const matches = d . toString ( 'ascii' ) . match ( / W e b U I a v a i l a b l e a t ( .+ ) / ) ;
97+ return new Promise ( c => {
98+ serverProcess ?. stdout ?. on ( 'data' , data => {
99+ const matches = data . toString ( 'ascii' ) . match ( / W e b U I a v a i l a b l e a t ( .+ ) / ) ;
98100 if ( matches !== null ) {
99- r ( matches [ 1 ] ) ;
101+ c ( matches [ 1 ] ) ;
100102 }
101103 } ) ;
102104 } ) ;
0 commit comments