runner.cjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. /*---------------------------------------------------------
  3. * Copyright (C) Microsoft Corporation. All rights reserved.
  4. *--------------------------------------------------------*/
  5. var __importDefault = (this && this.__importDefault) || function (mod) {
  6. return (mod && mod.__esModule) ? mod : { "default": mod };
  7. };
  8. Object.defineProperty(exports, "__esModule", { value: true });
  9. exports.run = run;
  10. const mocha_1 = __importDefault(require("mocha"));
  11. async function run() {
  12. const { mochaOpts, files, preload, colorDefault, } = JSON.parse(process.env.VSCODE_TEST_OPTIONS);
  13. // Create the mocha test
  14. const mocha = new mocha_1.default({
  15. ui: 'tdd',
  16. color: colorDefault,
  17. ...mochaOpts,
  18. });
  19. const required = [
  20. ...preload,
  21. ...ensureArray(mochaOpts.require),
  22. ].map((f) => require(normalizeCasing(f)));
  23. // currently `require` only seems to take effect for parallel runs, but remove
  24. // the option in case it's supported for serial runs in the future since we're
  25. // handling it ourselves.
  26. delete mochaOpts.require;
  27. for (const { mochaGlobalSetup } of required) {
  28. await mochaGlobalSetup?.();
  29. }
  30. for (const file of files) {
  31. mocha.addFile(normalizeCasing(file));
  32. }
  33. await new Promise((resolve, reject) => mocha.run((failures) => failures
  34. ? reject(failures > 1 ? `${failures} tests failed.` : `${failures} test failed.`)
  35. : resolve()));
  36. for (const { mochaGlobalTeardown } of required) {
  37. await mochaGlobalTeardown?.();
  38. }
  39. }
  40. const normalizeCasing = (path) => {
  41. // Normalize to lower-case drive letter to avoid path sensitivity in the loader
  42. // duplicating imports. VS Code normalizes to lower case drive letters in its
  43. // URIs, so do the same here
  44. // https://github.com/microsoft/vscode/blob/032c1b75447ade317715c3d2a82c2d9cd3e55dde/src/vs/base/common/uri.ts#L181-L185
  45. if (process.platform === 'win32' && path.match(/^[A-Z]:/)) {
  46. return path[0].toLowerCase() + path.slice(1);
  47. }
  48. return path;
  49. };
  50. const ensureArray = (value) => value ? (Array.isArray(value) ? value : [value]) : [];