1
0

runner.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. //@ts-check
  6. const yaserver = require('yaserver');
  7. const http = require('http');
  8. const cp = require('child_process');
  9. const path = require('path');
  10. /** @typedef {import('./common').BrowserKind} BrowserKind */
  11. /** @typedef {import('./common').PackagerKind} PackagerKind */
  12. /** @typedef {import('./common').TestInfo} TestInfo */
  13. const DEBUG_TESTS = true; // process.argv.includes('--debug-tests');
  14. const REPO_ROOT = path.join(__dirname, '../../');
  15. const PORT = 8563;
  16. yaserver
  17. .createServer({
  18. rootDir: REPO_ROOT
  19. })
  20. .then((staticServer) => {
  21. const server = http.createServer((request, response) => {
  22. return staticServer.handle(request, response);
  23. });
  24. server.listen(PORT, '127.0.0.1', async () => {
  25. try {
  26. await runTests();
  27. console.log(`All good`);
  28. process.exit(0);
  29. } catch (err) {
  30. console.error(err);
  31. process.exit(1);
  32. }
  33. });
  34. });
  35. async function runTests() {
  36. // uncomment to shortcircuit and run a specific combo
  37. // await runTest('webpack', 'chromium'); return;
  38. /** @type {PackagerKind[]} */
  39. const testTypes = ['webpack'];
  40. // TODO: add parcel! (this currently fails because parcel replaces process with {})
  41. for (const type of testTypes) {
  42. await runTest(type, 'chromium');
  43. await runTest(type, 'firefox');
  44. await runTest(type, 'webkit');
  45. }
  46. }
  47. /**
  48. * @param {PackagerKind} packager
  49. * @param {BrowserKind} browser
  50. * @returns
  51. */
  52. function runTest(packager, browser) {
  53. return new Promise((resolve, reject) => {
  54. /** @type TestInfo */
  55. const testInfo = {
  56. browser,
  57. packager,
  58. debugTests: DEBUG_TESTS,
  59. port: PORT
  60. };
  61. const env = { MONACO_TEST_INFO: JSON.stringify(testInfo), ...process.env };
  62. const proc = cp.spawn(
  63. 'node',
  64. [
  65. path.join(REPO_ROOT, 'node_modules/mocha/bin/mocha'),
  66. 'test/smoke/*.test.js',
  67. '--no-delay',
  68. '--headless',
  69. '--timeout',
  70. '2000000'
  71. ],
  72. {
  73. env,
  74. stdio: 'inherit'
  75. }
  76. );
  77. proc.on('error', reject);
  78. proc.on('exit', (code) => {
  79. if (code === 0) {
  80. resolve(undefined);
  81. } else {
  82. reject(code);
  83. }
  84. });
  85. });
  86. }