mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
esm - restore lost changes in tests from migration (#227225)
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// @ts-check
|
||||
|
||||
/*eslint-env mocha*/
|
||||
|
||||
const fs = require('fs');
|
||||
@@ -91,22 +89,22 @@ Object.assign(globalThis, {
|
||||
__mkdirPInTests: path => fs.promises.mkdir(path, { recursive: true }),
|
||||
});
|
||||
|
||||
const IS_CI = !!process.env.BUILD_ARTIFACTSTAGINGDIRECTORY;
|
||||
const _tests_glob = '**/test/**/*.test.js';
|
||||
let loader;
|
||||
const _loaderErrors = [];
|
||||
let _out;
|
||||
|
||||
function initNls(opts) {
|
||||
if (opts.build) {
|
||||
// when running from `out-build`, ensure to load the default
|
||||
// messages file, because all `nls.localize` calls have their
|
||||
// english values removed and replaced by an index.
|
||||
// VSCODE_GLOBALS: NLS
|
||||
globalThis._VSCODE_NLS_MESSAGES = require(`../../../out-build/nls.messages.json`);
|
||||
}
|
||||
}
|
||||
const _tests_glob = '**/test/**/*.test.js';
|
||||
let loader;
|
||||
let _out;
|
||||
const _loaderErrors = [];
|
||||
|
||||
function initLoader(opts) {
|
||||
// debugger;
|
||||
const outdir = opts.build ? 'out-build' : 'out';
|
||||
_out = path.join(__dirname, `../../../${outdir}`);
|
||||
|
||||
@@ -120,7 +118,6 @@ function initLoader(opts) {
|
||||
*/
|
||||
function esmRequire(modules, callback, errorback) {
|
||||
const tasks = modules.map(mod => {
|
||||
|
||||
const url = new URL(`./${mod}.js`, baseUrl).href;
|
||||
return import(url).catch(err => {
|
||||
console.log(mod, url);
|
||||
@@ -163,9 +160,8 @@ function loadTestModules(opts) {
|
||||
if (opts.run) {
|
||||
const files = Array.isArray(opts.run) ? opts.run : [opts.run];
|
||||
const modules = files.map(file => {
|
||||
file = file.replace(/^src/, 'out');
|
||||
file = file.replace(/\.ts$/, '.js');
|
||||
return path.relative(_out, file).replace(/\.js$/, '');
|
||||
file = file.replace(/^src[\\/]/, '');
|
||||
return file.replace(/\.[jt]s$/, '');
|
||||
});
|
||||
return loadModules(modules);
|
||||
}
|
||||
@@ -184,22 +180,103 @@ function loadTestModules(opts) {
|
||||
}).then(loadModules);
|
||||
}
|
||||
|
||||
/** @type Mocha.Test */
|
||||
let currentTest;
|
||||
|
||||
function loadTests(opts) {
|
||||
|
||||
//#region Unexpected Output
|
||||
|
||||
const _allowedTestOutput = [
|
||||
/The vm module of Node\.js is deprecated in the renderer process and will be removed./,
|
||||
];
|
||||
|
||||
// allow snapshot mutation messages locally
|
||||
if (!IS_CI) {
|
||||
_allowedTestOutput.push(/Creating new snapshot in/);
|
||||
_allowedTestOutput.push(/Deleting [0-9]+ old snapshots/);
|
||||
}
|
||||
|
||||
const _allowedTestsWithOutput = new Set([
|
||||
'creates a snapshot', // self-testing
|
||||
'validates a snapshot', // self-testing
|
||||
'cleans up old snapshots', // self-testing
|
||||
'issue #149412: VS Code hangs when bad semantic token data is received', // https://github.com/microsoft/vscode/issues/192440
|
||||
'issue #134973: invalid semantic tokens should be handled better', // https://github.com/microsoft/vscode/issues/192440
|
||||
'issue #148651: VSCode UI process can hang if a semantic token with negative values is returned by language service', // https://github.com/microsoft/vscode/issues/192440
|
||||
'issue #149130: vscode freezes because of Bracket Pair Colorization', // https://github.com/microsoft/vscode/issues/192440
|
||||
'property limits', // https://github.com/microsoft/vscode/issues/192443
|
||||
'Error events', // https://github.com/microsoft/vscode/issues/192443
|
||||
'fetch returns keybinding with user first if title and id matches', //
|
||||
'throw ListenerLeakError'
|
||||
]);
|
||||
|
||||
const _allowedSuitesWithOutput = new Set([
|
||||
'InteractiveChatController'
|
||||
]);
|
||||
|
||||
let _testsWithUnexpectedOutput = false;
|
||||
|
||||
for (const consoleFn of [console.log, console.error, console.info, console.warn, console.trace, console.debug]) {
|
||||
console[consoleFn.name] = function (msg) {
|
||||
if (!currentTest) {
|
||||
consoleFn.apply(console, arguments);
|
||||
} else if (!_allowedTestOutput.some(a => a.test(msg)) && !_allowedTestsWithOutput.has(currentTest.title) && !_allowedSuitesWithOutput.has(currentTest.parent?.title)) {
|
||||
_testsWithUnexpectedOutput = true;
|
||||
consoleFn.apply(console, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Unexpected / Loader Errors
|
||||
|
||||
const _unexpectedErrors = [];
|
||||
|
||||
// collect unexpected errors
|
||||
const _allowedTestsWithUnhandledRejections = new Set([
|
||||
// Lifecycle tests
|
||||
'onWillShutdown - join with error is handled',
|
||||
'onBeforeShutdown - veto with error is treated as veto',
|
||||
'onBeforeShutdown - final veto with error is treated as veto',
|
||||
// Search tests
|
||||
'Search Model: Search reports timed telemetry on search when error is called'
|
||||
]);
|
||||
|
||||
loader.require(['vs/base/common/errors'], function (errors) {
|
||||
errors.setUnexpectedErrorHandler(function (err) {
|
||||
|
||||
const onUnexpectedError = function (err) {
|
||||
if (err.name === 'Canceled') {
|
||||
return; // ignore canceled errors that are common
|
||||
}
|
||||
|
||||
let stack = (err ? err.stack : null);
|
||||
if (!stack) {
|
||||
stack = new Error().stack;
|
||||
}
|
||||
|
||||
_unexpectedErrors.push((err && err.message ? err.message : err) + '\n' + stack);
|
||||
};
|
||||
|
||||
process.on('uncaughtException', error => onUnexpectedError(error));
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
onUnexpectedError(reason);
|
||||
promise.catch(() => { });
|
||||
});
|
||||
window.addEventListener('unhandledrejection', event => {
|
||||
event.preventDefault(); // Do not log to test output, we show an error later when test ends
|
||||
event.stopPropagation();
|
||||
|
||||
if (!_allowedTestsWithUnhandledRejections.has(currentTest.title)) {
|
||||
onUnexpectedError(event.reason);
|
||||
}
|
||||
});
|
||||
|
||||
errors.setUnexpectedErrorHandler(err => unexpectedErrorHandler(err));
|
||||
});
|
||||
|
||||
//#endregion
|
||||
|
||||
return loadWorkbenchTestingUtilsModule().then((workbenchTestingModule) => {
|
||||
const assertCleanState = workbenchTestingModule.assertCleanState;
|
||||
|
||||
@@ -209,24 +286,30 @@ function loadTests(opts) {
|
||||
});
|
||||
});
|
||||
|
||||
return loadTestModules(opts).then(() => {
|
||||
suite('Unexpected Errors & Loader Errors', function () {
|
||||
test('should not have unexpected errors', function () {
|
||||
const errors = _unexpectedErrors.concat(_loaderErrors);
|
||||
if (errors.length) {
|
||||
errors.forEach(function (stack) {
|
||||
console.error('');
|
||||
console.error(stack);
|
||||
});
|
||||
assert.ok(false, errors.join());
|
||||
}
|
||||
});
|
||||
teardown(async () => {
|
||||
|
||||
test('assertCleanState - check that registries are clean and objects are disposed at the end of test running', () => {
|
||||
assertCleanState();
|
||||
});
|
||||
});
|
||||
// should not have unexpected output
|
||||
if (_testsWithUnexpectedOutput && !opts.dev) {
|
||||
assert.ok(false, 'Error: Unexpected console output in test run. Please ensure no console.[log|error|info|warn] usage in tests or runtime errors.');
|
||||
}
|
||||
|
||||
// should not have unexpected errors
|
||||
const errors = _unexpectedErrors.concat(_loaderErrors);
|
||||
if (errors.length) {
|
||||
for (const error of errors) {
|
||||
console.error(`Error: Test run should not have unexpected errors:\n${error}`);
|
||||
}
|
||||
assert.ok(false, 'Error: Test run should not have unexpected errors.');
|
||||
}
|
||||
});
|
||||
|
||||
suiteTeardown(() => { // intentionally not in teardown because some tests only cleanup in suiteTeardown
|
||||
|
||||
// should have cleaned up in registries
|
||||
assertCleanState();
|
||||
});
|
||||
|
||||
return loadTestModules(opts);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -338,9 +421,10 @@ function runTests(opts) {
|
||||
});
|
||||
});
|
||||
|
||||
runner.on('test', test => currentTest = test);
|
||||
|
||||
if (opts.dev) {
|
||||
runner.on('fail', (test, err) => {
|
||||
|
||||
console.error(test.fullTitle());
|
||||
console.error(err.stack);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user