* @param {import('puppeteer').Page} page * @param {string} pathnamePrefix
(page, pathnamePrefix)
| 75 | * @param {string} pathnamePrefix |
| 76 | */ |
| 77 | async loadMocha(page, pathnamePrefix) { |
| 78 | await page.evaluate(() => (document.body.id = 'mocha')); |
| 79 | await page.addStyleTag({ |
| 80 | url: `${pathnamePrefix}/node_modules/mocha/mocha.css` |
| 81 | }); |
| 82 | await page.addScriptTag({ |
| 83 | url: `${pathnamePrefix}/node_modules/chai/chai.js` |
| 84 | }); |
| 85 | await page.addScriptTag({ |
| 86 | url: `${pathnamePrefix}/node_modules/mocha/mocha.js` |
| 87 | }); |
| 88 | await page.evaluate( |
| 89 | (inspect, mochaGlobals) => { |
| 90 | mocha.setup({ |
| 91 | ui: 'bdd', |
| 92 | reporter: inspect ? 'html' : 'spec', |
| 93 | color: !this.inspect |
| 94 | }); |
| 95 | |
| 96 | mocha.checkLeaks(); |
| 97 | |
| 98 | // Expose mocha globals on the mocha object, to enable `import { describe } from 'mocha';` |
| 99 | // in the browser version of mocha. |
| 100 | // https://github.com/mochajs/mocha/issues/2765 |
| 101 | for (const name of mochaGlobals) { |
| 102 | // @ts-ignore |
| 103 | mocha[name] = self[name]; |
| 104 | } |
| 105 | |
| 106 | // mocha doesn't catch unhandledrejections yet. |
| 107 | // https://github.com/mochajs/mocha/issues/2640 |
| 108 | addEventListener('unhandledrejection', event => event.reason); |
| 109 | }, |
| 110 | this.inspect, |
| 111 | this.mochaGlobals |
| 112 | ); |
| 113 | } |
| 114 | } |
no test coverage detected