Skip to content

Commit abfd926

Browse files
committed
test: add pretty formatting html using beforeEmit
1 parent 0c826d6 commit abfd926

File tree

5 files changed

+88
-13
lines changed

5 files changed

+88
-13
lines changed

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Test</title>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
</body>
9+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
html
2+
head
3+
title Test
4+
body
5+
h1 Hello World!
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const path = require('path');
2+
const PugPlugin = require('@test/pug-plugin');
3+
4+
const pretty = require('js-beautify').html;
5+
6+
// formatting options: https://github.com/beautifier/js-beautify
7+
const prettyOptions = {
8+
html: {
9+
indent_size: 2,
10+
end_with_newline: true,
11+
indent_inner_html: true,
12+
preserve_newlines: true,
13+
max_preserve_newlines: 0,
14+
wrap_line_length: 120,
15+
extra_liners: [],
16+
space_before_conditional: true,
17+
js: {
18+
end_with_newline: false,
19+
preserve_newlines: true,
20+
max_preserve_newlines: 2,
21+
space_after_anon_function: true,
22+
},
23+
css: {
24+
end_with_newline: false,
25+
preserve_newlines: false,
26+
newline_between_rules: false,
27+
},
28+
},
29+
};
30+
31+
const isDev = true;
32+
33+
module.exports = {
34+
mode: 'production',
35+
36+
output: {
37+
path: path.join(__dirname, 'dist/'),
38+
},
39+
40+
plugins: [
41+
new PugPlugin({
42+
entry: {
43+
index: './src/index.pug',
44+
},
45+
beforeEmit: isDev ? (content) => pretty(content, prettyOptions) : undefined,
46+
}),
47+
],
48+
49+
module: {
50+
rules: [
51+
{
52+
test: /\.(css|sass|scss)$/,
53+
use: ['css-loader', 'sass-loader'],
54+
},
55+
],
56+
},
57+
};

test/index.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ describe('special cases', () => {
159159
test('compile template function in js', () => compareFiles('js-tmpl-entry-js'));
160160
});
161161

162+
describe('experimental', () => {
163+
test('option-pretty-beforeEmit', () => compareFiles('_experimental/option-pretty-beforeEmit'));
164+
});
165+
162166
// Test Messages
163167

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

0 commit comments

Comments
 (0)