33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- //@ts -check
6+ import * as path from 'path' ;
7+ import * as cp from 'child_process' ;
8+ import * as playwright from 'playwright' ;
9+ import * as url from 'url' ;
10+ import * as tmp from 'tmp' ;
11+ import * as rimraf from 'rimraf' ;
712
8- const path = require ( 'path' ) ;
9- const cp = require ( 'child_process' ) ;
10- const playwright = require ( 'playwright' ) ;
11- const url = require ( 'url' ) ;
12-
13- // opts
1413const optimist = require ( 'optimist' )
1514 . describe ( 'debug' , 'do not run browsers headless' ) . boolean ( 'debug' )
1615 . describe ( 'browser' , 'browser in which integration tests should run' ) . string ( 'browser' ) . default ( 'browser' , 'chromium' )
1716 . describe ( 'help' , 'show the help' ) . alias ( 'help' , 'h' ) ;
1817
19- // logic
20- const argv = optimist . argv ;
21-
22- let serverProcess ;
18+ let serverProcess : cp . ChildProcess | undefined = undefined ;
2319
2420function teardownServer ( ) {
2521 if ( serverProcess ) {
@@ -28,18 +24,17 @@ function teardownServer() {
2824 }
2925}
3026
31- /**
32- * @param {string } browserType
33- * @param {string } endpoint
34- */
35- async function runTestsInBrowser ( browserType , endpoint ) {
36- const browser = await playwright [ browserType ] . launch ( { headless : ! Boolean ( argv . debug ) } ) ;
27+ async function runTestsInBrowser ( browserType : string , endpoint : string ) : Promise < void > {
28+ const browser = await playwright [ browserType ] . launch ( { headless : ! Boolean ( optimist . argv . debug ) } ) ;
3729 const page = ( await browser . defaultContext ( ) . pages ( ) ) [ 0 ] ;
3830
39- const integrationTestsPath = path . join ( __dirname , '..' , '..' , '..' , 'extensions' , 'vscode-api-tests' ) ;
40- const testWorkspaceUri = url . format ( { pathname : path . join ( integrationTestsPath , 'testWorkspace' ) , protocol : 'vscode-remote:' , slashes : true , host : 'localhost:9888' } ) ;
41- const testExtensionUri = url . format ( { pathname : path . join ( integrationTestsPath ) , protocol : 'vscode-remote:' , slashes : true , host : 'localhost:9888' } ) ;
42- const testFilesUri = url . format ( { pathname : path . join ( integrationTestsPath , 'out' , 'singlefolder-tests' ) , protocol : 'vscode-remote:' , slashes : true , host : 'localhost:9888' } ) ;
31+ const host = url . parse ( endpoint ) . host ;
32+ const protocol = 'vscode-remote' ;
33+
34+ const integrationTestsPath = path . join ( __dirname , '..' , '..' , '..' , '..' , 'extensions' , 'vscode-api-tests' ) ;
35+ const testWorkspaceUri = url . format ( { pathname : path . join ( integrationTestsPath , 'testWorkspace' ) , protocol, host, slashes : true } ) ;
36+ const testExtensionUri = url . format ( { pathname : path . join ( integrationTestsPath ) , protocol, host, slashes : true } ) ;
37+ const testFilesUri = url . format ( { pathname : path . join ( integrationTestsPath , 'out' , 'singlefolder-tests' ) , protocol, host, slashes : true } ) ;
4338
4439 const folderParam = testWorkspaceUri ;
4540 const payloadParam = `[["extensionDevelopmentPath","${ testExtensionUri } "],["extensionTestsPath","${ testFilesUri } "]]` ;
@@ -51,7 +46,7 @@ async function runTestsInBrowser(browserType, endpoint) {
5146 // emitter.emit(type, data1, data2)
5247 // });
5348
54- page . on ( 'console' , async msg => {
49+ page . on ( 'console' , async ( msg : playwright . ConsoleMessage ) => {
5550 const msgText = msg . text ( ) ;
5651 console [ msg . type ( ) ] ( msgText , await Promise . all ( msg . args ( ) . map ( async arg => await arg . jsonValue ( ) ) ) ) ;
5752
@@ -63,20 +58,25 @@ async function runTestsInBrowser(browserType, endpoint) {
6358 } ) ;
6459}
6560
66- async function launch ( ) {
67- // workspacePath = _workspacePath;
68- // const agentFolder = userDataDir;
69- // await promisify(mkdir)(agentFolder);
61+ async function launchServer ( ) : Promise < string > {
62+ const tmpDir = tmp . dirSync ( { prefix : 't' } ) ;
63+ const testDataPath = tmpDir . name ;
64+ process . once ( 'exit' , ( ) => rimraf . sync ( testDataPath ) ) ;
65+
66+ const userDataDir = path . join ( testDataPath , 'd' ) ;
67+
7068 const env = {
71- // VSCODE_AGENT_FOLDER: agentFolder ,
69+ VSCODE_AGENT_FOLDER : userDataDir ,
7270 ...process . env
7371 } ;
7472
7573 let serverLocation ;
7674 if ( process . env . VSCODE_REMOTE_SERVER_PATH ) {
7775 serverLocation = path . join ( process . env . VSCODE_REMOTE_SERVER_PATH , `server.${ process . platform === 'win32' ? 'cmd' : 'sh' } ` ) ;
7876 } else {
79- serverLocation = path . join ( __dirname , '..' , '..' , '..' , `resources/server/web.${ process . platform === 'win32' ? 'bat' : 'sh' } ` ) ;
77+ serverLocation = path . join ( __dirname , '..' , '..' , '..' , '..' , `resources/server/web.${ process . platform === 'win32' ? 'bat' : 'sh' } ` ) ;
78+
79+ process . env . VSCODE_DEV = '1' ;
8080 }
8181
8282 serverProcess = cp . spawn (
@@ -85,15 +85,15 @@ async function launch() {
8585 { env }
8686 ) ;
8787
88- serverProcess . stderr . on ( 'data' , e => console . log ( ' Server stderr: ' + e ) ) ;
89- serverProcess . stdout . on ( 'data' , e => console . log ( ' Server stdout: ' + e ) ) ;
88+ serverProcess ? .stderr ? .on ( 'data' , e => console . log ( ` Server stderr: ${ e } ` ) ) ;
89+ serverProcess ? .stdout ? .on ( 'data' , e => console . log ( ` Server stdout: ${ e } ` ) ) ;
9090
9191 process . on ( 'exit' , teardownServer ) ;
9292 process . on ( 'SIGINT' , teardownServer ) ;
9393 process . on ( 'SIGTERM' , teardownServer ) ;
9494
9595 return new Promise ( r => {
96- serverProcess . stdout . on ( 'data' , d => {
96+ serverProcess ? .stdout ? .on ( 'data' , d => {
9797 const matches = d . toString ( 'ascii' ) . match ( / W e b U I a v a i l a b l e a t ( .+ ) / ) ;
9898 if ( matches !== null ) {
9999 r ( matches [ 1 ] ) ;
@@ -102,6 +102,6 @@ async function launch() {
102102 } ) ;
103103}
104104
105- launch ( ) . then ( async endpoint => {
106- return runTestsInBrowser ( argv . browser , endpoint ) ;
105+ launchServer ( ) . then ( async endpoint => {
106+ return runTestsInBrowser ( optimist . argv . browser , endpoint ) ;
107107} , console . error ) ;
0 commit comments