runner.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. const { PORT } = require('./common');
  11. const DEBUG_TESTS = process.argv.includes('--debug-tests');
  12. const REPO_ROOT = path.join(__dirname, '../../');
  13. yaserver
  14. .createServer({
  15. rootDir: REPO_ROOT
  16. })
  17. .then((staticServer) => {
  18. const server = http.createServer((request, response) => {
  19. return staticServer.handle(request, response);
  20. });
  21. server.listen(PORT, '127.0.0.1', async () => {
  22. try {
  23. await runTests();
  24. console.log(`All good`);
  25. process.exit(0);
  26. } catch (err) {
  27. console.error(err);
  28. process.exit(1);
  29. }
  30. });
  31. });
  32. async function runTests() {
  33. // uncomment to shortcircuit and run a specific combo
  34. // await runTest('webpack', 'chromium'); return;
  35. for (const type of ['amd', 'webpack']) {
  36. await runTest(type, 'chromium');
  37. await runTest(type, 'firefox');
  38. // await runTest(type, 'webkit');
  39. }
  40. }
  41. /**
  42. * @param {string} type
  43. * @param {'chromium'|'firefox'|'webkit'} browser
  44. * @returns
  45. */
  46. function runTest(type, browser) {
  47. return new Promise((resolve, reject) => {
  48. const env = { BROWSER: browser, TESTS_TYPE: type, ...process.env };
  49. if (DEBUG_TESTS) {
  50. env['DEBUG_TESTS'] = 'true';
  51. }
  52. const proc = cp.spawn(
  53. 'node',
  54. [
  55. path.join(REPO_ROOT, 'node_modules/mocha/bin/mocha'),
  56. 'test/smoke/*.test.js',
  57. '--no-delay',
  58. '--headless',
  59. '--timeout',
  60. '20000'
  61. ],
  62. {
  63. env,
  64. stdio: 'inherit'
  65. }
  66. );
  67. proc.on('error', reject);
  68. proc.on('exit', (code) => {
  69. if (code === 0) {
  70. resolve();
  71. } else {
  72. reject(code);
  73. }
  74. });
  75. });
  76. }