@@ -14,7 +14,6 @@ const WebpackConfig = require('../../lib/WebpackConfig');
1414const parseRuntime = require ( '../../lib/config/parse-runtime' ) ;
1515const webpack = require ( 'webpack' ) ;
1616const fs = require ( 'fs-extra' ) ;
17- const Browser = require ( 'zombie' ) ;
1817const httpServer = require ( 'http-server' ) ;
1918const configGenerator = require ( '../../lib/config-generator' ) ;
2019const validator = require ( '../../lib/config/validator' ) ;
@@ -142,18 +141,22 @@ function stopAllServers() {
142141 * makes a request to it, and executes a callback, passing that
143142 * the Browser instance used to make the request.
144143 *
144+ * @param {import('puppeteer').Browser } browser Puppeteer browser instance
145145 * @param {string } webRootDir Directory path (e.g. /path/to/public) where the web server should be rooted
146146 * @param {Array } scriptSrcs Used to create <script src=""> tags.
147- * @param {Function } callback Called after the page was requested.
148- * @returns {void }
147+ * @param {function({
148+ * page: import('puppeteer').Page,
149+ * loadedResources: Array<{ response: import('puppeteer').HTTPResponse }>}
150+ * ): void} callback Called after the page was requested.
151+ * @returns {Promise<void> }
149152 */
150- function requestTestPage ( webRootDir , scriptSrcs , callback ) {
153+ async function requestTestPage ( browser , webRootDir , scriptSrcs , callback ) {
151154 var scripts = '' ;
152155 for ( let scriptSrc of scriptSrcs ) {
153156 scripts += `<script src="${ scriptSrc } "></script>` ;
154157 }
155158
156- const testHtml = `
159+ const testHtml = `<!DOCTYPE html>
157160<html>
158161<head>
159162</head>
@@ -175,23 +178,31 @@ function requestTestPage(webRootDir, scriptSrcs, callback) {
175178 // start a secondary server - can be used as the "CDN"
176179 startHttpServer ( '8090' , webRootDir ) ;
177180
178- const browser = new Browser ( ) ;
179- browser . silent = true ;
180- browser . on ( 'error' , function ( error ) {
181- throw new Error ( `Error when running the browser: ${ error } ` ) ;
181+ const loadedResources = [ ] ;
182+
183+ const context = await browser . createBrowserContext ( ) ;
184+ const page = await context . newPage ( ) ;
185+
186+ page . on ( 'error' , ( error ) => {
187+ throw new Error ( `Error when running the browser: "${ error . message } ".` , { cause : error } ) ;
182188 } ) ;
183- browser . visit ( 'http://127.0.0.1:8080/testing.html' , ( ) => {
184- stopAllServers ( ) ;
185189
186- // sanity check for failed asset loading
187- for ( let resource of browser . resources ) {
188- if ( resource . response . status !== 200 ) {
189- throw new Error ( `Error: status code ${ resource . response . status } when requesting resource ${ resource . request . url } ` ) ;
190- }
191- }
190+ page . on ( 'requestfailed' , ( request ) => {
191+ throw new Error ( `Error "${ request . failure ( ) . errorText } " when requesting resource "${ request . url ( ) } ".` ) ;
192+ } ) ;
193+
194+ page . on ( 'response' , ( response ) => {
195+ loadedResources . push ( {
196+ response,
197+ } ) ;
198+ } ) ;
192199
193- callback ( browser ) ;
200+ await page . goto ( 'http://127.0.0.1:8080/testing.html' , {
201+ waitUntil : 'networkidle0' ,
194202 } ) ;
203+ stopAllServers ( ) ;
204+ await callback ( { page, loadedResources } ) ;
205+ await page . close ( ) ;
195206}
196207
197208module . exports = {
0 commit comments