Skip to content

Commit 8825e2e

Browse files
committed
Tests
1 parent 59382db commit 8825e2e

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/options.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@
5050
},
5151
"historyApiFallback": {
5252
"description": "When using the HTML5 History API, the index.html page will likely have to be served in place of any 404 responses. Enable historyApiFallback by setting it to true",
53-
"anyOf": [
54-
{
55-
"type": "boolean"
56-
}
57-
]
53+
"type": "boolean"
5854
},
5955
"stats": {
6056
"description": "Stats options object or preset name.",

src/utils/getFilenameFromUrl.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export default function getFilenameFromUrl(context, url) {
5353
filename = path.join(outputPath, querystring.unescape(pathname));
5454
}
5555

56-
if (!context.outputFileSystem.existsSync(filename) && options.historyApiFallback){
56+
if (
57+
!context.outputFileSystem.existsSync(filename) &&
58+
options.historyApiFallback
59+
) {
5760
filename = path.join(outputPath);
5861
}
5962

test/middleware.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,27 @@ describe.each([
25662566
});
25672567
});
25682568

2569+
describe("historyApiFallback option", () => {
2570+
describe("index.html page will likely have to be served in place of any 404 responses", () => {
2571+
beforeAll((done) => {
2572+
const compiler = getCompiler(webpackConfig);
2573+
2574+
instance = middleware(compiler, { historyApiFallback: true });
2575+
2576+
app = framework();
2577+
app.use(instance);
2578+
2579+
listen = listenShorthand(done);
2580+
});
2581+
2582+
afterAll(close);
2583+
2584+
it('should return the "200" code for the "GET" request', (done) => {
2585+
request(app).get("/foo/bar/baz").expect(200, done);
2586+
});
2587+
});
2588+
});
2589+
25692590
describe("serverSideRender option", () => {
25702591
let locals;
25712592

test/validation-options.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ describe("validation", () => {
3535
success: ["/foo", "", "auto", () => "/public/path"],
3636
failure: [false],
3737
},
38+
historyApiFallback: {
39+
success: [true],
40+
failure: [],
41+
},
3842
serverSideRender: {
3943
success: [true],
4044
failure: ["foo", 0],

0 commit comments

Comments
 (0)