Skip to content

Commit 753dcce

Browse files
committed
fix order of occurrence order plugin
remove enforced additional occurrence order plugin from test cases make test cases more independent of module/chunk order/ids
1 parent 08b3549 commit 753dcce

File tree

13 files changed

+1195
-1189
lines changed

13 files changed

+1195
-1189
lines changed

lib/optimize/OccurrenceChunkOrderPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class OccurrenceOrderChunkIdsPlugin {
4949
if (aOccurs < bOccurs) return 1;
5050
const orgA = originalOrder.get(a);
5151
const orgB = originalOrder.get(b);
52-
return orgB - orgA;
52+
return orgA - orgB;
5353
});
5454
}
5555
);

lib/optimize/OccurrenceModuleOrderPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class OccurrenceOrderModuleIdsPlugin {
9191
if (aOccurs < bOccurs) return 1;
9292
const orgA = originalOrder.get(a);
9393
const orgB = originalOrder.get(b);
94-
return orgB - orgA;
94+
return orgA - orgB;
9595
});
9696
}
9797
);

lib/optimize/OccurrenceOrderPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class OccurrenceOrderPlugin {
9191
if (aOccurs < bOccurs) return 1;
9292
const orgA = originalOrder.get(a);
9393
const orgB = originalOrder.get(b);
94-
return orgB - orgA;
94+
return orgA - orgB;
9595
});
9696
}
9797
);
@@ -124,7 +124,7 @@ class OccurrenceOrderPlugin {
124124
if (aOccurs < bOccurs) return 1;
125125
const orgA = originalOrder.get(a);
126126
const orgB = originalOrder.get(b);
127-
return orgB - orgA;
127+
return orgA - orgB;
128128
});
129129
}
130130
);

