Skip to content

Vitest test suite (#18)#92

Open
EdoAbarca wants to merge 5 commits intogbowne1:masterfrom
EdoAbarca:test/vitest-test-suite
Open

Vitest test suite (#18)#92
EdoAbarca wants to merge 5 commits intogbowne1:masterfrom
EdoAbarca:test/vitest-test-suite

Conversation

@EdoAbarca
Copy link

This pull request introduces a comprehensive testing setup for both backend and frontend code, using Vitest as the primary testing framework. It adds test scripts, dependencies, configuration files, and example tests, as well as updates documentation to guide contributors on testing practices. The CI workflow is updated to include test execution and coverage reporting.

Testing infrastructure and configuration:

  • Added Vitest test scripts to package.json and installed related dependencies for coverage, UI, DOM environments, and mocking (vitest, @vitest/ui, @vitest/coverage-v8, happy-dom, jsdom, mongodb-memory-server, supertest). [1] [2]
  • Created vitest.config.backend.js and vitest.config.frontend.js for separate backend (Node) and frontend (jsdom) test environments, with coverage and setup files specified. [1] [2]
  • Updated vite.config.js to include a unified test configuration and coverage exclusion rules.

Continuous Integration workflow:

  • Modified .github/workflows/ci.yml to run tests and generate coverage reports during CI, ensuring test results are part of the build process.

Documentation and contributor guidance:

  • Expanded CONTRIBUTING.md with a new Testing section, instructions for running tests, maintaining coverage, and test structure/examples.
  • Fixed a minor typo in contributor guidelines.

Test utilities and example tests:

  • Added test setup files (tests/setup.js, tests/setup.browser.js) for environment configuration and mocking. [1] [2]
  • Created helper modules for mock data and Express objects (tests/helpers/mockData.js, tests/helpers/mockExpress.js). [1] [2]
  • Added backend unit tests for authentication middleware (tests/unit/backend/middleware/auth.test.js).
  • Added frontend unit tests for utility functions, theme management, and filtering logic (tests/unit/frontend/main.test.js, tests/unit/frontend/theme.test.js). [1] [2]

Resolves #18

- Installed Vitest, @vitest/ui, @vitest/coverage-v8, jsdom, happy-dom, supertest, and mongodb-memory-server as dev dependencies
- Added test scripts to package.json: test, test:ui, test:run, test:coverage
- Created vitest.config.backend.js for Node.js backend tests
- Created vitest.config.frontend.js for jsdom frontend tests
- Updated vite.config.js with test configuration and setup files
- Updated .gitignore to exclude coverage reports, .env.test, and test artifacts
- Created tests/setup.js for backend test environment with dotenv configuration
- Created tests/setup.browser.js for frontend test environment with jsdom setup
- Added tests/helpers/mockData.js with mock users and streams data
- Added tests/helpers/mockExpress.js with Express req/res/next mock utilities
- Set up global test configuration including localStorage and fetch mocks
- Exported TEST_JWT_SECRET for consistent JWT testing across test suites
Backend Tests (10 tests):
- tests/unit/backend/middleware/auth.test.js
  - JWT token validation (valid, missing, invalid format, expired)
  - Role-based authorization (correct role, incorrect role, missing role)
  - 100% code coverage on auth middleware

Frontend Tests (20 tests):
- tests/unit/frontend/theme.test.js (8 tests)
  - localStorage operations (save, retrieve, overwrite, clear)
  - DOM manipulation (dark class, toggle, icon updates)

- tests/unit/frontend/main.test.js (12 tests)
  - formatViewers() utility function (number formatting)
  - debounce() helper function
  - getFilteredStreams() filtering logic (category, subcategory, languages)

Total: 30 passing tests across backend and frontend
All tests validated with 'npm run test:run'
- Added comprehensive Testing section with guidelines for contributors
- Documented test commands (npm test, test:run, test:ui, test:coverage)
- Explained test directory structure (backend, frontend, integration, helpers)
- Provided example test following AAA pattern (Arrange, Act, Assert)
- Fixed typo: 'collsborator' -> 'collaborator'
- Emphasized importance of maintaining test coverage for PRs
- Added 'Run Tests' step to execute npm run test:run in CI workflow
- Added 'Generate Coverage Report' step with npm run test:coverage
- Tests run after linting and formatting checks, before build
- Coverage generation continues on error to not block pipeline
- Tests will run on all Node.js versions (20, 22, 24) in matrix
- Ensures all PRs have passing tests before merge
@EdoAbarca EdoAbarca marked this pull request as draft February 8, 2026 01:42
@EdoAbarca
Copy link
Author

test-front Frontend test suite

@EdoAbarca
Copy link
Author

test-back Test backend

@EdoAbarca
Copy link
Author

test-cov-1 test-cov-2 Coverage

@EdoAbarca
Copy link
Author

EdoAbarca commented Feb 8, 2026

@gbowne1 I’m unable to update the PR's assignes, reviewers and more, this to meet the CONTRIBUTING.md requirements, could you please address that?

@gbowne1
Copy link
Owner

gbowne1 commented Feb 8, 2026

That requires clarification. That can only be done by collaborators and maintainers. I will do that.

If you wish to be a regular contributor to this project let us know in the appropriate area of the Discussion tab

I'll also review your PR

@gbowne1 gbowne1 added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Feb 8, 2026
@gbowne1 gbowne1 added this to the Alpha milestone Feb 8, 2026
@gbowne1 gbowne1 marked this pull request as ready for review February 8, 2026 02:12
Copy link
Owner

@gbowne1 gbowne1 left a comment

Choose a reason for hiding this comment

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

@EdoAbarca

I checked out this change locally for testing and review for merge

This adds much needed tests to the codestream project

I was able to replicate the expected results from this PR description

Approving this PR for merge pending further review by our collaborators and maintainers

Thanks for the opportunity to review your PR and for your contribution to this project and please feel free to work on this project, help review its bug fixes, report issues with it and or work on any other projects I have here on Github https://github.com/gbowne1

There are open discussions on the Discussion tab here as well

@gbowne1
Copy link
Owner

gbowne1 commented Feb 8, 2026

@EdoAbarca

I merged a large PR #87 as an Emergency WIP because of CI breakage. package-lock.json needs fixed. (Probably a delete then reinstall or we untracked it and node_modules left local only)

Make sure this PR works with the new merges

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TODO] add Vitest and create unit tests

2 participants