summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test/functions/dynamic-route.test.js
blob: 69d25a11e6d21bae26deb181b81fe262610ddf6e (plain) (blame)
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
import { expect } from "chai";
import { cli } from "./test-utils.js";
import { fileURLToPath } from "url";
import fs from "fs/promises";

const root = new URL("./fixtures/dynamic-route/", import.meta.url).toString();

describe("Dynamic pages", () => {
  before(async () => {
    await cli("build", "--root", fileURLToPath(root));
  });

  it("Dynamic pages are included in the redirects file", async () => {
    const redir = await fs.readFile(
      new URL("./dist/_redirects", root),
      "utf-8",
    );
    expect(redir).to.match(/\/products\/:id/);
  });

  it("Prerendered routes are also included using placeholder syntax", async () => {
    const redir = await fs.readFile(
      new URL("./dist/_redirects", root),
      "utf-8",
    );
    expect(redir).to.include(
      "/pets/:cat       /pets/:cat/index.html        200",
    );
    expect(redir).to.include(
      "/pets/:dog       /pets/:dog/index.html        200",
    );
    expect(redir).to.include(
      "/pets            /.netlify/functions/entry    200",
    );
  });
});