test/Compiler.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe("Compiler", () => {
8585
expect(Object.keys(files)).toEqual(["/main.js"]);
8686
const bundle = files["/main.js"];
8787
expect(bundle).toMatch("function __webpack_require__(");
88-
expect(bundle).toMatch("__webpack_require__(/*! ./a */ 0);");
88+
expect(bundle).toMatch(/__webpack_require__\(\/\*! \.\/a \*\/ \d\);/);
8989
expect(bundle).toMatch("./c.js");
9090
expect(bundle).toMatch("./a.js");
9191
expect(bundle).toMatch("This is a");
@@ -145,9 +145,9 @@ describe("Compiler", () => {
145145
it("should compile a file with multiple chunks", done => {
146146
compile("./chunks", {}, (stats, files) => {
147147
expect(stats.chunks).toHaveLength(2);
148-
expect(Object.keys(files)).toEqual(["/0.js", "/main.js"]);
148+
expect(Object.keys(files)).toEqual(["/main.js", "/1.js"]);
149149
const bundle = files["/main.js"];
150-
const chunk = files["/0.js"];
150+
const chunk = files["/1.js"];
151151
expect(bundle).toMatch("function __webpack_require__(");
152152
expect(bundle).toMatch("__webpack_require__(/*! ./b */");
153153
expect(chunk).not.toMatch("__webpack_require__(/* ./b */");

test/HotModuleReplacementPlugin.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ describe("HotModuleReplacementPlugin", () => {
5050
output: {
5151
path: path.join(__dirname, "js", "HotModuleReplacementPlugin")
5252
},
53-
plugins: [
54-
new webpack.HotModuleReplacementPlugin(),
55-
new webpack.optimize.OccurrenceOrderPlugin()
56-
]
53+
plugins: [new webpack.HotModuleReplacementPlugin()],
54+
optimization: {
55+
moduleIds: "size",
56+
chunkIds: "size"
57+
}
5758
});
5859
fs.writeFileSync(entryFile, "1", "utf-8");
5960
compiler.run((err, stats) => {

test/StatsTestCases.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe("StatsTestCases", () => {
7575
])
7676
);
7777
};
78-
new webpack.optimize.OccurrenceOrderPlugin().apply(c);
7978
});
8079
c.run((err, stats) => {
8180
if (err) return done(err);

test/__snapshots__/ConfigTestCases.test.js.snap

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ exports[`ConfigTestCases records issue-2991 exported tests should write relative
44
"{
55
\\"modules\\": {
66
\\"byIdentifier\\": {
7-
\\"external \\\\\\"path\\\\\\"\\": 0,
8-
\\"external \\\\\\"fs\\\\\\"\\": 1,
9-
\\"ignored pkgs/somepackage/foo\\": 2,
10-
\\"test.js\\": 3
7+
\\"test.js\\": 0,
8+
\\"ignored pkgs/somepackage/foo\\": 1,
9+
\\"external \\\\\\"fs\\\\\\"\\": 2,
10+
\\"external \\\\\\"path\\\\\\"\\": 3
1111
},
1212
\\"usedIds\\": {
1313
\\"0\\": 0,
@@ -32,12 +32,12 @@ exports[`ConfigTestCases records issue-7339 exported tests should write relative
3232
"{
3333
\\"modules\\": {
3434
\\"byIdentifier\\": {
35-
\\"dependencies/foo.js\\": 0,
36-
\\"dependencies/bar.js\\": 1,
37-
\\"external \\\\\\"path\\\\\\"\\": 2,
38-
\\"external \\\\\\"fs\\\\\\"\\": 3,
39-
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 4,
40-
\\"test.js\\": 5
35+
\\"dependencies/bar.js\\": 0,
36+
\\"dependencies/foo.js\\": 1,
37+
\\"test.js\\": 2,
38+
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 3,
39+
\\"external \\\\\\"fs\\\\\\"\\": 4,
40+
\\"external \\\\\\"path\\\\\\"\\": 5
4141
},
4242
\\"usedIds\\": {
4343
\\"0\\": 0,

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 1161 additions & 1161 deletions
Large diffs are not rendered by default.

test/configCases/chunk-index/order-multiple-entries/webpack.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ module.exports = {
6666
asyncIndex2: "0: ./async.js"
6767
});
6868
const indicies = compilation.modules
69+
.slice()
70+
.sort((a, b) => a.index - b.index)
6971
.map(
7072
m =>
7173
`${m.index}: ${m.readableIdentifier(
@@ -74,6 +76,8 @@ module.exports = {
7476
)
7577
.join(", ");
7678
const indicies2 = compilation.modules
79+
.slice()
80+
.sort((a, b) => a.index2 - b.index2)
7781
.map(
7882
m =>
7983
`${m.index2}: ${m.readableIdentifier(
@@ -82,10 +86,10 @@ module.exports = {
8286
)
8387
.join(", ");
8488
expect(indicies).toEqual(
85-
"2: ./shared.js, 4: ./c.js, 3: ./b.js, 1: ./a.js, 6: ./async.js, 5: ./entry2.js, 0: ./entry1.js"
89+
"0: ./entry1.js, 1: ./a.js, 2: ./shared.js, 3: ./b.js, 4: ./c.js, 5: ./entry2.js, 6: ./async.js"
8690
);
8791
expect(indicies2).toEqual(
88-
"0: ./shared.js, 3: ./c.js, 2: ./b.js, 1: ./a.js, 6: ./async.js, 5: ./entry2.js, 4: ./entry1.js"
92+
"0: ./shared.js, 1: ./a.js, 2: ./b.js, 3: ./c.js, 4: ./entry1.js, 5: ./entry2.js, 6: ./async.js"
8993
);
9094
});
9195
};

test/configCases/code-generation/use-strict/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ it("should include only one use strict per module", function() {
1515
match = regExp.exec(source);
1616
}
1717

18+
matches.sort();
19+
1820
expect(matches).toEqual([
19-
"__webpack_require__.r(__webpack_exports__);",
2021
"/* unused harmony default export */ var _unused_webpack_default_export = (\"a\");",
2122
"__webpack_require__.r(__webpack_exports__);",
2223
"__webpack_require__.r(__webpack_exports__);",
2324
"__webpack_require__.r(__webpack_exports__);",
25+
"__webpack_require__.r(__webpack_exports__);",
2426
"it(\"should include only one use strict per module\", function() {",
2527
]);
2628
});

0 commit comments

Comments
 (0)