Skip to content

Commit

Permalink
test: add test for inline css via query
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Nov 22, 2024
1 parent 22a39db commit c278340
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/cases/inline-style-query2/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<!-- inline CSS -->
<style>.index-css-inline {
color: red;
}
</style>
<style>.style-css-inline {
color: green;
}
</style>

<!-- resolve CSS file -->
<link href="style-file.e2174e16.css" rel="stylesheet" />

<!-- inline JS -->
<script>console.log(">> index.js");</script>
</head>
<body>
<h1>Home</h1>
<div class="index-css-inline">1</div>
<div class="style-css-inline">2</div>
<div class="style-css-file">3</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.style-css-file {
color: blue;
}
3 changes: 3 additions & 0 deletions test/cases/inline-style-query2/src/css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.index-css-inline {
color: red;
}
3 changes: 3 additions & 0 deletions test/cases/inline-style-query2/src/css/style-file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.style-css-file {
color: blue;
}
3 changes: 3 additions & 0 deletions test/cases/inline-style-query2/src/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.style-css-inline {
color: green;
}
21 changes: 21 additions & 0 deletions test/cases/inline-style-query2/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<!-- inline CSS -->
<link href="./css/index.css?inline" rel="stylesheet" />
<link href="./css/style.css?inline" rel="stylesheet" />

<!-- resolve CSS file -->
<link href="./css/style-file.css" rel="stylesheet" />

<!-- inline JS -->
<script src="./js/index.js?inline" defer="defer"></script>
</head>
<body>
<h1>Home</h1>
<div class="index-css-inline">1</div>
<div class="style-css-inline">2</div>
<div class="style-css-file">3</div>
</body>
</html>
1 change: 1 addition & 0 deletions test/cases/inline-style-query2/src/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('>> index.js');
31 changes: 31 additions & 0 deletions test/cases/inline-style-query2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path');
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');

module.exports = {
mode: 'production',

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

plugins: [
new HtmlBundlerPlugin({
entry: {
index: './src/index.html',
},
css: {
filename: '[name].[contenthash:8].css',
},
verbose: true,
}),
],

module: {
rules: [
{
test: /\.(css)$/,
use: ['css-loader'],
},
],
},
};
2 changes: 2 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ describe('inline styles & scripts', () => {
test('inline all assets into one HTML', () => compareFiles('inline-all-asset-to-html'));

test('inline CSS via `?inline` and resolve url()', () => compareFiles('inline-style-query'));
test('inline many CSS via `?inline`', () => compareFiles('inline-style-query2'));

test('inline CSS, source map, via `?inline`', () => compareFiles('inline-style-query-with-source-map'));
test('inline minimized CSS', () => compareFiles('inline-style-cssnano'));
test('inline js via `?inline`', () => compareFiles('inline-script-query'));
Expand Down

0 comments on commit c278340

Please sign in to comment.