index.html 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <html>
  2. <head>
  3. <meta name="referrer" content="always">
  4. <link href="../node_modules/mocha/mocha.css" rel="stylesheet">
  5. <script src="jquery-2.0.3.min.js"></script>
  6. </head>
  7. <body>
  8. <div id="mocha"></div>
  9. <script type="text/javascript" charset="utf-8">
  10. (function() {
  11. // Deprecated APIs are still supported and should be tested.
  12. process.throwDeprecation = false
  13. const path = require('path')
  14. const electron = require('electron')
  15. const { remote, ipcRenderer } = electron
  16. // Set up chai-as-promised here first to avoid conflicts
  17. // It must be loaded first or really strange things happen inside
  18. // chai that cause test failures
  19. // DO NOT MOVE, REMOVE OR EDIT THIS LINE
  20. require('chai').use(require('chai-as-promised'))
  21. // Check if we are running in CI.
  22. const isCi = remote.getGlobal('isCi')
  23. if (!isCi) {
  24. const win = remote.getCurrentWindow()
  25. win.show()
  26. win.focus()
  27. }
  28. // Show DevTools.
  29. document.oncontextmenu = (e) => {
  30. remote.getCurrentWindow().inspectElement(e.clientX, e.clientY)
  31. }
  32. // Rediret all output to browser.
  33. if (isCi) {
  34. global.__defineGetter__('console', function () {
  35. return {
  36. log: (...args) => ipcRenderer.send('console.log', args),
  37. error: (...args) => ipcRenderer.send('console.error', args)
  38. }
  39. })
  40. }
  41. const Mocha = require('mocha')
  42. const mochaOptions = {}
  43. if (process.env.MOCHA_REPORTER) {
  44. mochaOptions.reporter = process.env.MOCHA_REPORTER
  45. }
  46. if (process.env.MOCHA_MULTI_REPORTERS) {
  47. mochaOptions.reporterOptions = {
  48. reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
  49. }
  50. }
  51. const mocha = new Mocha(mochaOptions)
  52. if (!process.env.MOCHA_REPORTER) {
  53. mocha.ui('bdd').reporter(isCi ? 'tap' : 'html')
  54. }
  55. mocha.timeout(isCi ? 30000 : 10000)
  56. const query = Mocha.utils.parseQuery(window.location.search || '')
  57. if (query.grep) mocha.grep(query.grep)
  58. if (query.invert) mocha.invert()
  59. // Read all test files.
  60. const walker = require('walkdir').walk(path.dirname(__dirname), {
  61. no_recurse: true
  62. })
  63. const crashSpec = 'api-crash-reporter-spec.js'
  64. // This allows you to run specific modules only:
  65. // npm run test -match=menu
  66. const moduleMatch = process.env.npm_config_match
  67. ? new RegExp(process.env.npm_config_match, 'g')
  68. : null
  69. const testFiles = []
  70. walker.on('file', (file) => {
  71. if (/-spec\.js$/.test(file) && !file.includes(crashSpec) &&
  72. (!moduleMatch || moduleMatch.test(file))) {
  73. testFiles.push(file)
  74. }
  75. })
  76. walker.on('end', () => {
  77. testFiles.sort()
  78. testFiles.forEach((file) => mocha.addFile(file))
  79. if (!process.env.npm_config_match || new RegExp(process.env.npm_config_match, 'g').test(crashSpec)) {
  80. mocha.addFile(path.resolve(__dirname, '..', crashSpec))
  81. }
  82. const runner = mocha.run(() => {
  83. // Ensure the callback is called after runner is defined
  84. setTimeout(() => {
  85. if (isCi && runner.hasOnly) {
  86. try {
  87. throw new Error('A spec contains a call to it.only or describe.only and should be reverted.')
  88. } catch (error) {
  89. console.error(error.stack || error)
  90. }
  91. ipcRenderer.send('process.exit', 1)
  92. return
  93. }
  94. Mocha.utils.highlightTags('code')
  95. if (isCi) {
  96. ipcRenderer.send('process.exit', runner.failures)
  97. }
  98. }, 0)
  99. })
  100. })
  101. })()
  102. </script>
  103. </body>
  104. </html>