index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. const fakeConsole = {}
  35. for (const k in console) {
  36. if (console.hasOwnProperty(k) && k !== 'assert') {
  37. fakeConsole[k] = (...args) => ipcRenderer.send('console-call', k, args)
  38. }
  39. }
  40. global.__defineGetter__('console', function () {
  41. return fakeConsole
  42. })
  43. }
  44. const Mocha = require('mocha')
  45. const mochaOptions = {}
  46. if (process.env.MOCHA_REPORTER) {
  47. mochaOptions.reporter = process.env.MOCHA_REPORTER
  48. }
  49. if (process.env.MOCHA_MULTI_REPORTERS) {
  50. mochaOptions.reporterOptions = {
  51. reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
  52. }
  53. }
  54. const mocha = new Mocha(mochaOptions)
  55. if (!process.env.MOCHA_REPORTER) {
  56. mocha.ui('bdd').reporter(isCi ? 'tap' : 'html')
  57. }
  58. mocha.timeout(isCi ? 30000 : 10000)
  59. const query = Mocha.utils.parseQuery(window.location.search || '')
  60. if (query.grep) mocha.grep(query.grep)
  61. if (query.invert) mocha.invert()
  62. // Read all test files.
  63. const walker = require('walkdir').walk(path.dirname(__dirname), {
  64. no_recurse: true
  65. })
  66. const crashSpec = 'api-crash-reporter-spec.js'
  67. // This allows you to run specific modules only:
  68. // npm run test -match=menu
  69. const moduleMatch = process.env.npm_config_match
  70. ? new RegExp(process.env.npm_config_match, 'g')
  71. : null
  72. const testFiles = []
  73. walker.on('file', (file) => {
  74. if (/-spec\.js$/.test(file) && !file.includes(crashSpec) &&
  75. (!moduleMatch || moduleMatch.test(file))) {
  76. testFiles.push(file)
  77. }
  78. })
  79. walker.on('end', () => {
  80. testFiles.sort()
  81. testFiles.forEach((file) => mocha.addFile(file))
  82. if (!process.env.npm_config_match || new RegExp(process.env.npm_config_match, 'g').test(crashSpec)) {
  83. mocha.addFile(path.resolve(__dirname, '..', crashSpec))
  84. }
  85. const runner = mocha.run(() => {
  86. // Ensure the callback is called after runner is defined
  87. setTimeout(() => {
  88. Mocha.utils.highlightTags('code')
  89. if (isCi) ipcRenderer.send('process.exit', runner.failures)
  90. }, 0)
  91. })
  92. })
  93. })()
  94. </script>
  95. </body>
  96. </html>