33// This file is licensed under the MIT License.
44// License text available at https://opensource.org/licenses/MIT
55
6+ import fs from 'node:fs' ;
7+ import path from 'node:path' ;
8+ import url from 'node:url' ;
69import { expect , skipIf } from '@loopback/testlab' ;
7- import fs from 'fs' ;
8- import { Suite } from 'mocha' ;
9- import path from 'path' ;
10- import puppeteer , { Browser } from 'puppeteer' ;
11- import url from 'url' ;
10+ import puppeteer from 'puppeteer' ;
1211import { generateBundle } from './test-helper' ;
1312
14- //
1513/*
1614 * `zombie` fails to load the html file url with 404 on Windows
1715 * 1) bundle-web.js
@@ -22,45 +20,51 @@ import {generateBundle} from './test-helper';
2220 *
2321 * See https://github.com/assaf/zombie/issues/915
2422 */
25- skipIf < [ ( this : Suite ) => void ] , void > (
23+ skipIf (
2624 process . platform === 'win32' , // Skip on Windows
2725 describe ,
2826 'bundle-web.js' ,
2927 ( ) => {
30- before ( 'generate bundle-web.js' , async function ( this : Mocha . Context ) {
31- // It may take some time to generate the bundle using webpack
32- this . timeout ( 30000 ) ;
33- await generateBundle ( 'web' ) ;
34- expect (
35- fs . existsSync ( path . join ( __dirname , '../../bundle-web.js' ) ) ,
36- ) . to . be . true ( ) ;
37- } ) ;
38-
39- let browser : Browser ;
4028 let html : string ;
41- before ( async function ( this : Mocha . Context ) {
42- this . timeout ( 15000 ) ;
43- browser = await puppeteer . launch ( { headless : 'new' } ) ;
44- const page = await browser . newPage ( ) ;
45- await page . goto (
46- url
47- . pathToFileURL ( path . join ( __dirname , '../../../index.html' ) )
48- . toString ( ) ,
49- { waitUntil : 'networkidle2' } ,
50- ) ;
51- html = await page . content ( ) ;
52- /*
53- const bodyHandle = await page.$('body');
54- html = await page.evaluate(body => body.innerHTML, bodyHandle);
55- await bodyHandle!.dispose();
56- */
5729
58- await browser . close ( ) ;
59- } ) ;
30+ before (
31+ 'generate bundle-web.js' ,
32+ /** @this {Mocha.Context} */ async function ( ) {
33+ // It may take some time to generate the bundle using webpack
34+ this . timeout ( 30000 ) ;
35+ await generateBundle ( 'web' ) ;
36+ expect (
37+ fs . existsSync ( path . join ( __dirname , '../../bundle-web.js' ) ) ,
38+ ) . to . be . true ( ) ;
39+ } ,
40+ ) ;
41+
42+ before (
43+ /** @this {Mocha.Context} */ async function ( ) {
44+ this . timeout ( 15000 ) ;
45+ const browser = await puppeteer . launch ( { headless : 'new' } ) ;
46+ const page = await browser . newPage ( ) ;
47+ await page . goto (
48+ url
49+ . pathToFileURL ( path . join ( __dirname , '../../../index.html' ) )
50+ . toString ( ) ,
51+ { waitUntil : 'networkidle2' } ,
52+ ) ;
53+ html = await page . content ( ) ;
54+
55+ /*
56+ const bodyHandle = await page.$('body');
57+ html = await page.evaluate(body => body.innerHTML, bodyHandle);
58+ await bodyHandle!.dispose();
59+ */
60+
61+ await browser . close ( ) ;
62+ } ,
63+ ) ;
6064
6165 it ( 'should see the page with greetings' , ( ) => {
6266 let body = html ;
63- body = body . replace ( / \[ [ ^ \[ \] ] + \ ] / g, '' ) ;
67+ body = body . replace ( / \[ [ ^ \[ \] ] + ] / g, '' ) ;
6468 expect ( body ) . to . match ( / < l i > \( e n \) H e l l o , J a n e ! < \/ l i > / ) ;
6569 expect ( body ) . to . match ( / < l i > H e l l o , J o h n ! < \/ l i > / ) ;
6670 expect ( body ) . to . match ( / < l i > \( z h \) 你 好 , J o h n ! < \/ l i > / ) ;
0 commit comments