MCPcopy Create free account
hub / github.com/cfworker/cfworker / loadMocha

Method loadMocha

packages/dev/src/test-host.js:77–113  ·  view source on GitHub ↗

* @param {import('puppeteer').Page} page * @param {string} pathnamePrefix

(page, pathnamePrefix)

Source from the content-addressed store, hash-verified

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}

Callers 1

runTestsMethod · 0.95

Calls 1

addEventListenerFunction · 0.85

Tested by

no test coverage detected