Skip to content

feat: add sample test file generation to init command #411

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

Merged
merged 14 commits into from
Mar 30, 2025

Conversation

rmarescu
Copy link
Member

@rmarescu rmarescu commented Mar 28, 2025

Enhanced CLI initialization with interactive prompts for sample test generation, config customization, API key setup, and login credentials to streamline user onboarding with guided setup flow.

Ref #375 (comment)

Helper demo

The test file was not properly formatted due to some issues with detecting the ESLint config (no padding lines between statements)

CleanShot.2025-03-29.at.21.12.11.mp4

Iffy demo

Shortest is already installed on the project

CleanShot.2025-03-29.at.22.06.58.mp4

Copy link

vercel bot commented Mar 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
shortest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 30, 2025 5:17am

@rmarescu rmarescu changed the title f feat: init with prompts Mar 28, 2025
@rmarescu rmarescu added this to the v0.4.9 milestone Mar 28, 2025
rmarescu added a commit that referenced this pull request Mar 28, 2025
Adds a [task list](https://listr2.kilic.dev/) to manage the installation
steps.

In preparation for creating a more [interactive setup with
prompts](#411).


https://github.com/user-attachments/assets/50dbeeaa-22b7-4ebd-b4fd-a87cd8c3d98d
Base automatically changed from rmarescu/generate to main March 28, 2025 21:54
@rmarescu rmarescu marked this pull request as ready for review March 30, 2025 05:49

const analyzer = new AppAnalyzer(cwd, framework);
const analyzer = new AppAnalyzer(supportedFrameworkInfo);
Copy link
Member Author

Choose a reason for hiding this comment

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

Introduced some changes to support Next.js apps that are not using the repo's root dir.

await writeFile(configPath, exampleConfig, "utf8");
task.title = `${CONFIG_FILENAME} created.`;
},
title: "[🧪 Experimental Next.js] Confirm sample test file generation",
Copy link
Member Author

Choose a reason for hiding this comment

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

This introduces the new MVP setup to the init command.

We need to ask if the user wants to generate the sample file before the installation, so that a different value for testPattern can be set (shortest folder). If we automate test files generation, I think it would be simpler to just have all the files in a dedicated folder, or conflict with a more generic test folder.

),
},
{
title: "Adding Shortest login credentials for testing",
Copy link
Member Author

Choose a reason for hiding this comment

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

This allows the user to store credentials in ENVs, to be used by tests.

} else {
task.title = `ANTHROPIC_API_KEY already exists, skipped`;
const testPattern = ctx.generateSampleTestFile
? "shortest/**/*.test.ts"
Copy link
Member Author

Choose a reason for hiding this comment

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

This ensures the new test file can be executed without any manual changes to the config file. Went with this approach for backward compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

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

Quite complex logic, it could use some test coverage (can be added at a later time).

} else {
console.log(pc.green("\nInitialization complete! Next steps:"));
console.log("1. Create your first test file: example.test.ts");
console.log("2. Run tests with: npx/pnpm shortest example.test.ts");
Copy link
Member Author

Choose a reason for hiding this comment

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

Technically, we could detect the package manager, pass that info around, and craft the exact command that needs to be executed.

},
});

log.setOutputStream(streamAdapter);
Copy link
Member Author

Choose a reason for hiding this comment

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

Passing the output of our logger to the task's stdout so we can display the logs below the interactive list.

plugins: ["typescript"],
});

if (configOptions.testPattern) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Replacing the default value for testPattern. This setup introduces a pattern where the config file could be updated via CLI prompts in the future.

@@ -85,3 +103,22 @@ export const detectFramework = async (options: { force?: boolean } = {}) => {
throw new ShortestError("Failed to save project information");
}
};

const detectNextJsDirPathFromConfig = async (): Promise<string | undefined> => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Best-effort in detecting the folder of a Next.js app. It now uses next.config.* files for reference.

const nextNamedDir = nextDirConfigPaths.find((dirPath) =>
/next/i.test(dirPath),
);
return path.join(process.cwd(), nextNamedDir || nextDirConfigPaths[0]);
Copy link
Member Author

Choose a reason for hiding this comment

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

If multiple Next.js apps are found within the same repo, prioritize the one that has next in the folder name (e.g. for Helper, will pick apps/next over apps/docs)

@rmarescu rmarescu changed the title feat: init with prompts feat: add sample test file generation to init command Mar 30, 2025
@rmarescu rmarescu merged commit 051b3f7 into main Mar 30, 2025
6 checks passed
@rmarescu rmarescu deleted the rmarescu/init-prompts branch March 30, 2025 05:50
@github-project-automation github-project-automation bot moved this to Done in Shortest Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant