Skip to content

Commit 78e76df

Browse files
snitin315alexander-akait
authored andcommitted
test: add cases for staticOptions normalization (#4969)
1 parent 5c84368 commit 78e76df

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

lib/Server.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,9 @@ class Server {
852852
typeof optionsForStatic.directory !== "undefined"
853853
? optionsForStatic.directory
854854
: def.directory,
855-
// TODO: do merge in the next major release
856855
staticOptions:
857856
typeof optionsForStatic.staticOptions !== "undefined"
858-
? optionsForStatic.staticOptions
857+
? { ...def.staticOptions, ...optionsForStatic.staticOptions }
859858
: def.staticOptions,
860859
publicPath:
861860
// eslint-disable-next-line no-nested-ternary

test/__snapshots__/normalize-options.test.js.snap.webpack5

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,65 @@ exports[`normalize options static is an object 1`] = `
20452045
}
20462046
`;
20472047

2048+
exports[`normalize options static is an object with staticOptions 1`] = `
2049+
{
2050+
"allowedHosts": "auto",
2051+
"bonjour": false,
2052+
"client": {
2053+
"logging": "info",
2054+
"overlay": true,
2055+
"reconnect": 10,
2056+
"webSocketURL": {},
2057+
},
2058+
"compress": true,
2059+
"devMiddleware": {},
2060+
"historyApiFallback": false,
2061+
"host": undefined,
2062+
"hot": true,
2063+
"liveReload": true,
2064+
"open": [],
2065+
"port": "<auto>",
2066+
"server": {
2067+
"options": {},
2068+
"type": "http",
2069+
},
2070+
"setupExitSignals": true,
2071+
"static": [
2072+
{
2073+
"directory": "/static/path",
2074+
"publicPath": [
2075+
"/",
2076+
],
2077+
"serveIndex": {
2078+
"icons": true,
2079+
},
2080+
"staticOptions": {
2081+
"immutable": true,
2082+
"redirect": true,
2083+
},
2084+
"watch": {
2085+
"alwaysStat": true,
2086+
"atomic": false,
2087+
"followSymlinks": false,
2088+
"ignoreInitial": true,
2089+
"ignorePermissionErrors": true,
2090+
"ignored": undefined,
2091+
"interval": undefined,
2092+
"persistent": true,
2093+
"usePolling": false,
2094+
},
2095+
},
2096+
],
2097+
"watchFiles": [],
2098+
"webSocketServer": {
2099+
"options": {
2100+
"path": "/ws",
2101+
},
2102+
"type": "ws",
2103+
},
2104+
}
2105+
`;
2106+
20482107
exports[`normalize options static is false 1`] = `
20492108
{
20502109
"allowedHosts": "auto",

test/normalize-options.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,19 @@ describe("normalize options", () => {
380380
},
381381
},
382382
},
383+
{
384+
title: "static is an object with staticOptions",
385+
multiCompiler: false,
386+
options: {
387+
static: {
388+
directory: "/static/path",
389+
staticOptions: {
390+
redirect: true,
391+
immutable: true,
392+
},
393+
},
394+
},
395+
},
383396
{
384397
title: "static directory is an absolute url and throws error",
385398
multiCompiler: false,

0 commit comments

Comments
 (0)