Repository: denoland/fresh
File: tests/dev_command_test.ts (TypeScript)

Code before:
    options: {
      env: {
        DENO_DEPLOYMENT_ID: "foo",
      },
    },
  }, async (address) => {
    await t.step("useState", async () => {
      const doc = await fetchHtml(`${address}/hooks-server/useState`);
      assertNotSelector(doc, "pre");
    });

    await t.step("useReducer", async () => {
      const doc = await fetchHtml(`${address}/hooks-server/useReducer`);
      assertNotSelector(doc, "pre");
    });
  });
});

Deno.test("show codeframe in dev mode even with custom 500", async () => {
  // await withFakeServe(
  //   "./tests/fixture_dev_codeframe/dev.ts",
  //   async (server) => {
  //     const doc = await server.getHtml(`/`);
  //     assertSelector(doc, ".frsh-error-page");
  //   },
  // );

  await withFakeServe(
    "./tests/fixture_dev_codeframe/main.ts",
    async (server) => {
      const doc = await server.getHtml(`/`);
      assertNotSelector(doc, ".frsh-error-page");
      assertSelector(doc, "h1");
    },
  );
});

Deno.test("serve client script source map", async () => {
  await withFakeServe(
    "./tests/fixture/dev.ts",
    async (server) => {
      const res = await server.get(`/_frsh/fresh_dev_client.js`);
      await res.text(); // Consume body
      assertEquals(res.status, 200);
      assertEquals(
        res.headers.get("Content-Type"),
        "application/javascript; charset=UTF-8",
      );

      const res2 = await server.get(`/_frsh/fresh_dev_client.js.map`);
      const json = await res2.json();

Review comment (suggestion):
I'm not sure what to do about this test (or the one below). There seems to be a bit of overlap between this one and `tests/error_test.ts`, and I do not feel like this test has the desirable result.

Code after:
      env: {
        DENO_DEPLOYMENT_ID: "foo",
      },
    },
  }, async (address) => {
    await t.step("useState", async () => {
      const doc = await fetchHtml(`${address}/hooks-server/useState`);
      assertNotSelector(doc, "pre");
    });

    await t.step("useReducer", async () => {
      const doc = await fetchHtml(`${address}/hooks-server/useReducer`);
      assertNotSelector(doc, "pre");
    });
  });
});

Deno.test("show codeframe in dev mode even with custom 500", async () => {
  await withFakeServe(
    "./tests/fixture_dev_codeframe/dev.ts",
    async (server) => {
      const { title } = await getErrorOverlay(server, "/");
      assertEquals(title, "fail");
    },
  );

  await withFakeServe(
    "./tests/fixture_dev_codeframe/main.ts",
    async (server) => {
      const doc = await server.getHtml("/");
      assertNotSelector(doc, "#fresh-error-overlay");
    },
  );
});

Deno.test("serve client script source map", async () => {
  await withFakeServe(
    "./tests/fixture/dev.ts",
    async (server) => {
      const res = await server.get(`/_frsh/fresh_dev_client.js`);
      await res.text(); // Consume body
      assertEquals(res.status, 200);
      assertEquals(
        res.headers.get("Content-Type"),
        "application/javascript; charset=UTF-8",
      );

      const res2 = await server.get(`/_frsh/fresh_dev_client.js.map`);
      const json = await res2.json();
      assertEquals(res2.status, 200);
      assertEquals(