vscode/test/unit/browser/renderer.html

188 lines
6.1 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();
}
});
const urlParams = new URLSearchParams(window.location.search);
const isCI = urlParams.get('ci');
2020-02-04 22:02:52 +08:00
mocha.setup({
ui: 'tdd',
timeout: isCI ? 30000 : 5000
2020-02-04 22:02:52 +08:00
});
</script>
<!-- Depending on --build or not, load loader from known locations -->
2020-02-07 16:51:24 +08:00
<script src="../../../out/vs/loader.js"></script>
<script src="../../../out-build/vs/loader.js"></script>
2020-02-04 22:02:52 +08:00
<script>
const isBuild = urlParams.get('build');
2020-02-04 22:02:52 +08:00
// configure loader
const baseUrl = window.location.href;
require.config({
catchError: true,
baseUrl: urlParams.get('baseUrl'),
2020-02-04 22:02:52 +08:00
paths: {
vs: new URL(`../../../${!!isBuild ? 'out-build' : 'out'}/vs`, baseUrl).href,
2020-02-07 19:32:06 +08:00
assert: new URL('../assert.js', baseUrl).href,
2021-06-08 23:46:55 +08:00
sinon: new URL('../../../node_modules/sinon/pkg/sinon.js', baseUrl).href,
'sinon-test': new URL('../../../node_modules/sinon-test/dist/sinon-test.js', baseUrl).href,
2023-11-02 21:34:09 +08:00
'@xterm/xterm': new URL('../../../node_modules/@xterm/xterm/lib/xterm.js', baseUrl).href,
'@vscode/iconv-lite-umd': new URL('../../../node_modules/@vscode/iconv-lite-umd/lib/iconv-lite-umd.js', baseUrl).href,
Re-merge introduction of tree sitter (#223474) * Make space for tree sitter * Add the tree sitter wasm file * Very naive tree-sitter syntax highlighting for html, with a layer breaker * Update tree when content changes * WIP for making abstract tokens class * Handle theme changes * Replace entire text model value with parse callback * Perf improvements * Add tree-sitter-typescript * Add typescript + better initial parsing * Refactor into tree parsing service and fix flaw in parse callback * Remove things that aren't the parser service * Add yielding * Remove changes that aren't required for PR * Remove more file changes * Reduce yield to 50 ms * Fix incremental parsing * Try update node-abi * Revert "Try update node-abi" This reverts commit df28801e31e3d672a0754eb9edc55a7208d7cde8. * Update text buffer chunk api * fix build * Remove tree-sitter dependency * Adopt new, as yet unpublished, `@vscode/tree-sitter-wasm` package * Use published `@vscode/tree-sitter-wasm` package * Break `TreeSitterTree` and `TreeSitterParserService` into better pieces and: - document the order of editor changes - use service injection where `TextModel` is constructed * Fix tests * Remove unneeded import * Fix missing tree-sitter-wasm in web and remote * Make package.jsons match * Add @vscode/tree-sitter-wasm to web loader config * Try using importAMDNodeModule * PR feedback * Add race condition test for changing language while loading language * Use same timeout * Queue content changes * Remove override dispose * Move queue into TreeSitterTree --------- Co-authored-by: Peng Lyu <penn.lv@gmail.com>
2024-07-29 17:31:28 +08:00
'@vscode/tree-sitter-wasm': new URL('../../../node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter.js', baseUrl).href,
jschardet: new URL('../../../node_modules/jschardet/dist/jschardet.min.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(),
2020-12-18 02:16:42 +08:00
titlePath: suite.titlePath(),
2020-02-04 22:02:52 +08:00
timeout: suite.timeout(),
retries: suite.retries(),
slow: suite.slow(),
bail: suite.bail()
};
}
function serializeRunnable(runnable) {
return {
title: runnable.title,
2020-12-18 02:16:42 +08:00
titlePath: runnable.titlePath(),
2020-02-04 22:02:52 +08:00
fullTitle: runnable.fullTitle(),
async: runnable.async,
slow: runnable.slow(),
speed: runnable.speed,
duration: runnable.duration,
currentRetry: runnable.currentRetry(),
2020-02-04 22:02:52 +08:00
};
}
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)));
};
const remoteMethods = [
'__readFileInTests',
'__writeFileInTests',
'__readDirInTests',
'__unlinkInTests',
'__mkdirPInTests',
];
for (const method of remoteMethods) {
const prefix = window.location.pathname.split('/')[1];
globalThis[method] = async (...args) => {
const res = await fetch(`/${prefix}/remoteMethod/${method}`, {
body: JSON.stringify(args),
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
return res.json();
}
}
async function loadModules(modules) {
for (const file of modules) {
mocha.suite.emit(Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE, globalThis, file, mocha);
const m = await new Promise((resolve, reject) => require([file], resolve, err => {
console.log("BAD " + file + JSON.stringify(err, undefined, '\t'));
resolve({});
}));
mocha.suite.emit(Mocha.Suite.constants.EVENT_FILE_REQUIRE, m, file, mocha);
mocha.suite.emit(Mocha.Suite.constants.EVENT_FILE_POST_REQUIRE, globalThis, file, mocha);
}
}
window.loadAndRun = async function loadAndRun({ modules, grep }, manual = false) {
2020-02-04 22:02:52 +08:00
// load
await loadModules(modules);
// await new Promise((resolve, reject) => {
// require(modules, resolve, err => {
// console.log(err);
// reject(err);
// });
// });
2020-02-04 22:02:52 +08:00
// run
return new Promise((resolve, reject) => {
if (grep) {
mocha.grep(grep);
}
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 url = new URL(window.location.href);
const modules = url.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-05 22:22:02 +08:00
}
2020-02-04 22:02:52 +08:00
</script>
</body>
</html>