refactor(create-sei): extract lib and expand test coverage#310
refactor(create-sei): extract lib and expand test coverage#310codebycarson wants to merge 1 commit intomainfrom
Conversation
|
725eceb to
e1efb08
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 11 changed files in this pull request and generated 10 comments.
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| test("extension project can install dependencies", async () => { | ||
| await ensureProject(precompilesProjectName, ["--extension", "precompiles"]); | ||
| const projectDir = path.join(e2eDir, precompilesProjectName); | ||
| await installDeps(projectDir); | ||
| }, 60_000); | ||
|
|
||
| test("extension project can build successfully", async () => { | ||
| await ensureProject(precompilesProjectName, ["--extension", "precompiles"]); | ||
| const projectDir = path.join(e2eDir, precompilesProjectName); | ||
| await installDeps(projectDir); | ||
|
|
||
| const proc = Bun.spawn(["bun", "run", "build"], { | ||
| cwd: projectDir, |
There was a problem hiding this comment.
The e2e suite also installs dependencies multiple times for the extension fixture (installDeps is called in both the “can install dependencies” and “can build successfully” tests). Consider reusing the same installed project (or checking for existing node_modules) to reduce runtime.
| if (options.name) { | ||
| if (!isValidDirectoryName(options.name)) { | ||
| console.log("Invalid package name. Please use a valid npm package name."); | ||
| valid = false; | ||
| } |
There was a problem hiding this comment.
The user-facing message says “Invalid package name. Please use a valid npm package name.”, but isValidDirectoryName currently rejects scoped npm package names (because '/' is illegal in a directory name). Either align the validation to npm package names (allow scopes) or update the message to reflect the actual constraint (directory name / package name without slashes).
| "build": "tsc -b --force && chmod +x dist/main.js && rsync -av --exclude-from=.rsyncignore ./templates/ ./dist/templates/ && rsync -av --exclude-from=.rsyncignore ./extensions/ ./dist/extensions/", | ||
| "dev": "tsc --watch", | ||
| "clean": "rm -rf dist", |
There was a problem hiding this comment.
The build script no longer clears dist before compiling (tsc -b --force won’t remove outputs for deleted/renamed source files). This can leave stale artifacts under dist/ and potentially ship outdated files. Consider restoring rm -rf dist at the start of build (or tsc -b --clean before build) to ensure a clean output.
| "scripts": { | ||
| "build": "rm -rf dist && tsc && chmod +x dist/main.js && rsync -av --exclude-from=.rsyncignore ./templates/ ./dist/templates/ && rsync -av --exclude-from=.rsyncignore ./extensions/ ./dist/extensions/", | ||
| "dev": "node --loader ts-node/esm src/main.ts", | ||
| "test": "jest" | ||
| "build": "tsc -b --force && chmod +x dist/main.js && rsync -av --exclude-from=.rsyncignore ./templates/ ./dist/templates/ && rsync -av --exclude-from=.rsyncignore ./extensions/ ./dist/extensions/", | ||
| "dev": "tsc --watch", | ||
| "clean": "rm -rf dist", | ||
| "test": "bun test" |
There was a problem hiding this comment.
build/dev scripts rely on tsc, but this package no longer declares typescript in its own devDependencies. If someone runs this package’s scripts outside the monorepo tooling context (or if hoisting changes), these scripts can fail. Consider adding typescript (and any other required tooling) back to devDependencies, or document/enforce that the workspace root provides them.
| test("generated project can install dependencies", async () => { | ||
| await ensureProject(baseProjectName); | ||
| const projectDir = path.join(e2eDir, baseProjectName); | ||
| await installDeps(projectDir); | ||
|
|
||
| // node_modules should exist | ||
| const nmExists = await pathExists(path.join(projectDir, "node_modules")); | ||
| expect(nmExists).toBe(true); | ||
| }, 60_000); | ||
|
|
||
| test("generated project can build successfully", async () => { | ||
| await ensureProject(baseProjectName); | ||
| const projectDir = path.join(e2eDir, baseProjectName); | ||
| await installDeps(projectDir); | ||
|
|
||
| const proc = Bun.spawn(["bun", "run", "build"], { | ||
| cwd: projectDir, |
There was a problem hiding this comment.
The e2e suite runs bun install repeatedly for the same fixture project across multiple tests (e.g., install + build tests both call installDeps). This can significantly slow CI and increase flakiness. Consider installing once per fixture (in beforeAll) or skipping install when node_modules already exists.
| const e2eTmpDirEnv = `${e2eTmpDir}${path.sep}`; | ||
| const e2eSpawnEnv = { | ||
| ...process.env, | ||
| TMPDIR: e2eTmpDirEnv, | ||
| BUN_TMPDIR: e2eTmpDirEnv, | ||
| }; | ||
|
|
||
| async function runCli( | ||
| args: string[], | ||
| cwd: string, | ||
| ): Promise<{ stdout: string; stderr: string; exitCode: number }> { | ||
| const proc = Bun.spawn(["node", cliPath, ...args], { | ||
| cwd, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| env: { ...process.env, NO_COLOR: "1" }, | ||
| }); |
There was a problem hiding this comment.
e2eSpawnEnv sets TMPDIR/BUN_TMPDIR, but runCli/ensureCliBuilt don’t use it (they build their own env object). If the goal is to keep all subprocess temp output under test-output-e2e/.tmp, consider using e2eSpawnEnv consistently (and layering NO_COLOR on top) so the CLI build/run doesn’t write temp files elsewhere.
| // Copy base template | ||
| const templateName = "next-template"; | ||
| const templatePath = path.join(baseDir, "templates", templateName); | ||
| const dst = path.join(process.cwd(), dAppName); | ||
| await fs.promises.cp(templatePath, dst, { recursive: true }); |
There was a problem hiding this comment.
runWizard writes into path.join(process.cwd(), dAppName), which makes tests patch process.cwd globally (see lib.test.ts). Consider adding an explicit destination base directory parameter (e.g., cwd/outputDir) so callers/tests don’t need to mutate global process state.
| test("creates project from base template with --name", async () => { | ||
| const originalCwd = process.cwd; | ||
| process.cwd = () => testDir; | ||
|
|
||
| try { | ||
| await runWizard({ name: "test-app" }, packageDir); | ||
| } finally { | ||
| process.cwd = originalCwd; | ||
| } |
There was a problem hiding this comment.
These tests temporarily overwrite process.cwd globally to control the output directory. This can become flaky if Bun runs tests concurrently (or if another test relies on process.cwd). Prefer passing an explicit destination directory into runWizard (or using a helper that changes cwd via process.chdir with try/finally) to avoid global mutation.
| const logs: string[] = []; | ||
| const originalLog = console.log; | ||
| console.log = (...args: unknown[]) => logs.push(args.join(" ")); | ||
|
|
||
| try { | ||
| await listExtensions(packageDir); | ||
| } finally { | ||
| console.log = originalLog; | ||
| } |
There was a problem hiding this comment.
console.log is monkey-patched to capture output. If tests execute in parallel, this can interleave logs across tests/files. Consider injecting a logger into listExtensions/runWizard (or using Bun’s spy utilities if available) to avoid mutating global console state.
| .option( | ||
| "--name <name>", | ||
| "Specify the name of your dApp. Name must be a valid package name.", | ||
| ) |
There was a problem hiding this comment.
The CLI help text says the app name must be a “valid package name”, but the validation rejects scoped npm names because they contain '/'. Consider updating the option description to describe the actual constraint (a directory name / package name without slashes), or adjust validation to truly accept all valid npm package names.
- extract wizard logic into reusable lib module\n- expand unit and e2e coverage for create-sei flows\n- make e2e setup self-contained and auto-build CLI when needed\n- fix test tsconfig inheritance and create-sei build determinism
e1efb08 to
bc34a1f
Compare
This pull request introduces comprehensive Bun-based testing to the
create-seipackage, replacing the previous Jest setup. It adds both unit and end-to-end (e2e) tests, updates the test and build scripts to use Bun, and improves.gitignorehandling for test outputs. The changes also introduce a dedicatedtsconfig.jsonfor tests and remove the legacy Jest-based test file.Testing infrastructure and test coverage:
src/__tests__/lib.test.ts, covering directory name validation, extension listing, project creation, extension overlays, and error handling.src/__tests__/e2e.test.tsto verify CLI project creation, extension support, dependency installation, and build success.tsconfig.jsonto ensure proper TypeScript settings for tests.main.test.ts.Tooling and configuration updates:
package.jsonto use Bun for testing (bun test), replaced Jest dependencies, and improved build/dev/clean scripts for Bun compatibility. Also added anexportsfield and public publish config..gitignoreto ignore Bun test output directories.