vscode/test/unit/browser/renderer.html

141 lines
4.3 KiB
HTML
Raw Normal View History

2020-02-04 22:02:52 +08:00
<html>
<head>
<meta charset="utf-8">
<title>VSCode Tests</title>
2020-02-07 16:51:24 +08:00
<link href="../../../node_modules/mocha/mocha.css" rel="stylesheet" />
2020-02-04 22:02:52 +08:00
</head>
<body>
<div id="mocha"></div>
2020-02-07 16:51:24 +08:00
<script src="../../../node_modules/mocha/mocha.js"></script>
2020-02-04 22:02:52 +08:00
<script>
// !!! DO NOT CHANGE !!!
// Our unit tests may run in environments without
// display (e.g. from builds) and tests may by
// accident bring up native dialogs or even open
// windows. This we cannot allow as it may crash
// the test run.
// !!! DO NOT CHANGE !!!
window.open = function () { throw new Error('window.open() is not supported in tests!'); };
window.alert = function () { throw new Error('window.alert() is not supported in tests!'); }
window.confirm = function () { throw new Error('window.confirm() is not supported in tests!'); }
// Ignore uncaught cancelled promise errors
window.addEventListener('unhandledrejection', e => {
const name = e && e.reason && e.reason.name;
if (name === 'Canceled') {
e.preventDefault();
e.stopPropagation();
}
});
mocha.setup({
ui: 'tdd',
timeout: 5000
});
</script>
2020-02-07 16:51:24 +08:00
<script src="../../../out/vs/loader.js"></script>
2020-02-04 22:02:52 +08:00
<script>
// configure loader
const baseUrl = window.location.href;
require.config({
catchError: true,
2020-02-07 16:51:24 +08:00
baseUrl: new URL('../../../src', baseUrl).href,
2020-02-04 22:02:52 +08:00
paths: {
2020-02-07 16:51:24 +08:00
'vs': new URL('../../../out/vs', baseUrl).href,
2020-02-07 19:32:06 +08:00
assert: new URL('../assert.js', baseUrl).href,
2020-02-07 16:51:24 +08:00
sinon: new URL('../../../node_modules/sinon/pkg/sinon-1.17.7.js', baseUrl).href
2020-02-04 22:02:52 +08:00
}
});
</script>
<script>
function serializeSuite(suite) {
return {
root: suite.root,
suites: suite.suites.map(serializeSuite),
tests: suite.tests.map(serializeRunnable),
title: suite.title,
fullTitle: suite.fullTitle(),
timeout: suite.timeout(),
retries: suite.retries(),
enableTimeouts: suite.enableTimeouts(),
slow: suite.slow(),
bail: suite.bail()
};
}
function serializeRunnable(runnable) {
return {
title: runnable.title,
fullTitle: runnable.fullTitle(),
async: runnable.async,
slow: runnable.slow(),
speed: runnable.speed,
duration: runnable.duration
};
}
function serializeError(err) {
return {
message: err.message,
stack: err.stack,
actual: err.actual,
expected: err.expected,
uncaught: err.uncaught,
showDiff: err.showDiff,
inspect: typeof err.inspect === 'function' ? err.inspect() : ''
};
}
function PlaywrightReporter(runner) {
runner.on('start', () => window.mocha_report('start'));
runner.on('end', () => window.mocha_report('end'));
runner.on('suite', suite => window.mocha_report('suite', serializeSuite(suite)));
runner.on('suite end', suite => window.mocha_report('suite end', serializeSuite(suite)));
runner.on('test', test => window.mocha_report('test', serializeRunnable(test)));
runner.on('test end', test => window.mocha_report('test end', serializeRunnable(test)));
runner.on('hook', hook => window.mocha_report('hook', serializeRunnable(hook)));
runner.on('hook end', hook => window.mocha_report('hook end', serializeRunnable(hook)));
runner.on('pass', test => window.mocha_report('pass', serializeRunnable(test)));
runner.on('fail', (test, err) => window.mocha_report('fail', serializeRunnable(test), serializeError(err)));
runner.on('pending', test => window.mocha_report('pending', serializeRunnable(test)));
};
2020-02-07 16:51:24 +08:00
window.loadAndRun = async function loadAndRun(modules, manual = false) {
2020-02-04 22:02:52 +08:00
// load
// await Promise.all(modules.map(module => new Promise((resolve, reject) =>{
// require([module], resolve, err => {
// console.log("BAD " + module + JSON.stringify(err, undefined, '\t'));
2020-02-04 22:02:52 +08:00
// // console.log(module);
// resolve({});
// });
// })));
await new Promise((resolve, reject) => {
require(modules, resolve, err => {
console.log(err);
reject(err);
});
});
// run
return new Promise((resolve, reject) => {
2020-02-07 16:51:24 +08:00
if (!manual) {
2020-02-05 22:22:02 +08:00
mocha.reporter(PlaywrightReporter);
}
2020-02-04 22:02:52 +08:00
mocha.run(failCount => resolve(failCount === 0));
});
}
2020-02-05 22:22:02 +08:00
const modules = new URL(window.location.href).searchParams.getAll('m');
2020-02-07 16:51:24 +08:00
if (Array.isArray(modules) && modules.length > 0) {
2020-02-05 22:22:02 +08:00
console.log('MANUALLY running tests', modules);
loadAndRun(modules, true).then(() => console.log('done'), err => console.log(err));
}
2020-02-04 22:02:52 +08:00
</script>
</body>
</html>