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 pathoptionalCatchAll.test.js
60 lines (50 loc) · 1.77 KB
/
optionalCatchAll.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
// 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 { 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);
// The directory that contains the fixtures, such as NextJS pages,
// NextJS config, and package.json
const FIXTURE_PATH = join(__dirname, "fixtures");
// Capture the output to verify successful build
let buildOutput;
beforeAll(
async () => {
buildOutput = await buildNextApp()
.forTest(__filename)
.withPages("pages-with-optionalCatchAll")
.withNextConfig("next.config.js-with-optionalCatchAll")
.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("Routing", () => {
test("creates Netlify redirects", async () => {
// Read _redirects file
const contents = readFileSync(
join(PROJECT_PATH, "out_publish", "_redirects")
);
let redirects = contents.toString();
// Replace non-persistent build ID with placeholder
redirects = redirects.replace(
/\/_next\/data\/[^\/]+\//g,
"/_next/data/%BUILD_ID%/"
);
// Check that redirects match
expect(redirects).toMatchSnapshot();
});
});