-
Notifications
You must be signed in to change notification settings - Fork 787
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 vite+react templates with tests #8013
base: main
Are you sure you want to change the base?
Changes from all commits
99b8f85
eaa7a66
33d595f
8ccc86a
f08cad2
975d5dc
d5359d8
2126dda
0563609
f1f27ab
04eb517
fb1da7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-cloudflare": patch | ||
--- | ||
|
||
add experimental React templates using the Cloudflare Vite plugin |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,8 @@ | |
"@types/react-transition-group>@types/react": "^18", | ||
"@cloudflare/elements>@types/react": "^18", | ||
"capnpc-ts>typescript": "4.2.4", | ||
"@types/node": "$@types/node" | ||
"@types/node": "$@types/node", | ||
"vitest>vite": "^5.0.0" | ||
}, | ||
"patchedDependencies": { | ||
"@cloudflare/[email protected]": "patches/@[email protected]", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,26 @@ function getFrameworkTests(opts: { | |
}, | ||
flags: ["--style", "sass"], | ||
}, | ||
react: { | ||
promptHandlers: [ | ||
{ | ||
matcher: /Select a variant:/, | ||
input: [keys.enter], | ||
}, | ||
], | ||
unsupportedOSs: ["win32"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current |
||
unsupportedPms: ["yarn"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create-vite basically tries to parse the Because we are running create-cloudflare via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think there's any way to fix this? |
||
testCommitMessage: true, | ||
verifyDeploy: { | ||
route: "/", | ||
expectedText: "Vite + React", | ||
}, | ||
verifyPreview: { | ||
route: "/", | ||
previewArgs: ["--host=127.0.0.1"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary because by default |
||
expectedText: "Vite + React", | ||
}, | ||
}, | ||
gatsby: { | ||
unsupportedPms: ["bun", "pnpm"], | ||
promptHandlers: [ | ||
|
@@ -641,6 +661,10 @@ describe.concurrent( | |
|
||
test({ experimental }).runIf(shouldRunTest(frameworkId, testConfig))( | ||
frameworkId, | ||
{ | ||
retry: TEST_RETRIES, | ||
timeout: testConfig.timeout || TEST_TIMEOUT, | ||
}, | ||
async ({ logStream, project }) => { | ||
if (!testConfig.verifyDeploy) { | ||
expect( | ||
|
@@ -715,10 +739,6 @@ describe.concurrent( | |
} | ||
} | ||
}, | ||
{ | ||
retry: TEST_RETRIES, | ||
timeout: testConfig.timeout || TEST_TIMEOUT, | ||
}, | ||
); | ||
}); | ||
}, | ||
|
@@ -742,6 +762,7 @@ const runCli = async ( | |
NO_DEPLOY ? "--no-deploy" : "--deploy", | ||
"--no-open", | ||
"--no-git", | ||
"--no-auto-update", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably not really needed but seemed like a safe thing to do to ensure that we are actually running the instance of C3 that we expected. |
||
]; | ||
|
||
args.push(...argv); | ||
|
@@ -765,28 +786,29 @@ const runCli = async ( | |
}; | ||
|
||
/** | ||
* Either update or create a wrangler.toml to include a `TEST` var. | ||
* Either update or create a wrangler configuration file to include a `TEST` var. | ||
* | ||
* This is rather than having a wrangler.toml in the e2e test's fixture folder, | ||
* This is rather than having a wrangler configuration file in the e2e test's fixture folder, | ||
* which overwrites any that comes from the framework's template. | ||
*/ | ||
const addTestVarsToWranglerToml = async (projectPath: string) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not for this PR, but the name of this variable and all the references to |
||
const wranglerTomlPath = join(projectPath, "wrangler.toml"); | ||
const wranglerJsoncPath = join(projectPath, "wrangler.jsonc"); | ||
|
||
if (existsSync(wranglerTomlPath)) { | ||
const wranglerToml = readToml(wranglerTomlPath); | ||
// Add a TEST var to the wrangler.toml | ||
wranglerToml.vars ??= {}; | ||
(wranglerToml.vars as JsonMap).TEST = "C3_TEST"; | ||
|
||
writeToml(wranglerTomlPath, wranglerToml); | ||
} else if (existsSync(wranglerJsoncPath)) { | ||
const wranglerJson = readJSON(wranglerJsoncPath); | ||
// Add a TEST var to the wrangler.toml | ||
wranglerJson.vars ??= {}; | ||
wranglerJson.vars.TEST = "C3_TEST"; | ||
const wranglerJsonc = readJSON(wranglerJsoncPath) as { | ||
vars: Record<string, string>; | ||
}; | ||
wranglerJsonc.vars ??= {}; | ||
wranglerJsonc.vars.TEST = "C3_TEST"; | ||
|
||
writeJSON(wranglerJsoncPath, wranglerJson); | ||
writeJSON(wranglerJsoncPath, wranglerJsonc); | ||
} | ||
}; | ||
|
||
|
@@ -838,6 +860,7 @@ const verifyPreviewScript = async ( | |
...(pm === "npm" ? ["--"] : []), | ||
"--port", | ||
`${TEST_PORT}`, | ||
...(verifyPreview.previewArgs ?? []), | ||
], | ||
{ | ||
cwd: projectPath, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ export const detectPackageManager = () => { | |
if (process.env.TEST_PM && process.env.TEST_PM_VERSION) { | ||
name = process.env.TEST_PM as PmName; | ||
version = process.env.TEST_PM_VERSION; | ||
process.env.npm_config_user_agent = name; | ||
process.env.npm_config_user_agent = `${name}/${version}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was an attempt to get |
||
} | ||
|
||
switch (name) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this
>
magic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is standard pnpm magic, which means override only
vite
version but only those that are dependencies ofvitest
.