Skip to content

Commit 4b0b898

Browse files
authored
test: add 200 and 404 response checks for GET requests to "/slug/" and "/slug" paths
1 parent 6a8465e commit 4b0b898

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/utils/getFilenameFromUrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function getFilenameFromUrl(context, url) {
122122
if (filename[filename.length - 1] === "/") {
123123
if (options.index === false) {
124124
return;
125-
} else if (options.index === "string") {
125+
} else if (typeof options.index === "string") {
126126
filename = path.join(filename, options.index);
127127
} else {
128128
filename = path.join(filename, "index.html");

test/middleware.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5187,10 +5187,22 @@ describe.each([
51875187
instance.context.outputFileSystem.mkdirSync(outputPath, {
51885188
recursive: true,
51895189
});
5190+
5191+
instance.context.outputFileSystem.mkdirSync(
5192+
path.resolve(outputPath, "slug"),
5193+
{
5194+
recursive: true,
5195+
},
5196+
);
51905197
instance.context.outputFileSystem.writeFileSync(
51915198
path.resolve(outputPath, "default.html"),
51925199
"hello",
51935200
);
5201+
5202+
instance.context.outputFileSystem.writeFileSync(
5203+
path.resolve(outputPath, "slug", "default.html"),
5204+
"hello",
5205+
);
51945206
});
51955207

51965208
afterAll(async () => {
@@ -5206,6 +5218,24 @@ describe.each([
52065218
);
52075219
});
52085220

5221+
it('should return the "200" code for the "GET" request to the "/slug/" path', async () => {
5222+
const response = await req.get("/slug/");
5223+
5224+
expect(response.statusCode).toBe(200);
5225+
expect(response.headers["content-type"]).toBe(
5226+
"text/html; charset=utf-8",
5227+
);
5228+
});
5229+
5230+
it('should return the "404" code for the "GET" request to the "/slug" path', async () => {
5231+
const response = await req.get("/slug");
5232+
5233+
expect(response.statusCode).toBe(404);
5234+
expect(response.headers["content-type"]).toEqual(
5235+
get404ContentTypeHeader(name),
5236+
);
5237+
});
5238+
52095239
it('should return the "404" code for the "GET" request with a non-existent file', async () => {
52105240
const response = await req.get("/default.html/");
52115241

0 commit comments

Comments
 (0)