mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
make unit tests faster (#241847)
This commit is contained in:
@@ -34,6 +34,46 @@
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const isCI = urlParams.get('ci');
|
||||
|
||||
const $globalThis = globalThis;
|
||||
const setTimeout0IsFaster = (typeof $globalThis.postMessage === 'function' && !$globalThis.importScripts);
|
||||
|
||||
/**
|
||||
* See https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#:~:text=than%204%2C%20then-,set%20timeout%20to%204,-.
|
||||
*
|
||||
* Works similarly to `setTimeout(0)` but doesn't suffer from the 4ms artificial delay
|
||||
* that browsers set when the nesting level is > 5.
|
||||
*/
|
||||
const setTimeout0 = (() => {
|
||||
if (setTimeout0IsFaster) {
|
||||
const pending = [];
|
||||
|
||||
$globalThis.addEventListener('message', (e) => {
|
||||
if (e.data && e.data.vscodeScheduleAsyncWork) {
|
||||
for (let i = 0, len = pending.length; i < len; i++) {
|
||||
const candidate = pending[i];
|
||||
if (candidate.id === e.data.vscodeScheduleAsyncWork) {
|
||||
pending.splice(i, 1);
|
||||
candidate.callback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
let lastId = 0;
|
||||
return (callback) => {
|
||||
const myId = ++lastId;
|
||||
pending.push({
|
||||
id: myId,
|
||||
callback: callback
|
||||
});
|
||||
$globalThis.postMessage({ vscodeScheduleAsyncWork: myId }, '*');
|
||||
};
|
||||
}
|
||||
return (callback) => setTimeout(callback);
|
||||
})();
|
||||
|
||||
Mocha.Runner.immediately = setTimeout0;
|
||||
|
||||
mocha.setup({
|
||||
ui: 'tdd',
|
||||
timeout: isCI ? 30000 : 5000
|
||||
|
||||
Reference in New Issue
Block a user