Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C3] Add getBindingsProxy support to qwik template #4927

Merged
merged 13 commits into from
Feb 7, 2024
8 changes: 8 additions & 0 deletions .changeset/ten-parents-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"create-cloudflare": patch
---

feature: Add `getBindingsProxy` support to `qwik` template

The `qwik` template now uses `getBindingsProxy` for handling requests for bound resources
in dev. This allows projects to use `vite` for dev instead of `wrangler pages dev` on built output.
1 change: 1 addition & 0 deletions packages/create-cloudflare/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
ignorePatterns: [
"dist",
"scripts",
"e2e-tests/fixtures/*",
// template files are ignored by the eslint-config-worker configuration
// we do however want the c3 files to be linted
"!**/templates/**/c3.ts",
Expand Down
61 changes: 35 additions & 26 deletions packages/create-cloudflare/e2e-tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import {
} from "vitest";
import { version } from "../package.json";
import { frameworkToTest } from "./frameworkToTest";
import { isQuarantineMode, keys, recreateLogFolder, runC3 } from "./helpers";
import {
createTestLogStream,
isQuarantineMode,
keys,
recreateLogFolder,
runC3,
} from "./helpers";
import type { WriteStream } from "fs";
import type { Suite } from "vitest";

// Note: skipIf(frameworkToTest) makes it so that all the basic C3 functionality
Expand All @@ -21,13 +28,15 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(
() => {
const tmpDirPath = realpathSync(mkdtempSync(join(tmpdir(), "c3-tests")));
const projectPath = join(tmpDirPath, "basic-tests");
let logStream: WriteStream;

beforeAll((ctx) => {
recreateLogFolder(ctx as Suite);
});

beforeEach(() => {
beforeEach((ctx) => {
rmSync(projectPath, { recursive: true, force: true });
logStream = createTestLogStream(ctx);
});

afterEach(() => {
Expand All @@ -36,36 +45,35 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(
}
});

test("--version", async (ctx) => {
const { output } = await runC3({ ctx, argv: ["--version"] });
test("--version", async () => {
const { output } = await runC3(["--version"], [], logStream);
expect(output).toEqual(version);
});

test("--version with positionals", async (ctx) => {
test("--version with positionals", async () => {
const argv = ["foo", "bar", "baz", "--version"];
const { output } = await runC3({ ctx, argv });
const { output } = await runC3(argv, [], logStream);
expect(output).toEqual(version);
});

test("--version with flags", async (ctx) => {
test("--version with flags", async () => {
const argv = [
"foo",
"--type",
"webFramework",
"--no-deploy",
"--version",
];
const { output } = await runC3({ ctx, argv });
const { output } = await runC3(argv, [], logStream);
expect(output).toEqual(version);
});

test.skipIf(process.platform === "win32")(
"Using arrow keys + enter",
async (ctx) => {
const { output } = await runC3({
ctx,
argv: [projectPath],
promptHandlers: [
async () => {
const { output } = await runC3(
[projectPath],
[
{
matcher: /What type of application do you want to create/,
input: [keys.enter],
Expand All @@ -83,7 +91,8 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(
input: [keys.left, keys.enter],
},
],
});
logStream
);

expect(projectPath).toExist();
expect(output).toContain(`type "Hello World" Worker`);
Expand All @@ -95,11 +104,10 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(

test.skipIf(process.platform === "win32")(
"Typing custom responses",
async (ctx) => {
const { output } = await runC3({
argv: [],
ctx,
promptHandlers: [
async () => {
const { output } = await runC3(
[],
[
{
matcher:
/In which directory do you want to create your application/,
Expand All @@ -122,7 +130,8 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(
input: ["n"],
},
],
});
logStream
);

expect(projectPath).toExist();
expect(output).toContain(`type Example router & proxy Worker`);
Expand All @@ -134,11 +143,10 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(

test.skipIf(process.platform === "win32")(
"Mixed args and interactive",
async (ctx) => {
const { output } = await runC3({
ctx,
argv: [projectPath, "--ts", "--no-deploy"],
promptHandlers: [
async () => {
const { output } = await runC3(
[projectPath, "--ts", "--no-deploy"],
[
{
matcher: /What type of application do you want to create/,
input: [keys.enter],
Expand All @@ -148,7 +156,8 @@ describe.skipIf(frameworkToTest || isQuarantineMode())(
input: ["n"],
},
],
});
logStream
);

expect(projectPath).toExist();
expect(output).toContain(`type "Hello World" Worker`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { RequestHandler } from "@builder.io/qwik-city";

export const onGet: RequestHandler = async ({ platform, json }) => {
if (!platform.env) {
json(500, "Platform object not defined");
return;
}

json(200, { value: platform.env["TEST"], version: 1 });
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[vars]
TEST = "C3_TEST"
Loading
Loading