monaco-editor/test/smoke/runner.js
2021-11-15 15:55:37 +01:00

72 lines
1.7 KiB
JavaScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
const yaserver = require('yaserver');
const http = require('http');
const cp = require('child_process');
const path = require('path');
const { PORT } = require('./common');
const DEBUG_TESTS = process.argv.includes('--debug-tests');
const REPO_ROOT = path.join(__dirname, '../../');
yaserver
.createServer({
rootDir: REPO_ROOT
})
.then((staticServer) => {
const server = http.createServer((request, response) => {
return staticServer.handle(request, response);
});
server.listen(PORT, '127.0.0.1', async () => {
try {
await runTests();
console.log(`All good`);
process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
});
});
async function runTests() {
await runTest('chromium');
await runTest('firefox');
await runTest('webkit');
}
function runTest(browser) {
return new Promise((resolve, reject) => {
const env = { BROWSER: browser, ...process.env };
if (DEBUG_TESTS) {
env['DEBUG_TESTS'] = 'true';
}
const proc = cp.spawn(
'node',
[
path.join(REPO_ROOT, 'node_modules/mocha/bin/mocha'),
'test/smoke/*.test.js',
'--headless',
'--timeout',
'20000'
],
{
env,
stdio: 'inherit'
}
);
proc.on('error', reject);
proc.on('exit', (code) => {
if (code === 0) {
resolve();
} else {
reject(code);
}
});
});
}