@module-federation/modern-js 0.21.6 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/configPlugin.js +301 -357
- package/dist/cjs/cli/index.js +103 -93
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
- package/dist/cjs/cli/ssrPlugin.js +266 -298
- package/dist/cjs/cli/utils.js +84 -81
- package/dist/cjs/constant.js +37 -28
- package/dist/cjs/interfaces/bundler.js +17 -15
- package/dist/cjs/logger.js +37 -25
- package/dist/cjs/react/index.js +55 -19
- package/dist/cjs/react/plugin.js +62 -37
- package/dist/cjs/react/v18.js +55 -19
- package/dist/cjs/react/v19.js +55 -19
- package/dist/cjs/runtime/index.js +55 -19
- package/dist/cjs/server/fileCache.js +76 -76
- package/dist/cjs/server/index.js +65 -57
- package/dist/cjs/server/staticMiddleware.js +84 -84
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
- package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
- package/dist/cjs/types/index.js +17 -15
- package/dist/esm/cli/configPlugin.mjs +305 -0
- package/dist/esm/cli/index.mjs +83 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
- package/dist/esm/cli/ssrPlugin.mjs +254 -0
- package/dist/esm/cli/utils.mjs +40 -0
- package/dist/esm/constant.mjs +3 -0
- package/dist/esm/logger.mjs +5 -0
- package/dist/esm/react/plugin.mjs +3 -0
- package/dist/esm/server/fileCache.mjs +90 -0
- package/dist/esm/server/index.mjs +36 -0
- package/dist/esm/server/staticMiddleware.mjs +87 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
- package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
- package/dist/esm-node/cli/configPlugin.mjs +263 -0
- package/dist/esm-node/cli/index.mjs +67 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
- package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
- package/dist/esm-node/cli/utils.mjs +40 -0
- package/dist/esm-node/constant.mjs +3 -0
- package/dist/esm-node/logger.mjs +5 -0
- package/dist/esm-node/react/plugin.mjs +3 -0
- package/dist/esm-node/server/fileCache.mjs +37 -0
- package/dist/esm-node/server/index.mjs +34 -0
- package/dist/esm-node/server/staticMiddleware.mjs +42 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
- package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
- package/package.json +32 -31
- package/dist/cjs/cli/configPlugin.spec.js +0 -112
- package/dist/cjs/server/fileCache.spec.js +0 -28
- package/dist/cjs/server/staticMiddleware.spec.js +0 -185
- package/dist/esm/cli/configPlugin.js +0 -395
- package/dist/esm/cli/configPlugin.spec.js +0 -108
- package/dist/esm/cli/index.js +0 -92
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
- package/dist/esm/cli/ssrPlugin.js +0 -305
- package/dist/esm/cli/utils.js +0 -53
- package/dist/esm/constant.js +0 -6
- package/dist/esm/logger.js +0 -7
- package/dist/esm/react/plugin.js +0 -5
- package/dist/esm/server/fileCache.js +0 -98
- package/dist/esm/server/fileCache.spec.js +0 -50
- package/dist/esm/server/index.js +0 -41
- package/dist/esm/server/staticMiddleware.js +0 -104
- package/dist/esm/server/staticMiddleware.spec.js +0 -328
- package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
- package/dist/esm/ssr-runtime/devPlugin.js +0 -73
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
- package/dist/esm-node/cli/configPlugin.js +0 -347
- package/dist/esm-node/cli/configPlugin.spec.js +0 -89
- package/dist/esm-node/cli/index.js +0 -72
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
- package/dist/esm-node/cli/ssrPlugin.js +0 -280
- package/dist/esm-node/cli/utils.js +0 -53
- package/dist/esm-node/constant.js +0 -6
- package/dist/esm-node/logger.js +0 -7
- package/dist/esm-node/react/plugin.js +0 -5
- package/dist/esm-node/server/fileCache.js +0 -49
- package/dist/esm-node/server/fileCache.spec.js +0 -27
- package/dist/esm-node/server/index.js +0 -39
- package/dist/esm-node/server/staticMiddleware.js +0 -55
- package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
- package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
- /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
- /package/dist/esm/react/{index.js → index.mjs} +0 -0
- /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
- /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
- /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
- /package/dist/esm/types/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
- /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
- /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
- /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var import_vitest = require("vitest");
|
|
25
|
-
var import_configPlugin = require("./configPlugin");
|
|
26
|
-
var import_utils = require("./utils");
|
|
27
|
-
const mfConfig = {
|
|
28
|
-
name: "host",
|
|
29
|
-
filename: "remoteEntry.js",
|
|
30
|
-
remotes: {
|
|
31
|
-
remote: "http://localhost:3000/remoteEntry.js"
|
|
32
|
-
},
|
|
33
|
-
shared: {
|
|
34
|
-
react: {
|
|
35
|
-
singleton: true,
|
|
36
|
-
eager: true
|
|
37
|
-
},
|
|
38
|
-
"react-dom": {
|
|
39
|
-
singleton: true,
|
|
40
|
-
eager: true
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
(0, import_vitest.describe)("patchMFConfig", async () => {
|
|
45
|
-
(0, import_vitest.it)("patchMFConfig: server", async () => {
|
|
46
|
-
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
47
|
-
(0, import_configPlugin.patchMFConfig)(patchedConfig, true);
|
|
48
|
-
const ipv4 = (0, import_utils.getIPV4)();
|
|
49
|
-
(0, import_vitest.expect)(patchedConfig).toStrictEqual({
|
|
50
|
-
dev: false,
|
|
51
|
-
dts: false,
|
|
52
|
-
filename: "remoteEntry.js",
|
|
53
|
-
library: {
|
|
54
|
-
name: "host",
|
|
55
|
-
type: "commonjs-module"
|
|
56
|
-
},
|
|
57
|
-
name: "host",
|
|
58
|
-
remotes: {
|
|
59
|
-
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
60
|
-
},
|
|
61
|
-
remoteType: "script",
|
|
62
|
-
runtimePlugins: [
|
|
63
|
-
require.resolve("@module-federation/modern-js/shared-strategy"),
|
|
64
|
-
require.resolve("@module-federation/node/runtimePlugin"),
|
|
65
|
-
require.resolve("@module-federation/modern-js/inject-node-fetch")
|
|
66
|
-
],
|
|
67
|
-
shared: {
|
|
68
|
-
react: {
|
|
69
|
-
eager: true,
|
|
70
|
-
singleton: true
|
|
71
|
-
},
|
|
72
|
-
"react-dom": {
|
|
73
|
-
eager: true,
|
|
74
|
-
singleton: true
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
(0, import_vitest.it)("patchMFConfig: client", async () => {
|
|
80
|
-
const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
81
|
-
(0, import_configPlugin.patchMFConfig)(patchedConfig, false);
|
|
82
|
-
const ipv4 = (0, import_utils.getIPV4)();
|
|
83
|
-
(0, import_vitest.expect)(patchedConfig).toStrictEqual({
|
|
84
|
-
filename: "remoteEntry.js",
|
|
85
|
-
name: "host",
|
|
86
|
-
remotes: {
|
|
87
|
-
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
88
|
-
},
|
|
89
|
-
remoteType: "script",
|
|
90
|
-
runtimePlugins: [
|
|
91
|
-
require.resolve("@module-federation/modern-js/shared-strategy")
|
|
92
|
-
],
|
|
93
|
-
shared: {
|
|
94
|
-
react: {
|
|
95
|
-
eager: true,
|
|
96
|
-
singleton: true
|
|
97
|
-
},
|
|
98
|
-
"react-dom": {
|
|
99
|
-
eager: true,
|
|
100
|
-
singleton: true
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
dts: {
|
|
104
|
-
consumeTypes: {
|
|
105
|
-
runtimePkgs: [
|
|
106
|
-
"@module-federation/modern-js/runtime"
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var import_vitest = require("vitest");
|
|
3
|
-
var import_fileCache = require("./fileCache");
|
|
4
|
-
(0, import_vitest.beforeAll)(() => {
|
|
5
|
-
import_vitest.vi.mock("fs-extra", () => ({
|
|
6
|
-
default: {
|
|
7
|
-
pathExists: () => {
|
|
8
|
-
return true;
|
|
9
|
-
},
|
|
10
|
-
lstat: () => {
|
|
11
|
-
return {
|
|
12
|
-
mtimeMs: Date.now(),
|
|
13
|
-
size: 4
|
|
14
|
-
};
|
|
15
|
-
},
|
|
16
|
-
readFile: () => {
|
|
17
|
-
return "test";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
});
|
|
22
|
-
(0, import_vitest.describe)("modern serve static file cache", async () => {
|
|
23
|
-
(0, import_vitest.it)("should cache file", async () => {
|
|
24
|
-
const cache = new import_fileCache.FileCache();
|
|
25
|
-
const result = await cache.getFile("test.txt");
|
|
26
|
-
(0, import_vitest.expect)(result === null || result === void 0 ? void 0 : result.content).toBe("test");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var import_vitest = require("vitest");
|
|
25
|
-
var import_staticMiddleware = require("./staticMiddleware");
|
|
26
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
27
|
-
var import_fileCache = require("./fileCache");
|
|
28
|
-
import_vitest.vi.mock("fs-extra", () => ({
|
|
29
|
-
default: {
|
|
30
|
-
pathExists: import_vitest.vi.fn()
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
import_vitest.vi.mock("./fileCache", () => ({
|
|
34
|
-
fileCache: {
|
|
35
|
-
getFile: import_vitest.vi.fn()
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
(0, import_vitest.describe)("staticMiddleware", () => {
|
|
39
|
-
let middleware;
|
|
40
|
-
let mockContext;
|
|
41
|
-
let nextSpy;
|
|
42
|
-
(0, import_vitest.beforeEach)(() => {
|
|
43
|
-
import_vitest.vi.clearAllMocks();
|
|
44
|
-
middleware = (0, import_staticMiddleware.createStaticMiddleware)({
|
|
45
|
-
assetPrefix: "",
|
|
46
|
-
pwd: "/test/path"
|
|
47
|
-
});
|
|
48
|
-
nextSpy = import_vitest.vi.fn();
|
|
49
|
-
mockContext = {
|
|
50
|
-
req: {
|
|
51
|
-
path: ""
|
|
52
|
-
},
|
|
53
|
-
header: import_vitest.vi.fn(),
|
|
54
|
-
body: import_vitest.vi.fn()
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
(0, import_vitest.describe)("file extension filtering", () => {
|
|
58
|
-
(0, import_vitest.it)("should call next() for non-js files", async () => {
|
|
59
|
-
mockContext.req.path = "/bundles/test.css";
|
|
60
|
-
await middleware(mockContext, nextSpy);
|
|
61
|
-
(0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
|
|
62
|
-
(0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
|
|
63
|
-
(0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
|
|
64
|
-
});
|
|
65
|
-
(0, import_vitest.it)("should call next() for files without extension", async () => {
|
|
66
|
-
mockContext.req.path = "/bundles/test";
|
|
67
|
-
await middleware(mockContext, nextSpy);
|
|
68
|
-
(0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
|
|
69
|
-
(0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
|
|
70
|
-
(0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
|
|
71
|
-
});
|
|
72
|
-
(0, import_vitest.it)("should process .js files", async () => {
|
|
73
|
-
mockContext.req.path = "/bundles/test.js";
|
|
74
|
-
import_fs_extra.default.pathExists.mockResolvedValue(false);
|
|
75
|
-
await middleware(mockContext, nextSpy);
|
|
76
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalled();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
(0, import_vitest.describe)("asset prefix filtering", () => {
|
|
80
|
-
(0, import_vitest.it)("should call next() for paths not starting with /bundles", async () => {
|
|
81
|
-
mockContext.req.path = "/assets/test.js";
|
|
82
|
-
await middleware(mockContext, nextSpy);
|
|
83
|
-
(0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
|
|
84
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).not.toHaveBeenCalled();
|
|
85
|
-
(0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
|
|
86
|
-
(0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
88
|
-
(0, import_vitest.it)("should call next() for root path", async () => {
|
|
89
|
-
mockContext.req.path = "/test.js";
|
|
90
|
-
await middleware(mockContext, nextSpy);
|
|
91
|
-
(0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
|
|
92
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).not.toHaveBeenCalled();
|
|
93
|
-
});
|
|
94
|
-
(0, import_vitest.it)("should process paths starting with /bundles", async () => {
|
|
95
|
-
mockContext.req.path = "/bundles/test.js";
|
|
96
|
-
import_fs_extra.default.pathExists.mockResolvedValue(false);
|
|
97
|
-
await middleware(mockContext, nextSpy);
|
|
98
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/test.js");
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
(0, import_vitest.describe)("file existence check", () => {
|
|
102
|
-
(0, import_vitest.it)("should call next() when file does not exist", async () => {
|
|
103
|
-
mockContext.req.path = "/bundles/nonexistent.js";
|
|
104
|
-
import_fs_extra.default.pathExists.mockResolvedValue(false);
|
|
105
|
-
await middleware(mockContext, nextSpy);
|
|
106
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/nonexistent.js");
|
|
107
|
-
(0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
|
|
108
|
-
(0, import_vitest.expect)(import_fileCache.fileCache.getFile).not.toHaveBeenCalled();
|
|
109
|
-
(0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
|
|
110
|
-
(0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
|
|
111
|
-
});
|
|
112
|
-
(0, import_vitest.it)("should proceed to file cache when file exists", async () => {
|
|
113
|
-
mockContext.req.path = "/bundles/existing.js";
|
|
114
|
-
import_fs_extra.default.pathExists.mockResolvedValue(true);
|
|
115
|
-
import_fileCache.fileCache.getFile.mockResolvedValue(null);
|
|
116
|
-
await middleware(mockContext, nextSpy);
|
|
117
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/existing.js");
|
|
118
|
-
(0, import_vitest.expect)(import_fileCache.fileCache.getFile).toHaveBeenCalledWith("/test/path/bundles/existing.js");
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
(0, import_vitest.describe)("successful file serving", () => {
|
|
122
|
-
(0, import_vitest.it)("should serve file content with correct headers", async () => {
|
|
123
|
-
const mockFileContent = 'console.log("test");';
|
|
124
|
-
const mockFileResult = {
|
|
125
|
-
content: mockFileContent,
|
|
126
|
-
lastModified: Date.now()
|
|
127
|
-
};
|
|
128
|
-
mockContext.req.path = "/bundles/app.js";
|
|
129
|
-
import_fs_extra.default.pathExists.mockResolvedValue(true);
|
|
130
|
-
import_fileCache.fileCache.getFile.mockResolvedValue(mockFileResult);
|
|
131
|
-
mockContext.body.mockReturnValue("response");
|
|
132
|
-
const result = await middleware(mockContext, nextSpy);
|
|
133
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/app.js");
|
|
134
|
-
(0, import_vitest.expect)(import_fileCache.fileCache.getFile).toHaveBeenCalledWith("/test/path/bundles/app.js");
|
|
135
|
-
(0, import_vitest.expect)(nextSpy).not.toHaveBeenCalled();
|
|
136
|
-
(0, import_vitest.expect)(mockContext.header).toHaveBeenCalledWith("Content-Type", "application/javascript");
|
|
137
|
-
(0, import_vitest.expect)(mockContext.header).toHaveBeenCalledWith("Content-Length", String(mockFileResult.content.length));
|
|
138
|
-
(0, import_vitest.expect)(mockContext.body).toHaveBeenCalledWith(mockFileResult.content, 200);
|
|
139
|
-
(0, import_vitest.expect)(result).toBe("response");
|
|
140
|
-
});
|
|
141
|
-
(0, import_vitest.it)("should handle empty file content", async () => {
|
|
142
|
-
const mockFileResult = {
|
|
143
|
-
content: "",
|
|
144
|
-
lastModified: Date.now()
|
|
145
|
-
};
|
|
146
|
-
mockContext.req.path = "/bundles/empty.js";
|
|
147
|
-
import_fs_extra.default.pathExists.mockResolvedValue(true);
|
|
148
|
-
import_fileCache.fileCache.getFile.mockResolvedValue(mockFileResult);
|
|
149
|
-
mockContext.body.mockReturnValue("empty-response");
|
|
150
|
-
const result = await middleware(mockContext, nextSpy);
|
|
151
|
-
(0, import_vitest.expect)(mockContext.header).toHaveBeenCalledWith("Content-Length", "0");
|
|
152
|
-
(0, import_vitest.expect)(mockContext.body).toHaveBeenCalledWith(mockFileResult.content, 200);
|
|
153
|
-
(0, import_vitest.expect)(result).toBe("empty-response");
|
|
154
|
-
(0, import_vitest.expect)(nextSpy).not.toHaveBeenCalled();
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
(0, import_vitest.describe)("asset prefix handling", () => {
|
|
158
|
-
(0, import_vitest.it)("should handle custom asset prefix correctly", async () => {
|
|
159
|
-
const customMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
|
|
160
|
-
assetPrefix: "/custom-prefix",
|
|
161
|
-
pwd: "/test/path"
|
|
162
|
-
});
|
|
163
|
-
mockContext.req.path = "/bundles/test.js";
|
|
164
|
-
await customMiddleware(mockContext, nextSpy);
|
|
165
|
-
(0, import_vitest.expect)(nextSpy).toHaveBeenCalledOnce();
|
|
166
|
-
(0, import_vitest.expect)(mockContext.header).not.toHaveBeenCalled();
|
|
167
|
-
(0, import_vitest.expect)(mockContext.body).not.toHaveBeenCalled();
|
|
168
|
-
});
|
|
169
|
-
(0, import_vitest.it)("should handle asset prefix removal correctly", async () => {
|
|
170
|
-
const customMiddleware = (0, import_staticMiddleware.createStaticMiddleware)({
|
|
171
|
-
assetPrefix: "/prefix",
|
|
172
|
-
pwd: "/test/path"
|
|
173
|
-
});
|
|
174
|
-
const mockFileResult = {
|
|
175
|
-
content: "test content",
|
|
176
|
-
lastModified: Date.now()
|
|
177
|
-
};
|
|
178
|
-
mockContext.req.path = "/prefix/bundles/test.js";
|
|
179
|
-
import_fs_extra.default.pathExists.mockResolvedValue(true);
|
|
180
|
-
import_fileCache.fileCache.getFile.mockResolvedValue(mockFileResult);
|
|
181
|
-
await customMiddleware(mockContext, nextSpy);
|
|
182
|
-
(0, import_vitest.expect)(import_fs_extra.default.pathExists).toHaveBeenCalledWith("/test/path/bundles/test.js");
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|