index.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. // Check if we are running in CI.
  17. const isCi = remote.getGlobal('isCi')
  18. if (!isCi) {
  19. const win = remote.getCurrentWindow()
  20. win.show()
  21. win.focus()
  22. }
  23. // Show DevTools.
  24. document.oncontextmenu = (e) => {
  25. remote.getCurrentWindow().inspectElement(e.clientX, e.clientY)
  26. }
  27. // Rediret all output to browser.
  28. if (isCi) {
  29. global.__defineGetter__('console', function () {
  30. return {
  31. log: (...args) => ipcRenderer.send('console.log', args),
  32. error: (...args) => ipcRenderer.send('console.error', args)
  33. }
  34. })
  35. }
  36. const { Coverage } = require('electabul')
  37. const Mocha = require('mocha')
  38. const mochaOptions = {}
  39. if (process.env.MOCHA_REPORTER) {
  40. mochaOptions.reporter = process.env.MOCHA_REPORTER
  41. }
  42. if (process.env.MOCHA_MULTI_REPORTERS) {
  43. mochaOptions.reporterOptions = {
  44. reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
  45. }
  46. }
  47. const mocha = new Mocha(mochaOptions)
  48. if (!process.env.MOCHA_REPORTER) {
  49. mocha.ui('bdd').reporter(isCi ? 'tap' : 'html')
  50. }
  51. mocha.timeout(isCi ? 30000 : 10000)
  52. const query = Mocha.utils.parseQuery(window.location.search || '')
  53. if (query.grep) mocha.grep(query.grep)
  54. if (query.invert) mocha.invert()
  55. // Read all test files.
  56. const walker = require('walkdir').walk(path.dirname(__dirname), {
  57. no_recurse: true
  58. })
  59. const crashSpec = 'api-crash-reporter-spec.js'
  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. walker.on('file', (file) => {
  66. if (/-spec\.js$/.test(file) && !file.includes(crashSpec) &&
  67. (!moduleMatch || moduleMatch.test(file))) {
  68. mocha.addFile(file)
  69. }
  70. })
  71. walker.on('end', () => {
  72. if (!process.env.npm_config_match || new RegExp(process.env.npm_config_match, 'g').test(crashSpec)) {
  73. mocha.addFile(path.resolve(__dirname, '..', crashSpec))
  74. }
  75. const runner = mocha.run(() => {
  76. if (isCi && runner.hasOnly) {
  77. try {
  78. throw new Error('A spec contains a call to it.only or describe.only and should be reverted.')
  79. } catch (error) {
  80. console.error(error.stack || error)
  81. }
  82. ipcRenderer.send('process.exit', 1)
  83. return
  84. }
  85. Mocha.utils.highlightTags('code')
  86. const coverage = new Coverage({
  87. libPath: path.join(__dirname, '..', '..', 'lib'),
  88. outputPath: path.join(__dirname, '..', '..', 'out', 'coverage'),
  89. formats: ['text', 'lcov']
  90. })
  91. coverage.addCoverage(ipcRenderer.sendSync('get-main-process-coverage'))
  92. coverage.generateReport()
  93. if (isCi) {
  94. ipcRenderer.send('process.exit', runner.failures)
  95. }
  96. })
  97. })
  98. })()
  99. </script>
  100. </body>
  101. </html>