/
index.js
91 lines (82 loc) · 3.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as C from "./reexport-namespace";
import { counter } from "./reexport-namespace";
import * as C2 from "./reexport-namespace-again";
import cj2, { cjs3DefaultProvidedInfo } from "./cjs2";
import esm1, { esmDefaultProvidedInfo } from "./esm1";
it("default providedInfo should be correct for cjs", () => {
expect(cj2.a).toBe(1);
expect(cjs3DefaultProvidedInfo).toBe(false);
expect(__webpack_exports_info__.cj2.default.provideInfo).toBe(false);
});
it("default providedInfo and usedInfo should be correct for esm", () => {
expect(esm1).toBe(2);
expect(esmDefaultProvidedInfo).toBe(true);
});
it("should allow to reexport namespaces 1", () => {
(0, counter.reset)();
expect(counter.counter).toBe(0);
(0, counter.increment)();
expect(counter.counter).toBe(1);
});
it("should allow to reexport namespaces 2", () => {
(0, C.counter.reset)();
expect(C.counter.counter).toBe(0);
(0, C.counter.increment)();
expect(C.counter.counter).toBe(1);
});
it("should allow to reexport namespaces 3", () => {
(0, C2.CC.counter.reset)();
expect(C2.CC.counter.counter).toBe(0);
(0, C2.CC.counter.increment)();
expect(C2.CC.counter.counter).toBe(1);
});
import CJS from "./cjs";
it("should be able to call a deep function in commonjs", () => {
expect(CJS.a.b.c.d()).toBe(42);
});
it("should report consistent exports info", () => {
const x1 = counter.exportsInfo;
if (process.env.NODE_ENV === "production") {
expect(x1.incrementInfo).toBe(true);
expect(x1.counterInfo).toBe(true);
expect(x1.resetInfo).toBe(true);
expect(x1.unusedExport).toBe(false);
expect(x1.unusedExportInfo).toBe(false);
expect(x1.somethingElse).toBe(false);
expect(x1.somethingElseInfo).toBe(false);
expect(C.exportsInfo.nsInfo).toBe(true);
expect(C.exportsInfo.ns2).toBe(false);
expect(C.exportsInfo.ns2Info).toBe(false);
} else if (process.env.NODE_ENV === "development") {
expect(x1.incrementInfo).toBe(undefined);
expect(x1.counterInfo).toBe(undefined);
expect(x1.resetInfo).toBe(undefined);
expect(x1.unusedExport).toBe(true);
expect(x1.unusedExportInfo).toBe(undefined);
expect(x1.somethingElse).toBe(true);
expect(x1.somethingElseInfo).toBe(undefined);
expect(C.exportsInfo.nsInfo).toBe(undefined);
expect(C.exportsInfo.ns2).toBe(true);
expect(C.exportsInfo.ns2Info).toBe(undefined);
}
expect(x1.increment).toBe(true);
expect(x1.counter).toBe(true);
expect(x1.reset).toBe(true);
expect(x1.incrementProvideInfo).toBe(true);
expect(x1.somethingElseProvideInfo).toBe(false);
expect(C.exportsInfo.increment).toBe(x1.increment);
expect(C.exportsInfo.counter).toBe(x1.counter);
expect(C.exportsInfo.reset).toBe(x1.reset);
expect(C.exportsInfo.unusedExport).toBe(x1.unusedExport);
expect(C.exportsInfo.incrementInfo).toBe(x1.incrementInfo);
expect(C.exportsInfo.counterInfo).toBe(x1.counterInfo);
expect(C.exportsInfo.resetInfo).toBe(x1.resetInfo);
expect(C.exportsInfo.unusedExportInfo).toBe(x1.unusedExportInfo);
expect(C.exportsInfo.incrementProvideInfo).toBe(x1.incrementProvideInfo);
expect(C.exportsInfo.somethingElseProvideInfo).toBe(
x1.somethingElseProvideInfo
);
expect(C.exportsInfo.ns).toBe(true);
expect(C2.exportsInfo).toBe(true);
expect(__webpack_exports_info__).toBe(true);
});