runner.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. const yaserver = require('yaserver');
  6. const http = require('http');
  7. const cp = require('child_process');
  8. const PORT = 8563;
  9. yaserver.createServer({
  10. rootDir: __dirname
  11. }).then((staticServer) => {
  12. const server = http.createServer((request, response) => {
  13. return staticServer.handle(request, response);
  14. });
  15. server.listen(PORT, '127.0.0.1', () => {
  16. runTests().then(() => {
  17. console.log(`All good`);
  18. process.exit(0);
  19. }, (err) => {
  20. console.error(err);
  21. process.exit(1);
  22. });
  23. });
  24. });
  25. function runTests() {
  26. return (
  27. runTest('chromium')
  28. .then(() => runTest('firefox'))
  29. // .then(() => runTest('webkit'))
  30. );
  31. }
  32. function runTest(browser) {
  33. return new Promise((resolve, reject) => {
  34. const proc = cp.spawn('node', ['../../node_modules/mocha/bin/mocha', 'out/*.test.js', '--headless'], {
  35. env: { BROWSER: browser, ...process.env },
  36. stdio: 'inherit'
  37. });
  38. proc.on('error', reject);
  39. proc.on('exit', (code) => {
  40. if (code === 0) {
  41. resolve();
  42. } else {
  43. reject(code);
  44. }
  45. });
  46. });
  47. }