-
Notifications
You must be signed in to change notification settings - Fork 306
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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
f8bd364
to
31f03fb
Compare
|
||
const analyzer = new AppAnalyzer(cwd, framework); | ||
const analyzer = new AppAnalyzer(supportedFrameworkInfo); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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> => { |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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