index.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // Disable use of deprecated functions.
  12. process.throwDeprecation = true
  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 mocha = new Mocha(process.env.MOCHA_REPORTER
  39. ? { reporter: process.env.MOCHA_REPORTER }
  40. : undefined)
  41. if (!process.env.MOCHA_REPORTER) {
  42. mocha.ui('bdd').reporter(isCi ? 'tap' : 'html')
  43. }
  44. mocha.timeout(isCi ? 30000 : 10000)
  45. const query = Mocha.utils.parseQuery(window.location.search || '')
  46. if (query.grep) mocha.grep(query.grep)
  47. if (query.invert) mocha.invert()
  48. // Read all test files.
  49. const walker = require('walkdir').walk(path.dirname(__dirname), {
  50. no_recurse: true
  51. })
  52. const crashSpec = 'api-crash-reporter-spec.js'
  53. // This allows you to run specific modules only:
  54. // npm run test -match=menu
  55. const moduleMatch = process.env.npm_config_match
  56. ? new RegExp(process.env.npm_config_match, 'g')
  57. : null
  58. walker.on('file', (file) => {
  59. if (/-spec\.js$/.test(file) && !file.includes(crashSpec) &&
  60. (!moduleMatch || moduleMatch.test(file))) {
  61. mocha.addFile(file)
  62. }
  63. })
  64. walker.on('end', () => {
  65. if (!process.env.npm_config_match || new RegExp(process.env.npm_config_match, 'g').test(crashSpec)) {
  66. mocha.addFile(path.resolve(__dirname, '..', crashSpec))
  67. }
  68. const runner = mocha.run(() => {
  69. if (isCi && runner.hasOnly) {
  70. try {
  71. throw new Error('A spec contains a call to it.only or describe.only and should be reverted.')
  72. } catch (error) {
  73. console.error(error.stack || error)
  74. }
  75. ipcRenderer.send('process.exit', 1)
  76. return
  77. }
  78. Mocha.utils.highlightTags('code')
  79. const coverage = new Coverage({
  80. libPath: path.join(__dirname, '..', '..', 'lib'),
  81. outputPath: path.join(__dirname, '..', '..', 'out', 'coverage'),
  82. formats: ['text', 'lcov']
  83. })
  84. coverage.addCoverage(ipcRenderer.sendSync('get-main-process-coverage'))
  85. coverage.generateReport()
  86. if (isCi) {
  87. ipcRenderer.send('process.exit', runner.failures)
  88. }
  89. })
  90. })
  91. })()
  92. </script>
  93. </body>
  94. </html>