Skip to content

Commit 888588f

Browse files
test: give the data: resource its referrer's context on older webpack
The test loader sets this.context the way webpack/webpack#22940 does, so the test checks the loader on the released webpack too.
1 parent c0e6d92 commit 888588f

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎test/data-uri.test.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ describe("data: URI resource", () => {
2525
{
2626
mimetype: "text/less",
2727
type: "css/auto",
28-
loader: path.resolve(__dirname, "../src/index.js"),
28+
use: [
29+
{
30+
loader: path.resolve(
31+
__dirname,
32+
"./helpers/dataUriContextLoader.cjs",
33+
),
34+
options: { context: path.resolve(__dirname, "fixtures") },
35+
},
36+
path.resolve(__dirname, "../src/index.js"),
37+
],
2938
},
3039
],
3140
},
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
/**
4+
* Gives a `data:` resource the context webpack gives one from webpack/webpack#22940
5+
* on: the directory of what referenced it, so tests run on older webpack too.
6+
* @this {import("webpack").LoaderContext<{ context: string }>}
7+
* @param {string} source source
8+
* @returns {string} the source, untouched
9+
*/
10+
function loader(source) {
11+
return source;
12+
}
13+
14+
/**
15+
* @this {import("webpack").LoaderContext<{ context: string }>}
16+
*/
17+
loader.pitch = function pitch() {
18+
if (this.resourcePath.startsWith("data:")) {
19+
this.context = this.getOptions().context;
20+
}
21+
};
22+
23+
module.exports = loader;

0 commit comments

Comments
 (0)