Skip to content

Commit 9eb98d1

Browse files
committed
add test
1 parent 77cdce7 commit 9eb98d1

File tree

11 files changed

+181
-0
lines changed

11 files changed

+181
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
e,
3+
_1
4+
} from "./path1";
5+
import {
6+
aUsed,
7+
bUsed,
8+
cUsed
9+
} from "root1";
10+
import {
11+
dUsed,
12+
eUsed,
13+
fUsed
14+
} from "root2";
15+
16+
it("should use only current entrypoint exports", () => {
17+
expect(e).toBe("e");
18+
expect(_1.a).toBe("a");
19+
expect(_1.c).toBe("c");
20+
expect(aUsed).toBe(true);
21+
expect(bUsed).toBe(false);
22+
expect(cUsed).toBe(true);
23+
expect(dUsed).toBe(false);
24+
expect(eUsed).toBe(true);
25+
expect(fUsed).toBe(false);
26+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
b,
3+
_2
4+
} from "./path2";
5+
import {
6+
aUsed,
7+
bUsed,
8+
cUsed
9+
} from "root1";
10+
import {
11+
dUsed,
12+
eUsed,
13+
fUsed
14+
} from "root2";
15+
import {addFiles, isSame} from "./helper";
16+
17+
// should be the same as 3.js and reuse defaultVendors
18+
it("should use only current entrypoint exports", () => {
19+
expect(b).toBe("b");
20+
expect(_2.f).toBe("f");
21+
expect(aUsed).toBe(false);
22+
expect(bUsed).toBe(true);
23+
expect(cUsed).toBe(false);
24+
expect(dUsed).toBe(false);
25+
expect(eUsed).toBe(false);
26+
expect(fUsed).toBe(true);
27+
28+
const files = new Set();
29+
30+
addFiles(
31+
files,
32+
__STATS__.chunks.filter(ch => isSame(ch.runtime, ["b"]))
33+
);
34+
addFiles(
35+
files,
36+
__STATS__.chunks.filter(ch => isSame(ch.runtime, ["b", "c"]))
37+
);
38+
39+
expect(files.size).toBe(2);
40+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
b,
3+
_2
4+
} from "./path2";
5+
import {
6+
aUsed,
7+
bUsed,
8+
cUsed
9+
} from "root1";
10+
import {
11+
dUsed,
12+
eUsed,
13+
fUsed
14+
} from "root2";
15+
import { addFiles, isSame } from "./helper";
16+
17+
// should be the same as 2.js and reuse defaultVendors
18+
it("should use only current entrypoint exports", () => {
19+
expect(b).toBe("b");
20+
expect(_2.f).toBe("f");
21+
expect(aUsed).toBe(false);
22+
expect(bUsed).toBe(true);
23+
expect(cUsed).toBe(false);
24+
expect(dUsed).toBe(false);
25+
expect(eUsed).toBe(false);
26+
expect(fUsed).toBe(true);
27+
28+
const files = new Set();
29+
30+
addFiles(
31+
files,
32+
__STATS__.chunks.filter(ch => isSame(ch.runtime, ["c"]))
33+
);
34+
addFiles(
35+
files,
36+
__STATS__.chunks.filter(ch => isSame(ch.runtime, ["b", "c"]))
37+
);
38+
39+
expect(files.size).toBe(2);
40+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @template T
3+
* @param {T[]} arr arr
4+
* @param {T[]} expected expected
5+
* @returns {boolean} is same
6+
*/
7+
export function isSame(arr, expected) {
8+
const set = new Set(arr);
9+
return expected.every(i => set.has(i));
10+
}
11+
12+
/**
13+
* @param {Set<string>} files
14+
* @param {{files: string[]}[]} chunks
15+
*/
16+
export function addFiles(files, chunks) {
17+
chunks.forEach(ch => ch.files.forEach(f => files.add(f)));
18+
}

test/configCases/optimization/runtime-specific-used-exports2/node_modules/root1/index.js

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

test/configCases/optimization/runtime-specific-used-exports2/node_modules/root2/index.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { _1, _2 } from "./reexport-all";
2+
import { e, d } from "root2";
3+
4+
export { _1, e };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { _1 } from "./path1";
2+
import { _2 } from "./reexport-all";
3+
4+
const b = _1.b;
5+
6+
export { b, _2 }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * as _1 from "root1";
2+
export * as _2 from "root2";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
findBundle: function() {
3+
return [
4+
"./a.js",
5+
"./b.js",
6+
"./c.js"
7+
];
8+
}
9+
};

0 commit comments

Comments
 (0)