index.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <body>
  2. <script src="jquery-2.0.3.min.js"></script>
  3. <script type="text/javascript" charset="utf-8">
  4. (async function() {
  5. // Deprecated APIs are still supported and should be tested.
  6. process.throwDeprecation = false
  7. const Module = require('module');
  8. const path = require('path')
  9. const electron = require('electron')
  10. const { ipcRenderer } = electron
  11. // Extra module paths which can be used to load Mocha reporters
  12. if (process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS) {
  13. for (const modulePath of process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS.split(':')) {
  14. Module.globalPaths.push(modulePath);
  15. }
  16. }
  17. // Set up chai-as-promised here first to avoid conflicts
  18. // It must be loaded first or really strange things happen inside
  19. // chai that cause test failures
  20. // DO NOT MOVE, REMOVE OR EDIT THIS LINE
  21. require('chai').use(require('chai-as-promised'))
  22. // Rediret all output to browser.
  23. const fakeConsole = {}
  24. for (const k in console) {
  25. if (console.hasOwnProperty(k) && k !== 'assert') {
  26. fakeConsole[k] = (...args) => ipcRenderer.send('console-call', k, args)
  27. }
  28. }
  29. global.__defineGetter__('console', function () {
  30. return fakeConsole
  31. })
  32. const Mocha = require('mocha')
  33. const mochaOptions = {}
  34. if (process.env.MOCHA_REPORTER) {
  35. mochaOptions.reporter = process.env.MOCHA_REPORTER
  36. }
  37. if (process.env.MOCHA_MULTI_REPORTERS) {
  38. mochaOptions.reporterOptions = {
  39. reporterEnabled: process.env.MOCHA_MULTI_REPORTERS
  40. }
  41. }
  42. const mocha = new Mocha(mochaOptions)
  43. if (!process.env.MOCHA_REPORTER) {
  44. mocha.ui('bdd').reporter('tap')
  45. }
  46. const mochaTimeout = process.env.MOCHA_TIMEOUT || 30000
  47. mocha.timeout(mochaTimeout)
  48. const query = Mocha.utils.parseQuery(window.location.search || '')
  49. if (query.grep) mocha.grep(query.grep)
  50. if (query.invert) mocha.invert()
  51. const filter = (file) => {
  52. if (!/-spec\.js$/.test(file)) {
  53. return false
  54. }
  55. // This allows you to run specific modules only:
  56. // npm run test -match=menu
  57. const moduleMatch = process.env.npm_config_match
  58. ? new RegExp(process.env.npm_config_match, 'g')
  59. : null
  60. if (moduleMatch && !moduleMatch.test(file)) {
  61. return false
  62. }
  63. const files = query.files ? query.files.split(',') : undefined
  64. const baseElectronDir = path.resolve(__dirname, '..', '..')
  65. if (files && !files.includes(path.relative(baseElectronDir, file))) {
  66. return false
  67. }
  68. return true
  69. }
  70. const getFiles = require('./get-files')
  71. const testFiles = await getFiles(path.dirname(__dirname), { filter })
  72. testFiles.sort().forEach((file) => {
  73. mocha.addFile(file)
  74. })
  75. // Set up chai in the correct order
  76. const chai = require('chai')
  77. chai.use(require('chai-as-promised'))
  78. chai.use(require('dirty-chai'))
  79. // Show full object diff
  80. // https://github.com/chaijs/chai/issues/469
  81. chai.config.truncateThreshold = 0;
  82. const runner = mocha.run(() => {
  83. // Ensure the callback is called after runner is defined
  84. setTimeout(() => {
  85. ipcRenderer.send('process.exit', runner.failures)
  86. }, 0)
  87. })
  88. })()
  89. </script>
  90. </body>