Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line no-restricted-imports -- expect used in afterAll which has no test context
import { afterAll, describe, expect, test } from "vitest";
import { afterAll, assert, describe, test } from "vitest";
import {
getJsonResponse,
getTextResponse,
Expand All @@ -9,11 +8,18 @@ import {

describe("module resolution", async () => {
afterAll(() => {
expect(serverLogs.errors).toEqual([]);
assert(
serverLogs.errors.length === 0,
`Unexpected server error logs remaining after tests:\n${serverLogs.errors
.map((error) => ` - ${error}`)
.join("\n")}\n`
);
});

describe("basic module resolution", () => {
test("`require` js/cjs files with specifying their file extension", async () => {
test("`require` js/cjs files with specifying their file extension", async ({
expect,
}) => {
const result = await getJsonResponse("/require-ext");
expect(result).toEqual({
"(requires/ext) hello.cjs (wrong-extension)": null,
Expand All @@ -22,14 +28,16 @@ describe("module resolution", async () => {
});
});

test("`require` js/cjs files without specifying their file extension", async () => {
test("`require` js/cjs files without specifying their file extension", async ({
expect,
}) => {
const result = await getJsonResponse("/require-no-ext");
expect(result).toEqual({
"(requires/no-ext) helloWorld": "hello (.js) world (.cjs)",
});
});

test("`require` json files", async () => {
test("`require` json files", async ({ expect }) => {
const result = await getJsonResponse("/require-json");
expect(result).toEqual({
"(requires/json) package name":
Expand All @@ -40,7 +48,7 @@ describe("module resolution", async () => {
});

describe("Cloudflare specific module resolution", () => {
test("internal imports from `cloudflare:*`", async () => {
test("internal imports from `cloudflare:*`", async ({ expect }) => {
const result = await getJsonResponse("/cloudflare-imports");

// Note: in some cases the DurableObject class name (erroneously) includes
Expand All @@ -54,7 +62,7 @@ describe("module resolution", async () => {
});
});

test("external imports from `cloudflare:*`", async () => {
test("external imports from `cloudflare:*`", async ({ expect }) => {
const result = await getJsonResponse("/external-cloudflare-imports");

// Note: in some cases the DurableObject class name (erroneously) includes
Expand All @@ -75,7 +83,7 @@ describe("module resolution", async () => {
* special meaning to us.
*/
describe("third party packages resolutions", () => {
test("react", async () => {
test("react", async ({ expect }) => {
const result = await getJsonResponse("/third-party/react");
expect(result).toEqual({
"(react) reactVersionsMatch": true,
Expand All @@ -84,23 +92,23 @@ describe("module resolution", async () => {
});
});

test("@remix-run/cloudflare", async () => {
test("@remix-run/cloudflare", async ({ expect }) => {
const result = await getJsonResponse("/third-party/remix");
expect(result).toEqual({
"(remix) remixRunCloudflareCookieName":
"my-remix-run-cloudflare-cookie",
});
});

test("discord-api-types/v10", async () => {
test("discord-api-types/v10", async ({ expect }) => {
const result = await getJsonResponse("/third-party/discord-api-types");
expect(result).toEqual({
"(discord-api-types/v10) RPCErrorCodes.InvalidUser": 4010,
"(discord-api-types/v10) Utils.isLinkButton({})": false,
});
});

test("slash-create", async () => {
test("slash-create", async ({ expect }) => {
const result = await getJsonResponse("/third-party/slash-create");
expect(result).toEqual({
"(slash-create/web) VERSION": "6.2.1",
Expand All @@ -111,14 +119,16 @@ describe("module resolution", async () => {
});

describe("user aliases", () => {
test("imports from an aliased package", async () => {
test("imports from an aliased package", async ({ expect }) => {
const result = await getTextResponse("/@alias/test");
expect(result).toBe("OK!");
});
});

describe("optimizeDeps.exclude", () => {
test("supports excluded packages importing from virtual modules", async () => {
test("supports excluded packages importing from virtual modules", async ({
expect,
}) => {
const result = await getTextResponse("/optimize-deps/exclude");
expect(result).toBe("Export from virtual module");
});
Expand Down
Loading