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 pathdynamicImports.test.js
50 lines (42 loc) · 1.59 KB
/
dynamicImports.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
// Test next-on-netlify when config is set from a function in next.config.js
// See: https://github.com/netlify/next-on-netlify/issues/25
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-dynamic-imports")
.withNextConfig("next.config.js-est")
.withPackageJson("package.json")
.withFile("components/Header.js", join("components", "Header.js"))
.build();
},
// time out after 180 seconds
180 * 1000
);
describe("next-on-netlify", () => {
const functionsDir = join(PROJECT_PATH, "out_functions");
test("builds successfully", () => {
expect(buildOutput).toMatch("Next on Netlify");
expect(buildOutput).toMatch("Success! All done!");
});
test("copies chunk files to ", () => {
const functionFiles = readdirSync(join(functionsDir, "next_index"));
const chunkRegex = new RegExp(/(\.?[-_$~A-Z0-9a-z]+){1,}\.js$/g);
let chunkFileExists;
functionFiles.forEach((file) => {
chunkFileExists = chunkRegex.test(file);
});
expect(chunkFileExists).toBe(true);
});
});