Skip to content

Commit 90921fd

Browse files
authored
fix: add tests for 404 response on non-existent files and update logic for URL handling
1 parent e0af6e5 commit 90921fd

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/utils/getFilenameFromUrl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ function getFilenameFromUrl(context, url, extra = {}) {
125125
filename = path.join(filename, "index.html");
126126
}
127127
}
128+
128129
extra.stats = context.outputFileSystem.statSync(filename);
129130
} catch {
130131
continue;

test/middleware.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,10 @@ describe.each([
17281728
value: "noextension",
17291729
code: 200,
17301730
},
1731+
{
1732+
value: "noextension/",
1733+
code: 404,
1734+
},
17311735
],
17321736
},
17331737
{
@@ -1772,6 +1776,11 @@ describe.each([
17721776
contentType: "text/plain; charset=utf-8",
17731777
code: 200,
17741778
},
1779+
{
1780+
value: "windows%202.txt/",
1781+
contentType: get404ContentTypeHeader(name),
1782+
code: 404,
1783+
},
17751784
],
17761785
},
17771786
{
@@ -1937,7 +1946,7 @@ describe.each([
19371946

19381947
expect(response.statusCode).toEqual(code);
19391948

1940-
if (data) {
1949+
if (data && code !== 404) {
19411950
expect(response.headers["content-length"]).toEqual(
19421951
String(data.length),
19431952
);
@@ -5179,6 +5188,15 @@ describe.each([
51795188
"text/html; charset=utf-8",
51805189
);
51815190
});
5191+
5192+
it('should return the "404" code for the "GET" request with a non-existent file', async () => {
5193+
const response = await req.get("/default.html/");
5194+
5195+
expect(response.statusCode).toBe(404);
5196+
expect(response.headers["content-type"]).toBe(
5197+
get404ContentTypeHeader(name),
5198+
);
5199+
});
51825200
});
51835201

51845202
describe('should work with "string" value with a custom extension', () => {

0 commit comments

Comments
 (0)