Skip to content

refactor(create-sei): extract lib and expand test coverage#310

Draft
codebycarson wants to merge 1 commit intomainfrom
pr/create-sei-refactor
Draft

refactor(create-sei): extract lib and expand test coverage#310
codebycarson wants to merge 1 commit intomainfrom
pr/create-sei-refactor

Conversation

@codebycarson
Copy link
Collaborator

@codebycarson codebycarson commented Mar 9, 2026

This pull request introduces comprehensive Bun-based testing to the create-sei package, 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 .gitignore handling for test outputs. The changes also introduce a dedicated tsconfig.json for tests and remove the legacy Jest-based test file.

Testing infrastructure and test coverage:

  • Added extensive Bun-based unit and integration tests in src/__tests__/lib.test.ts, covering directory name validation, extension listing, project creation, extension overlays, and error handling.
  • Added Bun-based end-to-end tests in src/__tests__/e2e.test.ts to verify CLI project creation, extension support, dependency installation, and build success.
  • Introduced a dedicated test tsconfig.json to ensure proper TypeScript settings for tests.
  • Removed the obsolete Jest-based test file main.test.ts.

Tooling and configuration updates:

  • Updated package.json to use Bun for testing (bun test), replaced Jest dependencies, and improved build/dev/clean scripts for Bun compatibility. Also added an exports field and public publish config.
  • Updated .gitignore to ignore Bun test output directories.

@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: bc34a1f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

This comment was marked as resolved.

@codebycarson codebycarson force-pushed the pr/create-sei-refactor branch 4 times, most recently from 725eceb to e1efb08 Compare March 9, 2026 21:19
@codebycarson codebycarson requested a review from Copilot March 9, 2026 21:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +211 to +223
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,
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +58
if (options.name) {
if (!isValidDirectoryName(options.name)) {
console.log("Invalid package name. Please use a valid npm package name.");
valid = false;
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +20
"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",
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 17 to +21
"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"
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +176
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,
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +27
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" },
});
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +120 to +124
// 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 });
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +160 to +168
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;
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +107
const logs: string[] = [];
const originalLog = console.log;
console.log = (...args: unknown[]) => logs.push(args.join(" "));

try {
await listExtensions(packageDir);
} finally {
console.log = originalLog;
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +13
.option(
"--name <name>",
"Specify the name of your dApp. Name must be a valid package name.",
)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
- 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
@codebycarson codebycarson force-pushed the pr/create-sei-refactor branch from e1efb08 to bc34a1f Compare March 9, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants