mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
testing: allow waiting for server before running unit tests
Fixes https://github.com/microsoft/vscode/issues/121751
This commit is contained in:
parent
fc90674374
commit
b1569995f9
|
@ -15,6 +15,7 @@ const mocha = require('mocha');
|
|||
const events = require('events');
|
||||
const MochaJUnitReporter = require('mocha-junit-reporter');
|
||||
const url = require('url');
|
||||
const net = require('net');
|
||||
const createStatsCollector = require('mocha/lib/stats-collector');
|
||||
const FullJsonStreamReporter = require('../fullJsonStreamReporter');
|
||||
|
||||
|
@ -31,6 +32,7 @@ const optimist = require('optimist')
|
|||
.describe('debug', 'open dev tools, keep window open, reuse app data').string('debug')
|
||||
.describe('reporter', 'the mocha reporter').string('reporter').default('reporter', 'spec')
|
||||
.describe('reporter-options', 'the mocha reporter options').string('reporter-options').default('reporter-options', '')
|
||||
.describe('wait-server', 'port to connect to and wait before running tests')
|
||||
.describe('tfs').string('tfs')
|
||||
.describe('help', 'show the help').alias('help', 'h');
|
||||
|
||||
|
@ -177,9 +179,45 @@ app.on('ready', () => {
|
|||
win.show();
|
||||
win.webContents.openDevTools();
|
||||
}
|
||||
win.webContents.send('run', argv);
|
||||
|
||||
if (argv.waitServer) {
|
||||
waitForServer(Number(argv.waitServer)).then(sendRun);
|
||||
} else {
|
||||
sendRun();
|
||||
}
|
||||
});
|
||||
|
||||
async function waitForServer(port) {
|
||||
let timeout;
|
||||
let socket;
|
||||
|
||||
return new Promise(resolve => {
|
||||
socket = net.connect(port, '127.0.0.1');
|
||||
socket.on('error', e => {
|
||||
console.error('error connecting to waitServer', e);
|
||||
resolve();
|
||||
});
|
||||
|
||||
socket.on('close', () => {
|
||||
resolve();
|
||||
});
|
||||
|
||||
timeout = setTimeout(() => {
|
||||
console.error('timed out waiting for before starting tests debugger');
|
||||
resolve();
|
||||
}, 7000);
|
||||
}).finally(() => {
|
||||
if (socket) {
|
||||
socket.end();
|
||||
}
|
||||
clearTimeout(timeout);
|
||||
});
|
||||
}
|
||||
|
||||
function sendRun() {
|
||||
win.webContents.send('run', argv);
|
||||
}
|
||||
|
||||
win.loadURL(url.format({ pathname: path.join(__dirname, 'renderer.html'), protocol: 'file:', slashes: true }));
|
||||
|
||||
const runner = new IPCRunner();
|
||||
|
|
Loading…
Reference in a new issue