Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 98c00e2

Browse files
committed
add custom headers test
1 parent 8aa84e3 commit 98c00e2

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

tests/customHeaders.test.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Test next-on-netlify when a custom distDir is set in next.config.js
2+
3+
const { EOL } = require("os");
4+
const { parse, join } = require("path");
5+
const { readFileSync } = require("fs-extra");
6+
const buildNextApp = require("./helpers/buildNextApp");
7+
8+
// The name of this test file (without extension)
9+
const FILENAME = parse(__filename).name;
10+
11+
// The directory which will be used for testing.
12+
// We simulate a NextJS app within that directory, with pages, and a
13+
// package.json file.
14+
const PROJECT_PATH = join(__dirname, "builds", FILENAME);
15+
16+
// Capture the output to verify successful build
17+
let buildOutput;
18+
19+
beforeAll(
20+
async () => {
21+
buildOutput = await buildNextApp()
22+
.forTest(__filename)
23+
.withPages("pages-with-static-props-index")
24+
.withNextConfig("next.config.js")
25+
.withPackageJson("package.json")
26+
.withFile("_headers")
27+
.build();
28+
},
29+
// time out after 180 seconds
30+
180 * 1000
31+
);
32+
33+
describe("next-on-netlify", () => {
34+
test("builds successfully", () => {
35+
expect(buildOutput).toMatch("Next on Netlify");
36+
expect(buildOutput).toMatch("Success! All done!");
37+
});
38+
});
39+
40+
describe("Headers", () => {
41+
test("includes custom header rules", async () => {
42+
// Read _redirects file
43+
const contents = readFileSync(
44+
join(PROJECT_PATH, "out_publish", "_headers"),
45+
"utf8"
46+
);
47+
48+
const headers = contents.trim().split(EOL);
49+
expect(headers[0]).toEqual("/templates/index.html");
50+
});
51+
});

tests/fixtures/_headers

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/templates/index.html
2+
# headers for that path:
3+
X-Frame-Options: DENY
4+
X-XSS-Protection: 1; mode=block
5+
6+
/templates/index2.html
7+
# headers for that path:
8+
X-Frame-Options: SAMEORIGIN

0 commit comments

Comments
 (0)