Skip to content

Commit f8c7ecb

Browse files
authored
test: switch reload fixtures to built-in css (#187)
1 parent 18e1296 commit f8c7ecb

File tree

7 files changed

+261
-1153
lines changed

7 files changed

+261
-1153
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"connect-history-api-fallback": "^2.0.0",
6767
"connect-next": "^4.0.1",
6868
"cross-env": "^10.1.0",
69-
"css-loader": "^7.1.4",
7069
"express": "^5.2.1",
7170
"hono": "^4.12.9",
7271
"http-compression": "^1.1.2",
@@ -84,7 +83,6 @@
8483
"selfsigned": "^5.5.0",
8584
"serve-static": "^2.2.1",
8685
"simple-git-hooks": "^2.13.1",
87-
"style-loader": "^4.0.0",
8886
"typescript": "^6.0.2",
8987
"ws": "^8.20.0"
9088
},

pnpm-lock.yaml

Lines changed: 248 additions & 1105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e/__snapshots__/hot-and-live-reload.test.js.snap

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ exports[`hot and live reload > should work and refresh content using hot module
6363
[HMR] Checking for updates on the server...,
6464
[HMR] Updated modules:,
6565
[HMR] - ./main.css,
66-
[HMR] - <cssloader>/cjs.js!./main.css,
67-
,
6866
[HMR] App is up to date.,
6967
]
7068
`;
@@ -80,8 +78,6 @@ exports[`hot and live reload > should work and refresh content using hot module
8078
[HMR] Checking for updates on the server...,
8179
[HMR] Updated modules:,
8280
[HMR] - ./main.css,
83-
[HMR] - <cssloader>/cjs.js!./main.css,
84-
,
8581
[HMR] App is up to date.,
8682
]
8783
`;
@@ -97,8 +93,6 @@ exports[`hot and live reload > should work and refresh content using hot module
9793
[HMR] Checking for updates on the server...,
9894
[HMR] Updated modules:,
9995
[HMR] - ./main.css,
100-
[HMR] - <cssloader>/cjs.js!./main.css,
101-
,
10296
[HMR] App is up to date.,
10397
]
10498
`;
@@ -114,8 +108,6 @@ exports[`hot and live reload > should work and refresh content using hot module
114108
[HMR] Checking for updates on the server...,
115109
[HMR] Updated modules:,
116110
[HMR] - ./main.css,
117-
[HMR] - <cssloader>/cjs.js!./main.css,
118-
,
119111
[HMR] App is up to date.,
120112
]
121113
`;
@@ -131,8 +123,6 @@ exports[`hot and live reload > should work and refresh content using hot module
131123
[HMR] Checking for updates on the server...,
132124
[HMR] Updated modules:,
133125
[HMR] - ./main.css,
134-
[HMR] - <cssloader>/cjs.js!./main.css,
135-
,
136126
[HMR] App is up to date.,
137127
]
138128
`;
@@ -148,8 +138,6 @@ exports[`hot and live reload > should work and refresh content using hot module
148138
[HMR] Checking for updates on the server...,
149139
[HMR] Updated modules:,
150140
[HMR] - ./main.css,
151-
[HMR] - <cssloader>/cjs.js!./main.css,
152-
,
153141
[HMR] App is up to date.,
154142
]
155143
`;
@@ -165,8 +153,6 @@ exports[`hot and live reload > should work and refresh content using hot module
165153
[HMR] Checking for updates on the server...,
166154
[HMR] Updated modules:,
167155
[HMR] - ./main.css,
168-
[HMR] - <cssloader>/cjs.js!./main.css,
169-
,
170156
[HMR] App is up to date.,
171157
]
172158
`;
@@ -182,8 +168,6 @@ exports[`hot and live reload > should work and refresh content using hot module
182168
[HMR] Checking for updates on the server...,
183169
[HMR] Updated modules:,
184170
[HMR] - ./main.css,
185-
[HMR] - <cssloader>/cjs.js!./main.css,
186-
,
187171
[HMR] App is up to date.,
188172
]
189173
`;
@@ -199,8 +183,6 @@ exports[`hot and live reload > should work and refresh content using hot module
199183
[HMR] Checking for updates on the server...,
200184
[HMR] Updated modules:,
201185
[HMR] - ./main.css,
202-
[HMR] - <cssloader>/cjs.js!./main.css,
203-
,
204186
[HMR] App is up to date.,
205187
]
206188
`;
@@ -238,8 +220,6 @@ exports[`hot and live reload > should work with manual client setup (default) >
238220
[HMR] Checking for updates on the server...,
239221
[HMR] Updated modules:,
240222
[HMR] - ./main.css,
241-
[HMR] - <cssloader>/cjs.js!./main.css,
242-
,
243223
[HMR] App is up to date.,
244224
]
245225
`;
@@ -277,8 +257,6 @@ exports[`hot and live reload > should work with manual client setup and allow to
277257
[HMR] Checking for updates on the server...,
278258
[HMR] Updated modules:,
279259
[HMR] - ./main.css,
280-
[HMR] - <cssloader>/cjs.js!./main.css,
281-
,
282260
[HMR] App is up to date.,
283261
]
284262
`;

tests/fixtures/reload-config-2/rspack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
rules: [
1515
{
1616
test: /\.css$/,
17-
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
17+
type: 'css',
1818
},
1919
],
2020
},

tests/fixtures/reload-config/rspack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
rules: [
1515
{
1616
test: /\.css$/,
17-
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
17+
type: 'css',
1818
},
1919
],
2020
},

tests/helpers/html-generator-plugin.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
const HTMLContentForIndex = `
1+
const HTMLContentForIndex = (styleTags = '') => {
2+
const headStyleTags = styleTags ? `\n ${styleTags}` : '';
3+
4+
return `
25
<!DOCTYPE html>
36
<html>
47
<head>
58
<meta charset='UTF-8'>
6-
<title>rspack-dev-server</title>
9+
<title>rspack-dev-server</title>${headStyleTags}
710
</head>
811
<body>
912
<h1>rspack-dev-server is running...</h1>
1013
<script type="text/javascript" charset="utf-8" src="/main.js"></script>
1114
</body>
1215
</html>
1316
`;
17+
};
1418

1519
const HTMLContentForAssets = (assetName) => `
1620
<!DOCTYPE html>
@@ -53,9 +57,13 @@ module.exports = class HTMLGeneratorPlugin {
5357
stage: compiler.rspack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
5458
},
5559
() => {
56-
const indexSource = new RawSource(HTMLContentForIndex);
5760
const testSource = new RawSource(HTMLContentForTest);
5861
const assets = compilation.getAssets();
62+
const styleTags = assets
63+
.filter((asset) => asset.name.endsWith('.css'))
64+
.map((asset) => `<link rel="stylesheet" href="/${asset.name}" />`)
65+
.join('\n ');
66+
const indexSource = new RawSource(HTMLContentForIndex(styleTags));
5967

6068
compilation.emitAsset('index.html', indexSource);
6169
compilation.emitAsset('test.html', testSource);

tests/helpers/normalize.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ const path = require('node:path');
33
const CURRENT_CWD = process.cwd();
44
const ROOT = path.resolve(__dirname, '../../');
55

6-
const CSS_LOADER = path.dirname(require.resolve('css-loader'));
7-
const RELATIVE_CSS_LOADER = path.relative(
8-
path.dirname(
9-
path.resolve(__dirname, '../fixtures/reload-config/rspack.config'),
10-
),
11-
CSS_LOADER,
12-
);
136
const RSPACK = path.dirname(require.resolve('@rspack/core/package.json'));
147

158
const normalize = (str) => {
@@ -19,18 +12,6 @@ const normalize = (str) => {
1912
.split(RSPACK.replace(/(\\)+/g, '/'))
2013
.join('<rspack>');
2114

22-
normalizedStr = normalizedStr
23-
.split(CSS_LOADER.replace(/(\\)+/g, '/'))
24-
.join('<cssloader>');
25-
26-
normalizedStr = normalizedStr
27-
.split(RELATIVE_CSS_LOADER.replace(/(\\)+/g, '/'))
28-
.join('<cssloader>');
29-
30-
normalizedStr = normalizedStr
31-
.split(RELATIVE_CSS_LOADER.replace(/(\\)+/g, '/'))
32-
.join('<cssloader>');
33-
3415
normalizedStr = normalizedStr
3516
.split(ROOT.replace(/(\\)+/g, '/'))
3617
.join('<root>');

0 commit comments

Comments
 (0)