Skip to content

Commit dc03796

Browse files
committed
wip
1 parent 6dab2e2 commit dc03796

File tree

4 files changed

+55
-59
lines changed

4 files changed

+55
-59
lines changed

examples/webpack/index.html

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,23 @@
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>
8-
<div id="greetings"></div>
7+
<div id="greetings">
8+
<h1>Hello from LoopBack</h1>
9+
</div>
910

11+
<script src="dist/bundle-web.js"></script>
1012
<script>
11-
async function greet() {
12-
const element = document.getElementById('greetings');
13-
13+
(async () => {
1414
// Exported TypeScript functions/classes/types/constants are now
1515
// available under `LoopBack` namespace
1616
const greetings = await LoopBack.main();
17-
18-
const list = greetings.map(g => `<li>${g}</li>`);
19-
element.innerHTML = `
20-
<h1>Hello from LoopBack</h1>
21-
<p/>
22-
<ul>
23-
${list.join('\n')}
24-
</ul>`;
25-
return greetings;
26-
}
27-
28-
greet().catch(err => alert(err));
17+
const element = document.getElementById('greetings');
18+
const listEl = document.createElement('ul')
19+
const collectionEl = element.insertAdjacentElement('beforeend', listEl)
20+
greetings.forEach((val) => collectionEl.insertAdjacentHTML('beforeend', `<li>${val}</li>`))
21+
})().catch(err => alert(err));
2922
</script>
3023
</body>
3124
</html>

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

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
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';
10-
import puppeteer, {Browser} from 'puppeteer';
11-
import url from 'url';
10+
import puppeteer from 'puppeteer';
1211
import {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(/<li>\(en\) Hello, Jane!<\/li>/);
6569
expect(body).to.match(/<li>Hello, John!<\/li>/);
6670
expect(body).to.match(/<li>\(zh\) John<\/li>/);

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)