Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drudrum committed Jun 1, 2021
1 parent 59382db commit 8825e2e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@
},
"historyApiFallback": {
"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",
"anyOf": [
{
"type": "boolean"
}
]
"type": "boolean"
},
"stats": {
"description": "Stats options object or preset name.",
Expand Down
5 changes: 4 additions & 1 deletion src/utils/getFilenameFromUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export default function getFilenameFromUrl(context, url) {
filename = path.join(outputPath, querystring.unescape(pathname));
}

if (!context.outputFileSystem.existsSync(filename) && options.historyApiFallback){
if (
!context.outputFileSystem.existsSync(filename) &&
options.historyApiFallback
) {
filename = path.join(outputPath);
}

Expand Down
21 changes: 21 additions & 0 deletions test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,27 @@ describe.each([
});
});

describe("historyApiFallback option", () => {
describe("index.html page will likely have to be served in place of any 404 responses", () => {
beforeAll((done) => {
const compiler = getCompiler(webpackConfig);

instance = middleware(compiler, { historyApiFallback: true });

app = framework();
app.use(instance);

listen = listenShorthand(done);
});

afterAll(close);

it('should return the "200" code for the "GET" request', (done) => {
request(app).get("/foo/bar/baz").expect(200, done);
});
});
});

describe("serverSideRender option", () => {
let locals;

Expand Down
4 changes: 4 additions & 0 deletions test/validation-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe("validation", () => {
success: ["/foo", "", "auto", () => "/public/path"],
failure: [false],
},
historyApiFallback: {
success: [true],
failure: [],
},
serverSideRender: {
success: [true],
failure: ["foo", 0],
Expand Down

0 comments on commit 8825e2e

Please sign in to comment.