mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
tests - browser tests to go through new log service
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
"@types/mkdirp": "0.5.1",
|
||||
"@types/node": "^12.11.7",
|
||||
"@types/rimraf": "2.0.2",
|
||||
"@types/tmp": "^0.1.0",
|
||||
"rimraf": "^2.6.1",
|
||||
"tmp": "0.0.33",
|
||||
"typescript": "3.7.5"
|
||||
|
||||
@@ -15,18 +15,13 @@ const optimist = require('optimist')
|
||||
.describe('browser', 'browser in which integration tests should run').string('browser').default('browser', 'chromium')
|
||||
.describe('help', 'show the help').alias('help', 'h');
|
||||
|
||||
let serverProcess: cp.ChildProcess | undefined = undefined;
|
||||
|
||||
function teardownServer() {
|
||||
if (serverProcess) {
|
||||
serverProcess.kill();
|
||||
serverProcess = undefined;
|
||||
}
|
||||
}
|
||||
const width = 1200;
|
||||
const height = 800;
|
||||
|
||||
async function runTestsInBrowser(browserType: string, endpoint: string): Promise<void> {
|
||||
const browser = await playwright[browserType].launch({ headless: !Boolean(optimist.argv.debug) });
|
||||
const page = (await browser.defaultContext().pages())[0];
|
||||
await page.setViewport({ width, height });
|
||||
|
||||
const host = url.parse(endpoint).host;
|
||||
const protocol = 'vscode-remote';
|
||||
@@ -41,24 +36,22 @@ async function runTestsInBrowser(browserType: string, endpoint: string): Promise
|
||||
|
||||
await page.goto(`${endpoint}&folder=${folderParam}&payload=${payloadParam}`);
|
||||
|
||||
// const emitter = new events.EventEmitter();
|
||||
// await page.exposeFunction('mocha_report', (type, data1, data2) => {
|
||||
// emitter.emit(type, data1, data2)
|
||||
// });
|
||||
await page.exposeFunction('codeAutomationLog', (type: string, args: any[]) => {
|
||||
console[type](...args);
|
||||
});
|
||||
|
||||
page.on('console', async (msg: playwright.ConsoleMessage) => {
|
||||
const msgText = msg.text();
|
||||
console[msg.type()](msgText, await Promise.all(msg.args().map(async arg => await arg.jsonValue())));
|
||||
|
||||
if (msgText.indexOf('vscode:exit') >= 0) {
|
||||
browser.close();
|
||||
teardownServer();
|
||||
setTimeout(() => process.exit(msgText === 'vscode:exit 0' ? 0 : 1), 10);
|
||||
await browser.close();
|
||||
process.exit(msgText === 'vscode:exit 0' ? 0 : 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function launchServer(): Promise<string> {
|
||||
|
||||
// Ensure a tmp user-data-dir is used for the tests
|
||||
const tmpDir = tmp.dirSync({ prefix: 't' });
|
||||
const testDataPath = tmpDir.name;
|
||||
process.once('exit', () => rimraf.sync(testDataPath));
|
||||
@@ -70,7 +63,7 @@ async function launchServer(): Promise<string> {
|
||||
...process.env
|
||||
};
|
||||
|
||||
let serverLocation;
|
||||
let serverLocation: string;
|
||||
if (process.env.VSCODE_REMOTE_SERVER_PATH) {
|
||||
serverLocation = path.join(process.env.VSCODE_REMOTE_SERVER_PATH, `server.${process.platform === 'win32' ? 'cmd' : 'sh'}`);
|
||||
} else {
|
||||
@@ -79,24 +72,33 @@ async function launchServer(): Promise<string> {
|
||||
process.env.VSCODE_DEV = '1';
|
||||
}
|
||||
|
||||
serverProcess = cp.spawn(
|
||||
let serverProcess = cp.spawn(
|
||||
serverLocation,
|
||||
['--browser', 'none', '--driver', 'web'],
|
||||
{ env }
|
||||
);
|
||||
|
||||
serverProcess?.stderr?.on('data', e => console.log(`Server stderr: ${e}`));
|
||||
serverProcess?.stdout?.on('data', e => console.log(`Server stdout: ${e}`));
|
||||
serverProcess?.stderr?.on('data', error => console.log(`Server stderr: ${error}`));
|
||||
|
||||
if (optimist.argv.debug) {
|
||||
serverProcess?.stdout?.on('data', data => console.log(`Server stdout: ${data}`));
|
||||
}
|
||||
|
||||
function teardownServer() {
|
||||
if (serverProcess) {
|
||||
serverProcess.kill();
|
||||
}
|
||||
}
|
||||
|
||||
process.on('exit', teardownServer);
|
||||
process.on('SIGINT', teardownServer);
|
||||
process.on('SIGTERM', teardownServer);
|
||||
|
||||
return new Promise(r => {
|
||||
serverProcess?.stdout?.on('data', d => {
|
||||
const matches = d.toString('ascii').match(/Web UI available at (.+)/);
|
||||
return new Promise(c => {
|
||||
serverProcess?.stdout?.on('data', data => {
|
||||
const matches = data.toString('ascii').match(/Web UI available at (.+)/);
|
||||
if (matches !== null) {
|
||||
r(matches[1]);
|
||||
c(matches[1]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,6 +46,11 @@
|
||||
"@types/glob" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/tmp@^0.1.0":
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.1.0.tgz#19cf73a7bcf641965485119726397a096f0049bd"
|
||||
integrity sha512-6IwZ9HzWbCq6XoQWhxLpDjuADodH/MKXRUIDFudvgjcVdjFknvmR+DNsoUeer4XPrEnrZs04Jj+kfV9pFsrhmA==
|
||||
|
||||
balanced-match@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
|
||||
|
||||
Reference in New Issue
Block a user