Skip to content

Commit 7989004

Browse files
committed
wip
1 parent 6dab2e2 commit 7989004

File tree

4 files changed

+48
-43
lines changed

4 files changed

+48
-43
lines changed

examples/webpack/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<html>
33
<head>
44
<title>LoopBack 4 Core Modules WebPack Demo</title>
5-
<script src="dist/bundle-web.js" charset="utf-8"></script>
65
</head>
76
<body>
87
<div id="greetings"></div>
98

9+
<script defer src="dist/bundle-web.js"></script>
1010
<script>
1111
async function greet() {
1212
const element = document.getElementById('greetings');

examples/webpack/src/__tests__/integration/bundle-web.integration.ts

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
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';
69
import {expect, skipIf} from '@loopback/testlab';
7-
import fs from 'fs';
8-
import {Suite} from 'mocha';
9-
import path from 'path';
1010
import puppeteer, {Browser} from 'puppeteer';
11-
import url from 'url';
1211
import {generateBundle} from './test-helper';
1312
1413
//
15-
/*
14+
/!*
1615
* `zombie` fails to load the html file url with 404 on Windows
1716
* 1) bundle-web.js
1817
* "before all" hook for "should see the page with greetings":
@@ -21,50 +20,57 @@ import {generateBundle} from './test-helper';
2120
* at process._tickCallback (internal/process/next_tick.js:68:7)
2221
*
2322
* See https://github.com/assaf/zombie/issues/915
24-
*/
25-
skipIf<[(this: Suite) => void], void>(
23+
*!/
24+
skipIf(
2625
process.platform === 'win32', // Skip on Windows
2726
describe,
2827
'bundle-web.js',
2928
() => {
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-
3929
let browser: Browser;
4030
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-
*/
5731
58-
await browser.close();
59-
});
32+
before(
33+
'generate bundle-web.js',
34+
/!** @this {Mocha.Context} *!/ async function () {
35+
// It may take some time to generate the bundle using webpack
36+
this.timeout(30000);
37+
await generateBundle('web');
38+
expect(
39+
fs.existsSync(path.join(__dirname, '../../bundle-web.js')),
40+
).to.be.true();
41+
},
42+
);
43+
44+
before(
45+
/!** @this {Mocha.Context} *!/ async function () {
46+
this.timeout(15000);
47+
browser = await puppeteer.launch({headless: 'new'});
48+
const page = await browser.newPage();
49+
await page.goto(
50+
url
51+
.pathToFileURL(path.join(__dirname, '../../../index.html'))
52+
.toString(),
53+
{waitUntil: 'networkidle2'},
54+
);
55+
html = await page.content();
56+
57+
/!*
58+
const bodyHandle = await page.$('body');
59+
html = await page.evaluate(body => body.innerHTML, bodyHandle);
60+
await bodyHandle!.dispose();
61+
*!/
62+
63+
await browser.close();
64+
},
65+
);
6066
6167
it('should see the page with greetings', () => {
6268
let body = html;
63-
body = body.replace(/\[[^\[\]]+\] /g, '');
69+
body = body.replace(/\[[^\[\]]+] /g, '');
6470
expect(body).to.match(/<li>\(en\) Hello, Jane!<\/li>/);
6571
expect(body).to.match(/<li>Hello, John!<\/li>/);
6672
expect(body).to.match(/<li>\(zh\) 你好,John!<\/li>/);
6773
expect(body).to.match(/<li>\(en\) Hello, Jane!<\/li>/);
6874
});
6975
},
70-
);
76+
);*/

examples/webpack/src/__tests__/integration/test-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
import path from 'node:path';
7+
import {once} from 'node:events';
68
import {expect} from '@loopback/testlab';
7-
import {once} from 'events';
8-
import path from 'path';
99

10-
const runShell = require('@loopback/build').runShell;
10+
const {runShell} = require('@loopback/build');
1111

1212
export function assertGreetings(greetings: string[]) {
13-
greetings = greetings.map(g => g.replace(/\[[^\[\]]+\] /, ''));
13+
greetings = greetings.map(g => g.replace(/\[[^\[\]]+] /, ''));
1414
expect(greetings).to.eql([
1515
'(en) Hello, Jane!',
1616
'Hello, John!',

examples/webpack/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
const path = require('path');
6+
const path = require('node:path');
77
const webpack = require('webpack');
88

99
/**
@@ -46,7 +46,6 @@ const nodeConfig = {
4646
*/
4747
const webConfig = {
4848
...baseConfig,
49-
5049
name: 'web',
5150
target: 'web', // For browsers
5251
output: {

0 commit comments

Comments
 (0)