Skip to content

Commit 371f46c

Browse files
committed
test: add tests for special use cases
1 parent acf88db commit 371f46c

File tree

10 files changed

+105
-0
lines changed

10 files changed

+105
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Hello World!</h1>
2+
<p><strong>bold</strong>
3+
<em>italic</em></p>
4+
<h1>Title</h1>
5+
<h2>Subtitle</h2>
6+
<p>The <strong><em>markdown</em></strong> text.</p>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:markdown
2+
# Hello World!
3+
**bold**
4+
_italic_
5+
6+
include:markdown readme.md
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Title
2+
## Subtitle
3+
4+
The **_markdown_** text.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require('path');
2+
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'production',
6+
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
},
10+
11+
plugins: [
12+
new HtmlBundlerPlugin({
13+
entry: {
14+
index: 'src/index.pug',
15+
},
16+
preprocessor: 'pug',
17+
preprocessorOptions: {
18+
embedFilters: {
19+
markdown: true,
20+
},
21+
},
22+
}),
23+
],
24+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
<script>(()=>{let o=0;for(o=0;o<10;o++);let l=`Count: ${o} dollars`;console.log(l)})();</script>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
<script src="./main.js" defer="defer"></script>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let $i = 0;
2+
for ($i = 0; $i < 10; $i++) {}
3+
4+
let $str = `Count: ${$i} $.`;
5+
6+
console.log($str);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const path = require('path');
2+
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'production',
6+
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
},
10+
11+
plugins: [
12+
new HtmlBundlerPlugin({
13+
entry: {
14+
index: './src/index.html',
15+
},
16+
js: {
17+
inline: true,
18+
},
19+
postprocess: (content, templateInfo, compilation) => {
20+
const { RawSource } = compilation.compiler.webpack.sources;
21+
22+
// the filename of JS used in the HTML
23+
const jsFilename = 'main.js';
24+
25+
// get compiled JS code
26+
let source = compilation.assets[jsFilename].source();
27+
28+
// modify JS code
29+
source = source.replace(/\$[^\{]/g, 'dollars');
30+
31+
// update compilation with new JS code before this code will be inlined into HTML
32+
compilation.updateAsset(jsFilename, new RawSource(source));
33+
},
34+
}),
35+
],
36+
};

test/integration-pug.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ describe('embedded filters tests', () => {
124124
expect(result).toBeTruthy();
125125
done();
126126
});
127+
test(`:markdown`, () => compareFiles('_pug/filter-markdown'));
127128
});
128129

129130
describe('exception tests', () => {

test/integration.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ describe('special cases', () => {
447447

448448
test('dynamic import in js', () => compareFiles('js-dynamic-import-js'));
449449

450+
test('modify js in postprocess', () => compareFiles('postprocess-modify-js'));
451+
450452
// for debugging
451453
// test('resolve hmr file', () => watchCompareFiles('resolve-hmr-file'));
452454
});

0 commit comments

Comments
 (0)