Skip to content

Commit

Permalink
add side effects test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed May 19, 2020
1 parent 8e7b249 commit 7ec220e
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 0 deletions.
@@ -0,0 +1,3 @@
export * from "./module";
if (process.env.NODE_ENV !== "development")
throw new Error("Should not be loaded");
@@ -0,0 +1 @@
export * from "./module";
@@ -0,0 +1,2 @@
export * from "./a";
export * from "./b";
@@ -0,0 +1 @@
export const value = 42;
3 changes: 3 additions & 0 deletions test/cases/side-effects/dynamic-reexports/dedupe-target/a.js
@@ -0,0 +1,3 @@
export * from "./empty";
if (process.env.NODE_ENV !== "development")
throw new Error("Should not be loaded");
@@ -0,0 +1 @@
export * from "./empty";
Empty file.
@@ -0,0 +1,2 @@
export * from "./a";
export * from "./b";
@@ -0,0 +1 @@
export default 42;
@@ -0,0 +1 @@
module.exports = 42;
Empty file.
@@ -0,0 +1,7 @@
export { default as a } from "./a";
export { default as b } from "./b";
export { default as empty } from "./empty";
export { default as json } from "./json";

if (process.env.NODE_ENV !== "development")
throw new Error("Should not be loaded");
@@ -0,0 +1 @@
42
23 changes: 23 additions & 0 deletions test/cases/side-effects/dynamic-reexports/index.js
@@ -0,0 +1,23 @@
import { value as valueStatic } from "./dedupe-target-static";
import { value } from "./dedupe-target";
import * as DefaultExport from "./default-export";

it("should dedupe static reexport target", () => {
expect(valueStatic).toBe(42);
});

it("should dedupe dynamic reexport target", () => {
expect(value).toBe(undefined);
});

it("should optimize dynamic default reexport", () => {
expect(DefaultExport.a).toBe(42);
expect(DefaultExport.b).toBe(42);
expect(DefaultExport.empty).toEqual({});
expect(DefaultExport.json).toBe(42);
});

it("should handle default export when reexporting", () => {
const module = Object(require("./reexports-excludes-default"));
expect(module.test).toBe(true);
});
3 changes: 3 additions & 0 deletions test/cases/side-effects/dynamic-reexports/package.json
@@ -0,0 +1,3 @@
{
"sideEffects": false
}
Empty file.
@@ -0,0 +1 @@
export * from "./module";
@@ -0,0 +1,2 @@
export * from "./empty";
export const test = true;
3 changes: 3 additions & 0 deletions test/cases/side-effects/dynamic-reexports/unused.js
@@ -0,0 +1,3 @@
export const value = 42;
export const unused = __webpack_exports_info__.value.used;
export const unprovided = __webpack_exports_info__.other.provideInfo;

0 comments on commit 7ec220e

Please sign in to comment.