index.html 3.1 KB

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