index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const Module = require('module')
  2. const path = require('path')
  3. const v8 = require('v8')
  4. Module.globalPaths.push(path.resolve(__dirname, '../spec/node_modules'))
  5. // We want to terminate on errors, not throw up a dialog
  6. process.on('uncaughtException', (err) => {
  7. console.error('Unhandled exception in main spec runner:', err)
  8. process.exit(1)
  9. })
  10. // Tell ts-node which tsconfig to use
  11. process.env.TS_NODE_PROJECT = path.resolve(__dirname, '../tsconfig.spec.json')
  12. process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
  13. const { app, protocol } = require('electron')
  14. v8.setFlagsFromString('--expose_gc')
  15. app.commandLine.appendSwitch('js-flags', '--expose_gc')
  16. // Prevent the spec runner quiting when the first window closes
  17. app.on('window-all-closed', () => null)
  18. // Use fake device for Media Stream to replace actual camera and microphone.
  19. app.commandLine.appendSwitch('use-fake-device-for-media-stream')
  20. global.standardScheme = 'app'
  21. global.zoomScheme = 'zoom'
  22. protocol.registerSchemesAsPrivileged([
  23. { scheme: global.standardScheme, privileges: { standard: true, secure: true } },
  24. { scheme: global.zoomScheme, privileges: { standard: true, secure: true } },
  25. { scheme: 'cors-blob', privileges: { corsEnabled: true, supportFetchAPI: true } },
  26. { scheme: 'cors', privileges: { corsEnabled: true, supportFetchAPI: true } },
  27. { scheme: 'no-cors', privileges: { supportFetchAPI: true } },
  28. { scheme: 'no-fetch', privileges: { corsEnabled: true } }
  29. ])
  30. app.whenReady().then(async () => {
  31. require('ts-node/register')
  32. const argv = require('yargs')
  33. .boolean('ci')
  34. .string('g').alias('g', 'grep')
  35. .boolean('i').alias('i', 'invert')
  36. .argv
  37. const isCi = !!argv.ci
  38. global.isCI = isCi
  39. const Mocha = require('mocha')
  40. const mochaOptions = {}
  41. if (process.env.MOCHA_REPORTER) {
  42. mochaOptions.reporter = process.env.MOCHA_REPORTER
  43. }
  44. if (process.env.MOCHA_MULTI_REPORTERS) {
  45. mochaOptions.reporterOptions = {
  46. reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
  47. }
  48. }
  49. const mocha = new Mocha(mochaOptions)
  50. if (!process.env.MOCHA_REPORTER) {
  51. mocha.ui('bdd').reporter('tap')
  52. }
  53. mocha.timeout(isCi ? 30000 : 10000)
  54. if (argv.grep) mocha.grep(argv.grep)
  55. if (argv.invert) mocha.invert()
  56. const filter = (file) => {
  57. if (!/-spec\.[tj]s$/.test(file)) {
  58. return false
  59. }
  60. // This allows you to run specific modules only:
  61. // npm run test -match=menu
  62. const moduleMatch = process.env.npm_config_match
  63. ? new RegExp(process.env.npm_config_match, 'g')
  64. : null
  65. if (moduleMatch && !moduleMatch.test(file)) {
  66. return false
  67. }
  68. return true
  69. }
  70. const getFiles = require('../spec/static/get-files')
  71. const testFiles = await getFiles(__dirname, { filter })
  72. testFiles.sort()
  73. sortToEnd(testFiles, f => f.includes('crash-reporter')).forEach((file) => mocha.addFile(file))
  74. const cb = () => {
  75. // Ensure the callback is called after runner is defined
  76. process.nextTick(() => {
  77. process.exit(runner.failures)
  78. })
  79. }
  80. const runner = mocha.run(cb)
  81. })
  82. function partition (xs, f) {
  83. const trues = []
  84. const falses = []
  85. xs.forEach(x => (f(x) ? trues : falses).push(x))
  86. return [trues, falses]
  87. }
  88. function sortToEnd (xs, f) {
  89. const [end, beginning] = partition(xs, f)
  90. return beginning.concat(end)
  91. }