This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathpreRenderedIndexPages.test.js
76 lines (62 loc) · 2.22 KB
/
preRenderedIndexPages.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Test that next-on-netlify does not crash when pre-rendering index.js file.
// See: https://github.com/netlify/next-on-netlify/issues/2#issuecomment-636415494
const { parse, join } = require("path");
const { existsSync, readdirSync, readFileSync } = require("fs-extra");
const buildNextApp = require("./helpers/buildNextApp");
// The name of this test file (without extension)
const FILENAME = parse(__filename).name;
// The directory which will be used for testing.
// We simulate a NextJS app within that directory, with pages, and a
// package.json file.
const PROJECT_PATH = join(__dirname, "builds", FILENAME);
// Capture the output to verify successful build
let buildOutput;
beforeAll(
async () => {
buildOutput = await buildNextApp()
.forTest(__filename)
.withPages("pages-with-prerendered-index")
.withNextConfig("next.config.js")
.withPackageJson("package.json")
.build();
},
// time out after 180 seconds
180 * 1000
);
describe("next-on-netlify", () => {
test("builds successfully", () => {
expect(buildOutput).toMatch("Next on Netlify");
expect(buildOutput).toMatch("Success! All done!");
});
});
describe("Static Pages", () => {
test("copies static pages to output directory", () => {
const OUTPUT_PATH = join(PROJECT_PATH, "out_publish");
expect(existsSync(join(OUTPUT_PATH, "index.html"))).toBe(true);
expect(existsSync(join(OUTPUT_PATH, "shows.html"))).toBe(true);
});
test("copies static assets to out_publish/_next/ directory", () => {
const dirs = readdirSync(
join(PROJECT_PATH, "out_publish", "_next", "static")
);
expect(dirs.length).toBe(2);
expect(dirs).toContain("chunks");
});
});
describe("404 Page", () => {
test("copies 404.html to output directory", () => {
const OUTPUT_PATH = join(PROJECT_PATH, "out_publish");
expect(existsSync(join(OUTPUT_PATH, "404.html"))).toBe(true);
});
});
describe("Routing", () => {
test("does not create any redirects", async () => {
// Read _redirects file
const contents = readFileSync(
join(PROJECT_PATH, "out_publish", "_redirects")
);
const redirects = contents.toString();
// Check that no redirects are present
expect(redirects).toEqual("");
});
});