-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improve start-frontend CLI test #1257
Conversation
🦋 Changeset detectedLatest commit: 3b0ba4f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
expect(results).toContain(`start-frontend`); | ||
expect(results).toContain(`Welcome!`); | ||
expect(results).toContain( | ||
`? Where Would You like to Create Your Application?` | ||
); | ||
expect(results).toContain(`? Select a JavsScript library for UI`); | ||
expect(results).toContain(`? Select an API Solution`); | ||
expect(results).toContain(`? Select module do you want to use`); | ||
expect(results).toContain(`? Add Testing codes for Catching bugs early?`); | ||
expect(results).toContain(`? Add Vitest for Unit Testing?`); | ||
expect(results).toContain(`? Add Storybook for Visual Testing?`); | ||
expect(results).toContain(`? Add Playwright for End-To-End Testing?`); | ||
expect(results).toContain(`? Add ESLint for Code Linting?`); | ||
expect(results).toContain(`? Add Prettier for Code Formatting?`); | ||
expect(results).toContain(`Success! Created a new app at "my-test".`); |
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.
Since the wording of the CLI prompts is likely to change frequnetly, I thought it would be better to test the contests of the files generated by running the CLI rather than the working itself.
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.
I think the file contents may change a bit after this, since we're reorganizing the templates and how the projects are generated 😅
We'll just have to keep this in mind and modify the tests in order to accommodate any changes.
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.
That's right. Even if we change the tests to check the file structure from the messages, the file structure might change frequently for a while, so we'll need to update the tests each time. 😶🌫️
In the future, it might be more flexible to focus on whether the generated files can be built, rather than their structure. 🤔
const exe = util.promisify(child.execFile); | ||
const TEST_DIR = | ||
// eslint-disable-next-line turbo/no-undeclared-env-vars | ||
process.env.RUNNER_TEMP || execSync("mktemp -d -t my-test").toString("utf-8"); |
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.
The test folder is set to be created within a suitable folder in the OS's temp directory. Since mktemp
does not work well with Github Actions, I configured it to use the temp folder already specified in the environment variables.
expect(stdout.trim()).toBe(process.env.npm_package_version); | ||
const { stdout } = await exe("node", [START_FRONTEND, "--version"]); | ||
expect(stdout.trim()).toMatch(/^(\d+\.)?(\d+\.)?(\*|\d+)$/); |
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.
It doesn't need to be very strict; using a semantic versioning is sufficient.
const result = execSync( | ||
`npx tree-cli -a -l 5 --base ${TEST_DIR}` | ||
).toString("utf-8"); |
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.
I used tree-cli because it provides a visually clear folder structure. Do you have any other recommendations for a shell tree tool that works on macOS, Linux, and (if possible) Windows? 🤔
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.
I've only ever used tree-cli myself. 🤔
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.
Thank you for working the tests! I think it's a good idea to test out the generated project; it definitely looks more meaningful!
I have a couple of questions regarding your implementation, though, so could you please take a look?
expect(results).toContain(`start-frontend`); | ||
expect(results).toContain(`Welcome!`); | ||
expect(results).toContain( | ||
`? Where Would You like to Create Your Application?` | ||
); | ||
expect(results).toContain(`? Select a JavsScript library for UI`); | ||
expect(results).toContain(`? Select an API Solution`); | ||
expect(results).toContain(`? Select module do you want to use`); | ||
expect(results).toContain(`? Add Testing codes for Catching bugs early?`); | ||
expect(results).toContain(`? Add Vitest for Unit Testing?`); | ||
expect(results).toContain(`? Add Storybook for Visual Testing?`); | ||
expect(results).toContain(`? Add Playwright for End-To-End Testing?`); | ||
expect(results).toContain(`? Add ESLint for Code Linting?`); | ||
expect(results).toContain(`? Add Prettier for Code Formatting?`); | ||
expect(results).toContain(`Success! Created a new app at "my-test".`); |
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.
I think the file contents may change a bit after this, since we're reorganizing the templates and how the projects are generated 😅
We'll just have to keep this in mind and modify the tests in order to accommodate any changes.
const result = execSync( | ||
`npx tree-cli -a -l 5 --base ${TEST_DIR}` | ||
).toString("utf-8"); |
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.
I've only ever used tree-cli myself. 🤔
|
||
const testDir = "my-test" as const; | ||
let TEST_DIR; |
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.
If it's not a constant, I think testDir
would be more appropriate.
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.
Done in 2661d0a
import concat from "concat-stream"; | ||
import { spawn } from "node:child_process"; | ||
import { execFile, exec, execSync } from "node:child_process"; | ||
import fse from "fs-extra"; |
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.
Minor suggestion, but what do you think about sorting the imports? (Opt + Shift + O
on Mac VS Code)
It would be nice if there's a way to include it in the pre-commit script.
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.
Opt + Shift + O on Mac VS Code
Personally, I've been using Helix as my editor recently 🙏🏼
But for import order, I think your suggestion to handle it with a precommit hook could work. 👍🏼
It would be nice if there's a way to include it in the pre-commit script.
Yeah, it would be nice if we could ensure this with a formatter, like
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.
LGTM!
Pull Request Checklist
console.log()
)npm run test:cli
)npm run test:modules
)npm run e2e
)Description
In the existing tests, there was no check to verify if the output generated by running the CLI was correct, so I added it.
Context
Resolves #1255
Before
ml-frontend/packages/start-frontend/__tests__/cli.test.ts
Lines 72 to 98 in e589781
After
ml-frontend/packages/start-frontend/__tests__/cli.test.ts
Lines 108 to 174 in 6ebf40f