Skip to content

Commit ec13c43

Browse files
test: fix (#220)
1 parent d3bf829 commit ec13c43

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

test/__snapshots__/webpack.test.js.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ exports[`Works with test-loader: result 1`] = `
4040
"cacheable": "function",
4141
"callback": "function",
4242
"clearDependencies": "function",
43-
"context": "<cwd>/test/basic-loader-test",
44-
"currentRequest": "<cwd>/test/basic-loader-test/test-loader.js??ruleSet[1].rules[0].use[1]!<cwd>/test/basic-loader-test/file.js?q=1#hash",
43+
"context": "<PROJECT_ROOT>/test/basic-loader-test",
44+
"currentRequest": "<PROJECT_ROOT>/test/basic-loader-test/test-loader.js??ruleSet[1].rules[0].use[1]!<PROJECT_ROOT>/test/basic-loader-test/file.js?q=1#hash",
4545
"data": null,
4646
"dependency": "function",
4747
"emitError": "function",
@@ -58,13 +58,13 @@ exports[`Works with test-loader: result 1`] = `
5858
},
5959
"getContextDependencies": "function",
6060
"getContextDependenciesResult": [
61-
"<cwd>/test/basic-loader-test/directory",
61+
"<PROJECT_ROOT>/test/basic-loader-test/directory",
6262
],
6363
"getDependencies": "function",
6464
"getDependenciesResult": [
65-
"<cwd>/test/basic-loader-test/file.js",
66-
"<cwd>/test/basic-loader-test/dep1.js",
67-
"<cwd>/test/basic-loader-test/dep.js",
65+
"<PROJECT_ROOT>/test/basic-loader-test/file.js",
66+
"<PROJECT_ROOT>/test/basic-loader-test/dep1.js",
67+
"<PROJECT_ROOT>/test/basic-loader-test/dep.js",
6868
],
6969
"getLogger": "function",
7070
"getMissingDependencies": "function",
@@ -97,10 +97,10 @@ module.exports = new URL('./style.less', import.meta.url);
9797
"options": {
9898
"test": {},
9999
},
100-
"path": "<cwd>/test/basic-loader-test/test-loader.js",
100+
"path": "<PROJECT_ROOT>/test/basic-loader-test/test-loader.js",
101101
"pitchExecuted": true,
102102
"query": "??ruleSet[1].rules[0].use[1]",
103-
"request": "<cwd>/test/basic-loader-test/test-loader.js??ruleSet[1].rules[0].use[1]",
103+
"request": "<PROJECT_ROOT>/test/basic-loader-test/test-loader.js??ruleSet[1].rules[0].use[1]",
104104
},
105105
],
106106
"mode": "none",
@@ -111,14 +111,14 @@ module.exports = new URL('./style.less', import.meta.url);
111111
"query": {
112112
"test": {},
113113
},
114-
"remainingRequest": "<cwd>/test/basic-loader-test/file.js?q=1#hash",
115-
"request": "<cwd>/test/basic-loader-test/test-loader.js??ruleSet[1].rules[0].use[1]!<cwd>/test/basic-loader-test/file.js?q=1#hash",
114+
"remainingRequest": "<PROJECT_ROOT>/test/basic-loader-test/file.js?q=1#hash",
115+
"request": "<PROJECT_ROOT>/test/basic-loader-test/test-loader.js??ruleSet[1].rules[0].use[1]!<PROJECT_ROOT>/test/basic-loader-test/file.js?q=1#hash",
116116
"resolve": "function",
117-
"resource": "<cwd>/test/basic-loader-test/file.js?q=1#hash",
117+
"resource": "<PROJECT_ROOT>/test/basic-loader-test/file.js?q=1#hash",
118118
"resourceFragment": "#hash",
119-
"resourcePath": "<cwd>/test/basic-loader-test/file.js",
119+
"resourcePath": "<PROJECT_ROOT>/test/basic-loader-test/file.js",
120120
"resourceQuery": "?q=1",
121-
"rootContext": "<cwd>/test/basic-loader-test",
121+
"rootContext": "<PROJECT_ROOT>/test/basic-loader-test",
122122
"sourceMap": false,
123123
"target": "web",
124124
"utils": {

test/basic-loader-test/test-loader.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const path = require('path');
22

3+
const normalize = (str) =>
4+
str.split(process.cwd()).join('<PROJECT_ROOT>').replace(/\\/g, '/');
5+
36
module.exports = async function testLoader() {
47
this.cacheable(false);
58

@@ -35,18 +38,24 @@ module.exports = async function testLoader() {
3538
webpack: this.webpack,
3639
sourceMap: this.sourceMap,
3740
target: this.target,
38-
rootContext: this.rootContext,
39-
context: this.context,
41+
rootContext: normalize(this.rootContext),
42+
context: normalize(this.context),
4043
environment: this.environment,
4144
loaderIndex: this.loaderIndex,
42-
loaders: this.loaders,
43-
resourcePath: this.resourcePath,
45+
loaders: this.loaders.map((item) => {
46+
return {
47+
...item,
48+
path: normalize(item.path),
49+
request: normalize(item.request),
50+
};
51+
}),
52+
resourcePath: normalize(this.resourcePath),
4453
resourceQuery: this.resourceQuery,
4554
resourceFragment: this.resourceFragment,
46-
resource: this.resource,
47-
request: this.request,
48-
remainingRequest: this.remainingRequest,
49-
currentRequest: this.currentRequest,
55+
resource: normalize(this.resource),
56+
request: normalize(this.request),
57+
remainingRequest: normalize(this.remainingRequest),
58+
currentRequest: normalize(this.currentRequest),
5059
previousRequest: this.previousRequest,
5160
query: this.query,
5261
// Todo fix me
@@ -103,12 +112,13 @@ module.exports = async function testLoader() {
103112
addContextDependency: typeof this.addContextDependency,
104113
addMissingDependency: typeof this.addMissingDependency,
105114
getDependencies: typeof this.getDependencies,
106-
getDependenciesResult: this.getDependencies(),
115+
getDependenciesResult: this.getDependencies().map(normalize),
107116
getContextDependencies: typeof this.getContextDependencies,
108-
getContextDependenciesResult: this.getContextDependencies(),
117+
getContextDependenciesResult:
118+
this.getContextDependencies().map(normalize),
109119
getMissingDependencies: typeof this.getMissingDependencies,
110120
getMissingDependenciesResult: this.getMissingDependencies(),
111121
clearDependencies: typeof this.clearDependencies,
112-
}).replace(new RegExp(process.cwd(), 'g'), '<cwd>')};`
122+
})};`
113123
);
114124
};

test/pitch.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const runPitch = (options) =>
9898
getOptions: () => {
9999
return { workers: NaN, poolTimeout: 2000 };
100100
},
101+
cacheable: () => {},
101102
async: () => (error) => {
102103
if (error) {
103104
throw error;

0 commit comments

Comments
 (0)