routes.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const html = require('choo/html');
  2. const assets = require('../../common/assets');
  3. const initScript = require('../../server/initScript');
  4. module.exports = function(app) {
  5. app.get('/mocha.css', function(req, res) {
  6. res.sendFile(require.resolve('mocha/mocha.css'));
  7. });
  8. app.get('/mocha.js', function(req, res) {
  9. res.sendFile(require.resolve('mocha/mocha.js'));
  10. });
  11. app.get('/test', function(req, res) {
  12. res.send(
  13. html`
  14. <!DOCTYPE html>
  15. <html>
  16. <head>
  17. <link rel="stylesheet" type="text/css" href="/mocha.css" />
  18. <script src="/mocha.js"></script>
  19. <script>
  20. const reporters = mocha.constructor.reporters;
  21. function Combo(runner) {
  22. reporters.HTML.call(this, runner);
  23. reporters.JSON.call(this, runner);
  24. }
  25. Object.setPrototypeOf(Combo.prototype, reporters.HTML.prototype);
  26. mocha.setup({
  27. ui: 'bdd',
  28. reporter: Combo,
  29. timeout: 5000
  30. });
  31. </script>
  32. ${initScript({
  33. cspNonce: 'test',
  34. locale: 'en-US'
  35. })}
  36. <script src="${assets.get('tests.js')}"></script>
  37. </head>
  38. <body>
  39. <div id="mocha"></div>
  40. <script>
  41. window.runner = mocha.run();
  42. </script>
  43. </body>
  44. </html>
  45. `.toString()
  46. );
  47. });
  48. };