({ page, webpackServer, waitForMswActivation }, use)
| 92 | use(await getWebpackServer()) |
| 93 | }, |
| 94 | async loadExample({ page, webpackServer, waitForMswActivation }, use) { |
| 95 | const pageExceptions: Array<Error> = [] |
| 96 | page.on('pageerror', (error) => pageExceptions.push(error)) |
| 97 | |
| 98 | const workerConsole = new WorkerConsole() |
| 99 | let compilation: Compilation | undefined |
| 100 | |
| 101 | await use(async (entry, options = {}) => { |
| 102 | const resolvedEntry = |
| 103 | entry instanceof URL ? url.fileURLToPath(entry) : entry |
| 104 | |
| 105 | compilation = await webpackServer.compile( |
| 106 | Array.prototype.concat([], resolvedEntry), |
| 107 | options, |
| 108 | ) |
| 109 | |
| 110 | // Allow arbitrary setup code before navigating to the compilation preview. |
| 111 | // This is useful to set up console watchers and other side-effects. |
| 112 | options.beforeNavigation?.(compilation) |
| 113 | |
| 114 | // Forward browser runtime errors/warnings to the test runner. |
| 115 | page.on('pageerror', console.error) |
| 116 | |
| 117 | const oncePageReady = [ |
| 118 | page.waitForLoadState('domcontentloaded', { timeout: 15_000 }), |
| 119 | page.waitForEvent('load', { timeout: 30_000 }), |
| 120 | page.waitForLoadState('networkidle', { timeout: 5_000 }), |
| 121 | ] |
| 122 | page.goto(compilation.previewUrl) |
| 123 | await Promise.all(oncePageReady) |
| 124 | |
| 125 | // All examples await the MSW activation message by default. |
| 126 | // Support opting-out from this behavior for tests where activation |
| 127 | // is not expected (e.g. when testing activation errors). |
| 128 | if (!options.skipActivation) { |
| 129 | await waitForMswActivation() |
| 130 | } |
| 131 | |
| 132 | await workerConsole.init(page) |
| 133 | |
| 134 | return { |
| 135 | compilation, |
| 136 | workerConsole, |
| 137 | } |
| 138 | }) |
| 139 | |
| 140 | workerConsole.removeAllListeners() |
| 141 | await compilation?.dispose() |
| 142 | }, |
| 143 | async waitFor({}, use) { |
| 144 | await use(waitFor) |
| 145 | }, |
no test coverage detected
searching dependent graphs…