chore(cli): add smoke tests (#489)

This commit is contained in:
Aman Varshney
2025-08-11 02:56:25 +05:30
committed by GitHub
parent d6cf5c9d26
commit 198d6e968b
9 changed files with 2831 additions and 51 deletions

3
apps/cli/.gitignore vendored
View File

@@ -1,2 +1,3 @@
/node_modules
/dist
/dist
.smoke

View File

@@ -49,7 +49,8 @@
"dev": "tsdown --watch",
"check-types": "tsc --noEmit",
"check": "biome check --write .",
"test": "vitest run",
"test": "bun run build && vitest run",
"test:with-build": "bun run build && WITH_BUILD=1 vitest run",
"prepublishOnly": "npm run build"
},
"dependencies": {
@@ -70,6 +71,7 @@
"@types/fs-extra": "^11.0.4",
"@types/node": "^24.2.0",
"tsdown": "^0.13.3",
"typescript": "^5.9.2"
"typescript": "^5.9.2",
"vitest": "^3.2.4"
}
}

View File

@@ -236,7 +236,7 @@ async function getDatabaseInstructions(
);
instructions.push(
`${pc.cyan("4.")} Generate migrations: ${pc.white(
"cd apps/server && bun db:generate",
`cd apps/server && ${packageManager} db:generate`,
)}`,
);
instructions.push(

View File

@@ -11,12 +11,14 @@ async function processAndCopyFiles(
destDir: string,
context: ProjectConfig,
overwrite = true,
ignorePatterns?: string[],
) {
const sourceFiles = await globby(sourcePattern, {
cwd: baseSourceDir,
dot: true,
onlyFiles: true,
absolute: false,
ignore: ignorePatterns,
});
for (const relativeSrcPath of sourceFiles) {
@@ -26,28 +28,30 @@ async function processAndCopyFiles(
if (relativeSrcPath.endsWith(".hbs")) {
relativeDestPath = relativeSrcPath.slice(0, -4);
}
const basename = path.basename(relativeSrcPath);
const basename = path.basename(relativeDestPath);
if (basename === "_gitignore") {
relativeDestPath = path.join(path.dirname(relativeSrcPath), ".gitignore");
relativeDestPath = path.join(
path.dirname(relativeDestPath),
".gitignore",
);
} else if (basename === "_npmrc") {
relativeDestPath = path.join(path.dirname(relativeSrcPath), ".npmrc");
relativeDestPath = path.join(path.dirname(relativeDestPath), ".npmrc");
}
const destPath = path.join(destDir, relativeDestPath);
try {
await fs.ensureDir(path.dirname(destPath));
await fs.ensureDir(path.dirname(destPath));
if (!overwrite && (await fs.pathExists(destPath))) {
continue;
}
if (!overwrite && (await fs.pathExists(destPath))) {
continue;
}
if (srcPath.endsWith(".hbs")) {
await processTemplate(srcPath, destPath, context);
} else {
await fs.copy(srcPath, destPath, { overwrite: true });
}
} catch (_error) {}
if (srcPath.endsWith(".hbs")) {
await processTemplate(srcPath, destPath, context);
} else {
await fs.copy(srcPath, destPath, { overwrite: true });
}
}
}
@@ -655,26 +659,14 @@ export async function setupExamplesTemplate(
ignorePatterns.push("next/**");
}
const generalServerFiles = await globby(["**/*.ts", "**/*.hbs"], {
cwd: exampleServerSrc,
onlyFiles: true,
deep: 1,
ignore: ignorePatterns,
});
for (const file of generalServerFiles) {
const srcPath = path.join(exampleServerSrc, file);
const destPath = path.join(serverAppDir, file.replace(".hbs", ""));
try {
if (srcPath.endsWith(".hbs")) {
await processTemplate(srcPath, destPath, context);
} else {
if (!(await fs.pathExists(destPath))) {
await fs.copy(srcPath, destPath, { overwrite: false });
}
}
} catch (_error) {}
}
await processAndCopyFiles(
["**/*.ts", "**/*.hbs"],
exampleServerSrc,
serverAppDir,
context,
false,
ignorePatterns,
);
}
if (webAppDirExists) {
@@ -791,9 +783,13 @@ export async function handleExtras(projectDir: string, context: ProjectConfig) {
if (context.packageManager === "bun") {
const bunfigSrc = path.join(extrasDir, "bunfig.toml.hbs");
const bunfigDest = path.join(projectDir, "bunfig.toml");
if (await fs.pathExists(bunfigSrc)) {
await processTemplate(bunfigSrc, bunfigDest, context);
await processAndCopyFiles(
"bunfig.toml.hbs",
extrasDir,
projectDir,
context,
);
}
}
@@ -802,9 +798,8 @@ export async function handleExtras(projectDir: string, context: ProjectConfig) {
(hasNative || context.frontend.includes("nuxt"))
) {
const npmrcTemplateSrc = path.join(extrasDir, "_npmrc.hbs");
const npmrcDest = path.join(projectDir, ".npmrc");
if (await fs.pathExists(npmrcTemplateSrc)) {
await processTemplate(npmrcTemplateSrc, npmrcDest, context);
await processAndCopyFiles("_npmrc.hbs", extrasDir, projectDir, context);
}
}

View File

@@ -1,5 +1,5 @@
import { cancel } from "@clack/prompts";
import { consola } from "consola";
import consola from "consola";
import pc from "picocolors";
export function exitWithError(message: string): never {

File diff suppressed because it is too large Load Diff

View File

@@ -11,5 +11,5 @@
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "**/*.test.ts", "**/*.spec.ts"]
}

15
apps/cli/vitest.config.ts Normal file
View File

@@ -0,0 +1,15 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
watch: false,
testTimeout: 180_000,
hookTimeout: 120_000,
reporters: "default",
poolOptions: {
threads: {
singleThread: true,
},
},
},
});