Skip to content

Commit

Permalink
Fixing project cleanup and tweaking test concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
jculvey committed Jul 27, 2023
1 parent 4a9bfd9 commit 1845864
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
47 changes: 32 additions & 15 deletions packages/create-cloudflare/e2e-tests/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type FrameworkTestConfig = RunnerConfig & {

describe(`E2E: Web frameworks`, () => {
const tmpDirPath = realpathSync(mkdtempSync(join(tmpdir(), "c3-tests")));
const baseProjectName = `c3-e2e-${crypto.randomBytes(4).toString("hex")}`;
const baseProjectName = `c3-e2e-${crypto.randomBytes(3).toString("hex")}`;

const getProjectName = (framework: string) =>
`${baseProjectName}-${framework}`;
Expand All @@ -39,13 +39,29 @@ describe(`E2E: Web frameworks`, () => {
afterEach((ctx) => {
const framework = ctx.meta.name;
const projectPath = getProjectPath(framework);
const projectName = getProjectPath(framework);
const projectName = getProjectName(framework);

if (existsSync(projectPath)) {
rmSync(projectPath, { recursive: true });
}

spawn("npx", ["wrangler", "pages", "project", "delete", "-y", projectName]);
try {
const { output } = spawn.sync("npx", [
"wrangler",
"pages",
"project",
"delete",
"-y",
projectName,
]);

if (!output.toString().includes(`Successfully deleted ${projectName}`)) {
console.error(output.toString());
}
} catch (error) {
console.error(`Failed to cleanup project: ${projectName}`);
console.error(error);
}
});

const runCli = async (
Expand Down Expand Up @@ -124,13 +140,26 @@ describe(`E2E: Web frameworks`, () => {
).toContain(expectResponseToContain);
};

// These are ordered based on speed and reliability for ease of debugging
const frameworkTests: Record<string, FrameworkTestConfig> = {
astro: {
expectResponseToContain: "Hello, Astronaut!",
},
hono: {
expectResponseToContain: "/api/hello",
},
qwik: {
expectResponseToContain: "Welcome to Qwik",
promptHandlers: [
{
matcher: /Yes looks good, finish update/,
input: [keys.enter],
},
],
},
remix: {
expectResponseToContain: "Welcome to Remix",
},
next: {
expectResponseToContain: "Create Next App",
promptHandlers: [
Expand All @@ -148,21 +177,9 @@ describe(`E2E: Web frameworks`, () => {
},
},
},
qwik: {
expectResponseToContain: "Welcome to Qwik",
promptHandlers: [
{
matcher: /Yes looks good, finish update/,
input: [keys.enter],
},
],
},
react: {
expectResponseToContain: "React App",
},
remix: {
expectResponseToContain: "Welcome to Remix",
},
solid: {
expectResponseToContain: "Hello world",
promptHandlers: [
Expand Down
10 changes: 7 additions & 3 deletions packages/create-cloudflare/scripts/cleanupPagesProject.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const listProjectsToDelete = async () => {
const { stdout } = await npx("wrangler pages project list");

for (const line of stdout.split("\n")) {
const c3ProjectRe = /(c3-e2e-\w*)\s+/;
const c3ProjectRe = /(c3-e2e-[\w-]*)\s?/;
const match = line.match(c3ProjectRe);

if (match) {
Expand All @@ -34,8 +34,12 @@ const listProjectsToDelete = async () => {

const deleteProjects = async (projects) => {
for (const project of projects) {
console.log(`Deleting project: ${project}`);
await npx(`wrangler pages project delete -y ${project}`);
try {
console.log(`Deleting project: ${project}`);
await npx(`wrangler pages project delete -y ${project}`);
} catch (error) {
console.error(error);
}
}
};

Expand Down
1 change: 1 addition & 0 deletions packages/create-cloudflare/vitest-e2e.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default defineConfig({
cache: false,
root: ".",
testTimeout: 1000 * 60 * 3, // 3 min for lengthy installs
maxConcurrency: 4,
setupFiles: ["e2e-tests/setup.ts"],
},
});

0 comments on commit 1845864

Please sign in to comment.