Skip to content

Commit

Permalink
test: add pretty formatting html using beforeEmit
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Mar 21, 2024
1 parent 0c826d6 commit abfd926
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 13 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
html
head
title Test
body
h1 Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const path = require('path');
const PugPlugin = require('@test/pug-plugin');

const pretty = require('js-beautify').html;

// formatting options: https://github.com/beautifier/js-beautify
const prettyOptions = {
html: {
indent_size: 2,
end_with_newline: true,
indent_inner_html: true,
preserve_newlines: true,
max_preserve_newlines: 0,
wrap_line_length: 120,
extra_liners: [],
space_before_conditional: true,
js: {
end_with_newline: false,
preserve_newlines: true,
max_preserve_newlines: 2,
space_after_anon_function: true,
},
css: {
end_with_newline: false,
preserve_newlines: false,
newline_between_rules: false,
},
},
};

const isDev = true;

module.exports = {
mode: 'production',

output: {
path: path.join(__dirname, 'dist/'),
},

plugins: [
new PugPlugin({
entry: {
index: './src/index.pug',
},
beforeEmit: isDev ? (content) => pretty(content, prettyOptions) : undefined,
}),
],

module: {
rules: [
{
test: /\.(css|sass|scss)$/,
use: ['css-loader', 'sass-loader'],
},
],
},
};
4 changes: 4 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ describe('special cases', () => {
test('compile template function in js', () => compareFiles('js-tmpl-entry-js'));
});

describe('experimental', () => {
test('option-pretty-beforeEmit', () => compareFiles('_experimental/option-pretty-beforeEmit'));
});

// Test Messages

describe('exception tests', () => {
Expand Down

0 comments on commit abfd926

Please sign in to comment.