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

chore: migrate from nodeunit to jest #640

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

cesine
Copy link
Member

@cesine cesine commented Nov 27, 2024

nodeunit is deprecated. we considered mocha and jest and went with jest since it has good support for dom testing.

How this was tested

  • used windsurf to do the migration and have it commit each test with more info on what i asked it to do
  • used windsurf to add a few more tests for more coverage

Review without whitespace to see what is actually changed https://github.com/shutterstock/rickshaw/pull/640/files?diff=split&w=1

- Replace nodeunit with Jest in package.json
- Add Jest configuration optimized for browser/D3 testing
- Update test scripts to use Jest
- Add Jest setup file for global configuration
- Add Rickshaw.Graph.Legend.test.js with self-contained tests and helper function
- Add Rickshaw.Graph.Renderer.Scatterplot.test.js with D3 v3 compatibility
- Remove global state and beforeEach/afterEach hooks
- Add proper DOM cleanup in each test
- Improve test readability with clear setup/assertion/cleanup sections
- Add comprehensive render tests
- Add DOM cleanup tests
- Fix callback assertions
- Match and exceed original test coverage
- Update collectCoverageFrom to target root directory source files
- Exclude bundle files from coverage
- Remove manual JSDOM setup in favor of Jest's built-in JSDOM environment
- Simplify DOM setup using document.body.innerHTML
- Remove manual cleanup of global document/window
- Maintain original test coverage and functionality
- Convert nodeunit test to Jest format
- Use createElement for DOM setup
- Maintain original test coverage and functionality
- Convert nodeunit test to Jest format
- Add proper DOM setup and cleanup
- Handle annotation data structure and events correctly
- Maintain original test coverage and functionality
- Convert nodeunit test to Jest format
- Organize tests into logical groups
- Add descriptive test names
- Add test for mid-year values
- Maintain original test coverage
- Convert nodeunit test to Jest format
- Organize tests into logical groups
- Add descriptive test names
- Add explicit timezone verification test
- Maintain original test coverage
- Convert nodeunit test to Jest format
- Use document.body.innerHTML for DOM setup
- Add proper jQuery initialization
- Maintain original test coverage and functionality
- Keep DOM setup local to each test
- Convert nodeunit test to Jest format
- Keep jQuery global as required by source
- Convert nodeunit test to Jest format
- Use direct element creation without IDs
- Add proper DOM cleanup
- Maintain original test coverage and functionality
- Convert nodeunit test to Jest format
- Minimize shared state by moving setup into test
- Add proper DOM and renderer cleanup
- Maintain original test coverage
- Convert nodeunit test to Jest format
- Add proper Array inheritance checks
- Add descriptive comments about data point interpolation
- Maintain original test coverage
- Convert nodeunit tests to Jest format
- Minimize shared state by moving element creation into individual tests
- Remove shared series data from test scopes
- Add descriptive test blocks and assertions
- Maintain original test coverage and functionality
- Added comprehensive test coverage for Color Palette
- Removed d3 mocking in favor of integration testing
- Added tests for edge cases and core functionality
- Added comprehensive test coverage for RangeSlider.Preview
- Created helper functions for clean test instance creation
- Ensured test isolation with no shared state
- Added tests for error handling, callbacks, and DOM structure
Migrated Rickshaw.Graph.Renderer tests from nodeunit to Jest:
- Added comprehensive domain calculation tests
- Added stroke factory tests
- Added empty series handling tests
- Added configuration tests
- Created reusable test helper functions
- Maintained original test behavior with TODO note
Migrated main Rickshaw test file from nodeunit to Jest:
- Added version check test
- Added namespace existence tests
- Added color utilities tests
- Added class system tests
- Improved test organization and coverage
- Reduce shared state in test by moving test data into individual test cases
- Fix fill method test to properly verify null fill value
- Remove debug logging
add coverage for ajax
Update coverage thresholds to match current test coverage:
- Fix legend item order handling
- Improve transform function verification
- Fix stroke color comparison
- Add comprehensive test cases for series highlighting
Added comprehensive test coverage for the Series Order behavior:
- Test jQuery and jQuery UI dependency checks
- Verify legend sortable initialization
- Test graph updates on legend reordering
- Verify legend height maintenance

Implemented with minimal jQuery UI mock to avoid external dependencies.
Added comprehensive test coverage for the LinePlot renderer:
- Test default settings and configuration
- Verify path and circle rendering
- Test custom dot sizes (global and per-point)
- Handle disabled series and null values
- Test line interpolation and tension

Improved test isolation using:
- Helper function for graph creation
- Clean DOM cleanup
- Proper d3 line factory mocking
@@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [12.x, 22.x]
node-version: [22.x]
Copy link
Member Author

Choose a reason for hiding this comment

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

jest no longer supports node 12 https://jestjs.io/docs/upgrading-to-jest29

https://github.com/cesine/rickshaw/actions/runs/12040292801/job/33569879332

Run npm run coverage

> [email protected] coverage /home/runner/work/rickshaw/rickshaw
> jest --coverage

/home/runner/work/rickshaw/rickshaw/node_modules/jest/node_modules/jest-cli/build/run.js:135
    if (error?.stack) {
              ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:[9](https://github.com/cesine/rickshaw/actions/runs/12040317722/job/33569956048#step:6:10)15:16)

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.

1 participant