-
Notifications
You must be signed in to change notification settings - Fork 1
test: Add comprehensive unit tests and CI workflow #65
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| name: Run Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [18.x, 20.x] | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 8 | ||
|
|
||
| - name: Get pnpm store directory | ||
| id: pnpm-cache | ||
| shell: bash | ||
| run: | | ||
| echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Setup pnpm cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | ||
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pnpm-store- | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Run tests | ||
| run: pnpm test | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance Issue: Redundant test execution This workflow runs tests twice:
The second run repeats all tests with coverage instrumentation. Consider running tests only once: - name: Run tests with coverage
run: pnpm test:coverage
if: matrix.node-version == '20.x'
- name: Run tests (no coverage)
run: pnpm test
if: matrix.node-version == '18.x'This would reduce CI time by ~50% for the Node 20.x job. |
||
|
|
||
| - name: Run tests with coverage | ||
| run: pnpm test:coverage | ||
| if: matrix.node-version == '20.x' | ||
|
|
||
| - name: Upload coverage reports | ||
| uses: codecov/codecov-action@v3 | ||
| if: matrix.node-version == '20.x' | ||
| with: | ||
| files: ./coverage/lcov.info | ||
| flags: unittests | ||
| name: codecov-umbrella | ||
| fail_ci_if_error: false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'jsdom', | ||
| roots: ['<rootDir>/src'], | ||
| testMatch: ['**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'], | ||
| moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], | ||
| collectCoverageFrom: [ | ||
| 'src/**/*.{ts,tsx}', | ||
| '!src/**/*.d.ts', | ||
| '!src/types/**', | ||
| '!src/**/*.stories.tsx' | ||
| ], | ||
| setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'], | ||
| moduleNameMapper: { | ||
| '\\.(css|less|scss|sass)$': 'identity-obj-proxy', | ||
| '\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/src/test/__mocks__/fileMock.js' | ||
| }, | ||
| transform: { | ||
| '^.+\\.tsx?$': ['ts-jest', { | ||
| tsconfig: { | ||
| jsx: 'react', | ||
| esModuleInterop: true, | ||
| allowSyntheticDefaultImports: true, | ||
| verbatimModuleSyntax: false, | ||
| module: 'commonjs', | ||
| target: 'es2020' | ||
| } | ||
| }] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 new CI job installs dependencies using
pnpm install --frozen-lockfile(lines 26‑47), but this same commit also added new Jest dependencies and scripts topackage.jsonwithout updatingpnpm-lock.yaml. When pnpm runs with--frozen-lockfileand the lockfile is out of sync withpackage.json, it aborts with “Cannot install with frozen lockfile because pnpm-lock.yaml is not up to date,” so this workflow never reaches the test steps. Please update the pnpm lockfile (or drop the frozen flag) so the CI job introduced here can actually execute.Useful? React with 👍 / 👎.
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.
@codex fix this issue on 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.
Summary
pnpm-lock.yamlto capture the new testing-related dependencies (@testing-library/*,@types/jest,fake-indexeddb,jest,jest-environment-jsdom,ts-jest, etc.), ensuring the CI workflow can runpnpm install --frozen-lockfilewithout aborting. pnpm-lock.yamlL41-L80Testing
View task →