Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/test.yml
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

Comment on lines +26 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep pnpm lockfile in sync with new workflow step

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 to package.json without updating pnpm-lock.yaml. When pnpm runs with --frozen-lockfile and the lockfile is out of sync with package.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 👍 / 👎.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

  • Updated pnpm-lock.yaml to capture the new testing-related dependencies (@testing-library/*, @types/jest, fake-indexeddb, jest, jest-environment-jsdom, ts-jest, etc.), ensuring the CI workflow can run pnpm install --frozen-lockfile without aborting. pnpm-lock.yamlL41-L80

Testing

  • ⚠️ Not run (not requested)

View task →

- name: Run tests
run: pnpm test

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Issue: Redundant test execution

This workflow runs tests twice:

  1. Line 49: pnpm test
  2. Line 52: pnpm test:coverage

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
30 changes: 30 additions & 0 deletions jest.config.js
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'
}
}]
}
}
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"build": "plasmo build",
"package": "plasmo package",
"format": "prettier --write .",
"format:check": "prettier --check ."
"format:check": "prettier --check .",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"dependencies": {
"@emotion/react": "^11.14.0",
Expand All @@ -25,11 +28,18 @@
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "4.1.1",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@types/chrome": "0.0.258",
"@types/jest": "^29.5.11",
"@types/node": "20.11.5",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"fake-indexeddb": "^5.0.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "3.2.4",
"ts-jest": "^29.1.1",
"typescript": "5.3.3"
},
"manifest": {
Expand Down
Loading
Loading