Skip to content
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

Merged
merged 5 commits into from
Nov 13, 2024
Merged

Conversation

hoshinotsuyoshi
Copy link
Member

@hoshinotsuyoshi hoshinotsuyoshi commented Nov 11, 2024

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, with vitest introduced for testing.

Related Issue

N/A

Changes

  1. Workflow Updates: Added a new frontend-ci job in the GitHub Actions workflow for running tests only when there are changes detected by the setup-job. This job includes steps to set up the environment and execute pnpm test:turbo.
  2. CLI Refactor: Simplified cli.ts to import the program from a new src/index.js, removing redundant code and centralizing CLI logic.
  3. Command Implementations: Added buildCommand, devCommand, and previewCommand modules to encapsulate their respective logic, improving readability and maintainability.
  4. Testing Setup: Introduced vitest as the testing framework and added test files for runPreprocess and the CLI commands to validate functionality.
  5. Package Updates: Updated package.json to include vitest and added a test script for running the tests. Modified turbo.json to incorporate the test task configuration.
  • 86a3fd3 : Refactor CLI to modularize commands
  • a2fa9c5 : $ pnpm add -D vitest @types/node
  • 805f42c : Add testing setup with Vitest and initial tests for CLI
  • 8c43185 : Add CI workflow for frontend testing with Turbo

Testing

Same as #79 ✔️

@hoshinotsuyoshi hoshinotsuyoshi self-assigned this Nov 11, 2024
- 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.
@hoshinotsuyoshi hoshinotsuyoshi force-pushed the setup-erd-generator-cli-test branch from a26abfd to 8c43185 Compare November 11, 2024 11:37
@hoshinotsuyoshi hoshinotsuyoshi changed the title draft: Setup erd generator cli test draft: Enhance Frontend CI with Testing Nov 11, 2024
@hoshinotsuyoshi hoshinotsuyoshi marked this pull request as ready for review November 11, 2024 11:45
@hoshinotsuyoshi hoshinotsuyoshi requested a review from a team as a code owner November 11, 2024 11:45
@hoshinotsuyoshi hoshinotsuyoshi requested review from FunamaYukina, junkisai, MH4GF and sasamuku and removed request for a team November 11, 2024 11:45
@hoshinotsuyoshi hoshinotsuyoshi changed the title draft: Enhance Frontend CI with Testing Enhance Frontend CI with Testing Nov 11, 2024
Copy link
Member

@junkisai junkisai left a 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'
Copy link
Member

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?

Suggested change
import { runPreprocess } from '../runPreprocess.js'
import { runPreprocess } from '../runPreprocess'

Comment on lines +1 to +4
import { buildCommand } from './buildCommand.js'
import { devCommand } from './devCommand.js'
import { previewCommand } from './previewCommand.js'
export { buildCommand, devCommand, previewCommand }
Copy link
Member

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?

Suggested change
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'

Copy link
Member Author

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!

@hoshinotsuyoshi hoshinotsuyoshi requested a review from a team as a code owner November 13, 2024 00:54
Base automatically changed from setup-erd-generator-cli to main November 13, 2024 05:20
@hoshinotsuyoshi hoshinotsuyoshi added this pull request to the merge queue Nov 13, 2024
Merged via the queue into main with commit 0d59a80 Nov 13, 2024
7 checks passed
@hoshinotsuyoshi hoshinotsuyoshi deleted the setup-erd-generator-cli-test branch November 13, 2024 06:15
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