Skip to content

Commit

Permalink
test: add cases for staticOptions normalization (#4969)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored Aug 6, 2023
1 parent a87dc53 commit a8b82b0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,9 @@ class Server {
typeof optionsForStatic.directory !== "undefined"
? optionsForStatic.directory
: def.directory,
// TODO: do merge in the next major release
staticOptions:
typeof optionsForStatic.staticOptions !== "undefined"
? optionsForStatic.staticOptions
? { ...def.staticOptions, ...optionsForStatic.staticOptions }
: def.staticOptions,
publicPath:
// eslint-disable-next-line no-nested-ternary
Expand Down
59 changes: 59 additions & 0 deletions test/__snapshots__/normalize-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,65 @@ exports[`normalize options static is an object 1`] = `
}
`;

exports[`normalize options static is an object with staticOptions 1`] = `
{
"allowedHosts": "auto",
"bonjour": false,
"client": {
"logging": "info",
"overlay": true,
"reconnect": 10,
"webSocketURL": {},
},
"compress": true,
"devMiddleware": {},
"historyApiFallback": false,
"host": undefined,
"hot": true,
"liveReload": true,
"open": [],
"port": "<auto>",
"server": {
"options": {},
"type": "http",
},
"setupExitSignals": true,
"static": [
{
"directory": "/static/path",
"publicPath": [
"/",
],
"serveIndex": {
"icons": true,
},
"staticOptions": {
"immutable": true,
"redirect": true,
},
"watch": {
"alwaysStat": true,
"atomic": false,
"followSymlinks": false,
"ignoreInitial": true,
"ignorePermissionErrors": true,
"ignored": undefined,
"interval": undefined,
"persistent": true,
"usePolling": false,
},
},
],
"watchFiles": [],
"webSocketServer": {
"options": {
"path": "/ws",
},
"type": "ws",
},
}
`;

exports[`normalize options static is false 1`] = `
{
"allowedHosts": "auto",
Expand Down
13 changes: 13 additions & 0 deletions test/normalize-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,19 @@ describe("normalize options", () => {
},
},
},
{
title: "static is an object with staticOptions",
multiCompiler: false,
options: {
static: {
directory: "/static/path",
staticOptions: {
redirect: true,
immutable: true,
},
},
},
},
{
title: "static directory is an absolute url and throws error",
multiCompiler: false,
Expand Down

0 comments on commit a8b82b0

Please sign in to comment.