Prince
CDCloudflare Developers
•Created by Prince on 5/20/2024 in #vitest-integration-beta
I ran into this issue too - `Error:
src/index.test.ts
import {
createExecutionContext,
env,
waitOnExecutionContext,
} from "cloudflare:test";
import { describe, expect, it } from "vitest";
import worker from ".";
describe("Worker", () => {
it("should return 200 response", async () => {
const url = new URL("/test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});
it("should return 200 response, when inngest is imported", async () => {
const url = new URL("/inngest-test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});
});
import {
createExecutionContext,
env,
waitOnExecutionContext,
} from "cloudflare:test";
import { describe, expect, it } from "vitest";
import worker from ".";
describe("Worker", () => {
it("should return 200 response", async () => {
const url = new URL("/test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});
it("should return 200 response, when inngest is imported", async () => {
const url = new URL("/inngest-test", "http://localhost:8787");
const request = new Request(url, {
method: "GET",
headers: { "Content-Type": "application/json" },
});
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
await waitOnExecutionContext(ctx);
expect(response.status).toBe(200);
});
});
4 replies
CDCloudflare Developers
•Created by Prince on 5/20/2024 in #vitest-integration-beta
I ran into this issue too - `Error:
src/index.ts
import { Hono } from "hono";
type Bindings = {};
const app = new Hono<{ Bindings: Bindings }>();
app.get("/test", (c) => {
return c.json({ success: true });
});
app.get("/inngest-test", async (c) => {
// The same error occurs when imported at the top of the file
// But, this way (ie, with a dynamic import), I can show `/test` works fine
const { Inngest } = await import("inngest");
const inngest = new Inngest({ id: "foo" });
return c.json({ success: true, inngestClientId: inngest.id });
});
export default app;
import { Hono } from "hono";
type Bindings = {};
const app = new Hono<{ Bindings: Bindings }>();
app.get("/test", (c) => {
return c.json({ success: true });
});
app.get("/inngest-test", async (c) => {
// The same error occurs when imported at the top of the file
// But, this way (ie, with a dynamic import), I can show `/test` works fine
const { Inngest } = await import("inngest");
const inngest = new Inngest({ id: "foo" });
return c.json({ success: true, inngestClientId: inngest.id });
});
export default app;
4 replies
CDCloudflare Developers
•Created by Prince on 5/20/2024 in #vitest-integration-beta
I ran into this issue too - `Error:
vitest.config.ts
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersConfig({
test: {
name: "example-worker",
server: {
deps: {
inline: [
// /@hono\/zod-validtor/,
// /@hono\/zod-openapi/,
// /zod-to-openapi/,
// Without this, there is an error
// TypeError: Cannot read properties of undefined (reading 'bold')
// in `monorepo/node_modules/.pnpm/[email protected][email protected]/node_modules/inngest/index.js?mf_vitest_no_cjs_esm_shim:6:17`
/inngest/,
],
},
},
poolOptions: {
workers: {
main: "src/index.ts",
wrangler: { configPath: "./wrangler.json" },
miniflare: {
compatibilityFlags: ["nodejs_compat"],
},
},
},
},
});
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersConfig({
test: {
name: "example-worker",
server: {
deps: {
inline: [
// /@hono\/zod-validtor/,
// /@hono\/zod-openapi/,
// /zod-to-openapi/,
// Without this, there is an error
// TypeError: Cannot read properties of undefined (reading 'bold')
// in `monorepo/node_modules/.pnpm/[email protected][email protected]/node_modules/inngest/index.js?mf_vitest_no_cjs_esm_shim:6:17`
/inngest/,
],
},
},
poolOptions: {
workers: {
main: "src/index.ts",
wrangler: { configPath: "./wrangler.json" },
miniflare: {
compatibilityFlags: ["nodejs_compat"],
},
},
},
},
});
4 replies