Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Commit 50ff9e4

Browse files
misticevilebottnawi
authored andcommitted
test: fix for cacheContext-option in order to normalize the snapshots path (#52)
1 parent 22d0173 commit 50ff9e4

File tree

4 files changed

+95
-30
lines changed

4 files changed

+95
-30
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
3939
"babel-cli": "^6.0.0",
4040
"babel-core": "^6.26.3",
41-
"babel-loader": "^7.1.5",
4241
"babel-jest": "^21.0.0",
42+
"babel-loader": "^7.1.5",
4343
"babel-plugin-transform-object-rest-spread": "^6.0.0",
4444
"babel-polyfill": "^6.0.0",
4545
"babel-preset-env": "^1.6.0",
@@ -53,8 +53,9 @@
5353
"jest": "^21.0.0",
5454
"lint-staged": "^5.0.0",
5555
"memory-fs": "^0.4.1",
56-
"prettier": "^1.15.2",
56+
"normalize-path": "^3.0.0",
5757
"pre-commit": "^1.0.0",
58+
"prettier": "^1.15.2",
5859
"standard-version": "^4.0.0",
5960
"webpack": "^4.27.1",
6061
"webpack-cli": "^3.1.2",

test/__snapshots__/cacheContext-option.test.js.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ Array [
1111
"dependencies": Array [
1212
Object {
1313
"mtime": null,
14-
"path": "test/fixtures/basic/file_1.js",
14+
"path": "test/fixtures/basic/index.js",
1515
},
1616
Object {
1717
"mtime": null,
1818
"path": "src/index.js",
1919
},
2020
],
21-
"remainingRequest": "test/fixtures/basic/file_1.js",
21+
"remainingRequest": "test/fixtures/basic/index.js",
2222
"result": Array [
2323
"/* eslint-disable */
24-
console.log('file_1');
24+
require('./file_1.js');
25+
require('./file_2.js');
26+
27+
console.log('basic_entry');
2528
",
2629
],
2730
},
@@ -30,17 +33,17 @@ console.log('file_1');
3033
"dependencies": Array [
3134
Object {
3235
"mtime": null,
33-
"path": "test/fixtures/basic/file_2.js",
36+
"path": "test/fixtures/basic/file_1.js",
3437
},
3538
Object {
3639
"mtime": null,
3740
"path": "src/index.js",
3841
},
3942
],
40-
"remainingRequest": "test/fixtures/basic/file_2.js",
43+
"remainingRequest": "test/fixtures/basic/file_1.js",
4144
"result": Array [
4245
"/* eslint-disable */
43-
console.log('file_2');
46+
console.log('file_1');
4447
",
4548
],
4649
},
@@ -49,20 +52,17 @@ console.log('file_2');
4952
"dependencies": Array [
5053
Object {
5154
"mtime": null,
52-
"path": "test/fixtures/basic/index.js",
55+
"path": "test/fixtures/basic/file_2.js",
5356
},
5457
Object {
5558
"mtime": null,
5659
"path": "src/index.js",
5760
},
5861
],
59-
"remainingRequest": "test/fixtures/basic/index.js",
62+
"remainingRequest": "test/fixtures/basic/file_2.js",
6063
"result": Array [
6164
"/* eslint-disable */
62-
require('./file_1.js');
63-
require('./file_2.js');
64-
65-
console.log('basic_entry');
65+
console.log('file_2');
6666
",
6767
],
6868
},

test/cacheContext-option.test.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const normalizePath = require('normalize-path');
23
const { webpack } = require('./helpers');
34

45
const mockCacheLoaderWriteFn = jest.fn();
@@ -25,17 +26,27 @@ const mockRelativeWebpackConfig = {
2526
};
2627

2728
const buildSnapshotReadyDeps = (deps) =>
28-
deps.map((dep) => Object.assign({}, dep, { mtime: null })).sort();
29+
deps.map((dep) =>
30+
Object.assign({}, dep, { mtime: null, path: normalizePath(dep.path) })
31+
);
2932

3033
const buildCacheLoaderCallsData = (calls) =>
31-
calls.sort().map((rawCall) => {
32-
const call = rawCall[1];
33-
return {
34-
...call,
35-
dependencies: buildSnapshotReadyDeps(call.dependencies),
36-
contextDependencies: buildSnapshotReadyDeps(call.contextDependencies),
37-
};
38-
});
34+
Array.from(
35+
calls
36+
.reduce((builtCalls, call) => {
37+
const [, rawData] = call;
38+
39+
return builtCalls.set(rawData.remainingRequest, {
40+
...rawData,
41+
remainingRequest: normalizePath(rawData.remainingRequest),
42+
dependencies: buildSnapshotReadyDeps(rawData.dependencies),
43+
contextDependencies: buildSnapshotReadyDeps(
44+
rawData.contextDependencies
45+
),
46+
});
47+
}, new Map())
48+
.values()
49+
);
3950

4051
describe('cacheContext option', () => {
4152
it('should generate relative paths to the project root', async () => {

0 commit comments

Comments
 (0)