-
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
Enhance Frontend CI with Testing #81
Conversation
- Extracted build, dev, and preview commands into separate modules under `src/cli/commands`. - Simplified `bin/cli.ts` to import and use the main `program` from `src/cli/index.ts`. - Added `runPreprocess` utility function in `src/cli/runPreprocess.ts` for SQL file processing. - Enhanced code organization for improved readability and maintainability.
- Updated `package.json` to include a `test` script using Vitest. - Modified `vite.config.ts` to configure Vitest for testing. - Documented the testing setup in `README.md`.
- Introduced a `frontend-ci` job in GitHub Actions to run `pnpm test:turbo`. - Updated `frontend/package.json` to add a `test:turbo` script. - Modified `turbo.json` to include the `test` task with no cached outputs.
a26abfd
to
8c43185
Compare
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!
I think adopting Vitest is a great idea!
@@ -0,0 +1,15 @@ | |||
import { createServer } from 'vite' | |||
import { runPreprocess } from '../runPreprocess.js' |
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.
[nits]
Could we write it like this to make it more concise?
import { runPreprocess } from '../runPreprocess.js' | |
import { runPreprocess } from '../runPreprocess' |
import { buildCommand } from './buildCommand.js' | ||
import { devCommand } from './devCommand.js' | ||
import { previewCommand } from './previewCommand.js' | ||
export { buildCommand, devCommand, previewCommand } |
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.
[nits]
Could we write it like this to make it more concise?
import { buildCommand } from './buildCommand.js' | |
import { devCommand } from './devCommand.js' | |
import { previewCommand } from './previewCommand.js' | |
export { buildCommand, devCommand, previewCommand } | |
export { buildCommand } from './buildCommand' | |
export { devCommand } from './devCommand' | |
export { previewCommand } from './previewCommand' |
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 actually been a bit of a headache for me since yesterday! At the moment, removing the .js
extension causes the CLI to not work correctly. 😭 😭
error
[cli]$ rm -rf dist dist-cli/ node_modules/.tmp
[cli]$ pnpm run build:cli
> @liam/[email protected] build:cli /Users/hoshino/.local/share/go/src/github.com/liam-hq/liam/frontend/packages/cli
> tsc -p tsconfig.node.json
[cli]$
[cli]$ pnpm link --global
[cli]$ which liam
/Users/hoshino/.local/share/pnpm/liam
[cli]$ liam erd help
node:internal/modules/esm/resolve:265
throw new ERR_MODULE_NOT_FOUND(
^
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/hoshino/.local/share/go/src/github.com/liam-hq/liam/frontend/packages/cli/dist-cli/src/cli/commands/buildCommand' imported from /Users/hoshino/.local/share/go/src/github.com/liam-hq/liam/frontend/packages/cli/dist-cli/src/cli/commands/index.js
at finalizeResolution (node:internal/modules/esm/resolve:265:11)
at moduleResolve (node:internal/modules/esm/resolve:933:10)
at defaultResolve (node:internal/modules/esm/resolve:1157:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
at link (node:internal/modules/esm/module_job:86:36) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///Users/hoshino/.local/share/go/src/github.com/liam-hq/liam/frontend/packages/cli/dist-cli/src/cli/commands/buildCommand'
}
Node.js v20.12.0
So, I can only confirm that it functions properly in its current state, with the .js
extension included. It’s not ideal, but it's a workaround that keeps things running for now.
To explain a bit further, if I change tsconfig.node.json
from "module": "ESNext"
to "CommonJS"
and remove "type": "module"
from package.json
, the CLI would indeed work without the .js
extension. However, doing so triggers a warning: The CJS build of Vite's Node API is deprecated. See https://vite.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
I’m hoping to get some help with this issue from someone else in the future. Also, since this is a rather fragile part of the setup, I’m considering adding a smoke test to ensure the CLI continues to work properly.
Hope that gives some clarity, and thank you for the suggestion!
Summary
This pull request enhances the frontend CI setup by adding automated testing, improves the CLI structure, and updates package dependencies for better functionality. It ensures the
liam
CLI commands are organized and streamlined, withvitest
introduced for testing.Related Issue
N/A
Changes
frontend-ci
job in the GitHub Actions workflow for running tests only when there are changes detected by thesetup-job
. This job includes steps to set up the environment and executepnpm test:turbo
.cli.ts
to import theprogram
from a newsrc/index.js
, removing redundant code and centralizing CLI logic.buildCommand
,devCommand
, andpreviewCommand
modules to encapsulate their respective logic, improving readability and maintainability.vitest
as the testing framework and added test files forrunPreprocess
and the CLI commands to validate functionality.package.json
to includevitest
and added atest
script for running the tests. Modifiedturbo.json
to incorporate thetest
task configuration.Testing
Same as #79 ✔️