|
| 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 | +}); |
0 commit comments