Skip to content

Commit 7037f39

Browse files
committed
Add test case
1 parent 0aa7584 commit 7037f39

8 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const FLAG = process.env.FLAG;
2+
export const NUM = 5;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { FLAG, NUM } from "./env";
2+
import { REEXPORTED_NUM } from "./reexport";
3+
import "./trigger";
4+
5+
const fs = __non_webpack_require__("fs");
6+
const path = __non_webpack_require__("path");
7+
8+
it("should refresh the inlined constants a cached build baked into consumers", () => {
9+
const source = fs.readFileSync(
10+
path.join(STATS_JSON.outputPath, "bundle.js"),
11+
"utf8"
12+
);
13+
const expectedFlag = WATCH_STEP === "0" ? "on" : "off";
14+
const expectedNum = WATCH_STEP === "2" ? 6 : 5;
15+
expect(FLAG).toBe(expectedFlag);
16+
expect(NUM).toBe(expectedNum);
17+
expect(REEXPORTED_NUM).toBe(expectedNum);
18+
expect(source).toContain(
19+
`(/* inlined export .FLAG */${JSON.stringify(expectedFlag)})`
20+
);
21+
expect(source).toContain(`(/* inlined export .NUM */${expectedNum})`);
22+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { NUM as REEXPORTED_NUM } from "./env";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Changed at every step so the watcher rebuilds while the consumer stays as it was
2+
module.exports = 0;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Changed at every step so the watcher rebuilds while the consumer stays as it was
2+
module.exports = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const FLAG = process.env.FLAG;
2+
export const NUM = 6;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Changed at every step so the watcher rebuilds while the consumer stays as it was
2+
module.exports = 2;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
3+
const { DefinePlugin } = require("../../../../");
4+
const currentWatchStep = require("../../../helpers/currentWatchStep");
5+
6+
/** @type {import("../../../../").Configuration} */
7+
module.exports = {
8+
mode: "production",
9+
cache: {
10+
type: "filesystem"
11+
},
12+
optimization: {
13+
minimize: false,
14+
inlineExports: true
15+
},
16+
plugins: [
17+
new DefinePlugin({
18+
"process.env.FLAG": DefinePlugin.runtimeValue(
19+
() =>
20+
JSON.stringify(
21+
Number(currentWatchStep.step || 0) === 0 ? "on" : "off"
22+
),
23+
{ version: () => String(currentWatchStep.step || 0) }
24+
)
25+
})
26+
]
27+
};

0 commit comments

Comments
 (0)