Skip to content

Conversation

@justin808
Copy link
Member

Summary

Addresses #844 by adding comprehensive Jest unit tests for the rspack public API exports in package/rspack/index.ts.

What was tested

All 17 tests pass and verify:

Webpack-merge function exports - merge, mergeWithRules, mergeWithCustomize, unique
Configuration object exports - config, devServer, env, rules, baseConfig
Utility function exports - moduleExists, canProcess, inliningCss
generateRspackConfig() behavior:

  • Returns immutable config objects
  • Properly merges extra configuration
  • Validates input arguments (errors on multiple configs)
  • Includes required plugins array
  • Includes optimization object
  • Includes module rules array
  • Respects NODE_ENV for environment-specific configs
  • Falls back to base config for unknown environments
  • Correctly merges environment and extra configs

Key improvements

  • baseConfig verification: Tests confirm baseConfig is a valid rspack configuration object with required properties (output, resolve), helping catch issues like those reported in baseConfig export from rspack is broken, baseConfig for webpack might be broken as well #843
  • Dependency validation mocking: Tests mock validateRspackDependencies() to avoid requiring actual rspack dependencies during test runs
  • Environment variable setup: Tests properly set SHAKAPACKER_ASSETS_BUNDLER=rspack to ensure rspack-specific code paths are tested

Test file location

test/package/rspack/index.test.js - mirrors the structure of existing test/package/index.test.js for webpack

Test plan

  • All 17 new tests pass
  • All existing package tests still pass
  • Linting passes

🤖 Generated with Claude Code

Addresses issue #844 by adding Jest unit tests for the rspack public API.
These tests verify all exports from package/rspack/index.ts work correctly.

Tests cover:
- Webpack-merge function exports (merge, mergeWithRules, etc.)
- Configuration object exports (config, devServer, env, rules, baseConfig)
- Utility function exports (moduleExists, canProcess, inliningCss)
- generateRspackConfig() behavior:
  - Returns immutable config objects
  - Properly merges extra configuration
  - Validates input arguments
  - Includes required plugins and optimization
  - Respects NODE_ENV for environment-specific configs
  - Falls back to base config for unknown environments
  - Merges environment and extra configs correctly

The baseConfig export is verified to be a valid rspack configuration
object, which helps catch issues like those reported in #843.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Feb 9, 2026

Warning

Rate limit exceeded

@justin808 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jg/fix-ci-linting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link

greptile-apps bot commented Feb 9, 2026

Greptile Overview

Greptile Summary

This PR adds a new Jest test suite under test/package/rspack/index.test.js that exercises the rspack public API surface from package/rspack/index.ts, including re-exported webpack-merge helpers, config/devServer/env/rules/baseConfig exports, and several behavioral checks for generateRspackConfig() (merging, environment selection, and required top-level properties).

The tests follow the same overall structure as the existing test/package/index.test.js suite used for webpack, with additional rspack-specific environment setup (SHAKAPACKER_ASSETS_BUNDLER=rspack) and mocks to avoid requiring rspack dependencies during unit test runs.

Confidence Score: 4/5

  • Mostly safe to merge once the new tests are made deterministic and aligned with current error messages.
  • Changes are isolated to a new test file and generally mirror existing test patterns, but there are a couple of correctness issues (NODE_ENV not restored; mismatched expected error message) that can cause false failures/flakiness in CI.
  • test/package/rspack/index.test.js

Important Files Changed

Filename Overview
test/package/rspack/index.test.js Adds Jest coverage for rspack public exports and generateRspackConfig; contains environment leakage (NODE_ENV) and a brittle error-message assertion that will fail if the message changes.

Sequence Diagram

sequenceDiagram
  participant T as Jest test
  participant I as package/rspack/index
  participant V as validateDependencies
  participant E as env
  participant FS as fs
  participant P as plugins/optimization
  participant WM as webpack-merge

  T->>I: require("package/rspack/index")
  T->>T: set SHAKAPACKER_ASSETS_BUNDLER=rspack
  T->>T: jest.mock(validateDependencies, helpers)

  T->>I: generateRspackConfig(extraConfig?)
  I->>V: validateRspackDependencies()
  I->>E: read env.nodeEnv (from NODE_ENV)
  I->>FS: existsSync(environments/{nodeEnv}.js)
  alt env config exists
    I->>I: require(environment config)
  else missing
    I->>I: use baseConfig
  end
  I->>P: getPlugins(), getOptimization()
  I->>WM: merge({}, baseRspackConfig, extraConfig)
  WM-->>T: merged config object
Loading

@justin808
Copy link
Member Author

@greptile, review this PR.
@claude, review this PR.

@claude
Copy link

claude bot commented Feb 10, 2026

Claude finished @justin808's task in 58s —— View job


Code Review Complete ✅

Todo List:

  • Read the new test file (test/package/rspack/index.test.js)
  • Read the source file being tested (package/rspack/index.ts)
  • Read comparison webpack tests (test/package/index.test.js)
  • Analyze test quality and coverage
  • Provide comprehensive review feedback

Summary

This PR adds excellent comprehensive test coverage for the rspack public API. The tests are well-structured, follow existing patterns, and properly verify all exports and behaviors. Approved - ready to merge!

Strengths

1. Comprehensive Coverage

  • All 13 exports from package/rspack/index.ts are tested
  • generateRspackConfig() behavior is thoroughly tested (9 test cases)
  • Tests verify both the "happy path" and error conditions

2. Proper Test Setup

  • Correctly mocks moduleExists() to return false (avoiding dependency issues)
  • Properly mocks validateRspackDependencies() to skip validation during tests
  • Sets SHAKAPACKER_ASSETS_BUNDLER=rspack environment variable
  • Uses jest.resetModules() in beforeEach to ensure clean state
  • Proper cleanup with afterAll(() => process.chdir(rootPath))

3. Mirrors Existing Patterns

  • Test structure closely follows test/package/index.test.js for webpack
  • Uses same helper functions (chdirTestApp, resetEnv)
  • Consistent naming conventions and assertion patterns

4. Important Validations

  • Tests immutability (test/package/rspack/index.test.js:89-100)
  • Tests config merging behavior (test/package/rspack/index.test.js:102-115)
  • Tests error handling for multiple configs (test/package/rspack/index.test.js:117-123)
  • Tests environment-specific behavior (test/package/rspack/index.test.js:153-189)
  • Verifies required config properties like output, resolve, plugins, optimization, and module.rules

5. Addresses Issue #844

Minor Observations

1. Test Consistency with webpack tests
The webpack tests in test/package/index.test.js are less comprehensive (only 4 tests vs 17 here). This rspack test suite is actually more thorough, which is positive. Consider backporting some of these test patterns to the webpack tests in a future PR.

2. Missing unique export test
The test at line 35-41 checks for merge, mergeWithRules, mergeWithCustomize, and unique functions. However, looking at package/rspack/index.ts, I only see three webpack-merge exports (lines 56-61):

export {
  merge,
  mergeWithCustomize,
  mergeWithRules,
  unique
} from "webpack-merge"

Actually, unique IS exported (line 60), so the test is correct. ✅

3. Environment Variable Testing
The tests properly test NODE_ENV behavior:

  • Production mode (test/package/rspack/index.test.js:153-161)
  • Development mode (test/package/rspack/index.test.js:177-189)
  • Non-existent environment fallback (test/package/rspack/index.test.js:163-175)

This is thorough and covers all code paths in the source.

Code Quality

Formatting

  • File ends with trailing newline (line 191) - follows project linting rules
  • Consistent indentation and style
  • Clear test descriptions

Best Practices

  • Each test is focused and tests one thing
  • Uses proper Jest matchers (toBeInstanceOf, toBeDefined, toHaveProperty, toThrow)
  • Tests are independent and can run in any order
  • Proper use of beforeEach and afterAll for setup/cleanup

Recommendations

None - this is excellent test coverage that follows all project conventions. The PR is ready to merge as-is.

Test Coverage Analysis

All 13 exports verified:

  • merge (line 37)
  • mergeWithRules (line 38)
  • mergeWithCustomize (line 39)
  • unique (line 40)
  • config (lines 43-48)
  • devServer (lines 50-54)
  • env (lines 56-61)
  • rules (lines 63-67)
  • baseConfig (lines 69-75)
  • moduleExists (line 79)
  • canProcess (line 80)
  • inliningCss (line 81)
  • generateRspackConfig (lines 84-189)

All generateRspackConfig() behaviors verified:

  • ✅ Returns immutable objects
  • ✅ Merges extra config
  • ✅ Errors on multiple configs
  • ✅ Includes plugins array
  • ✅ Includes optimization object
  • ✅ Includes module.rules array
  • ✅ Respects NODE_ENV for production
  • ✅ Respects NODE_ENV for development
  • ✅ Falls back to baseConfig for unknown environments
  • ✅ Merges environment and extra configs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +28 to +32
beforeEach(() => {
jest.resetModules()
resetEnv()
process.env.SHAKAPACKER_ASSETS_BUNDLER = "rspack"
})
Copy link

Choose a reason for hiding this comment

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

NODE_ENV leaks across tests

Several tests set process.env.NODE_ENV and call jest.resetModules(), but beforeEach() does not restore NODE_ENV back to its prior value. This can make later tests in this file (or other test files, depending on Jest execution order) run under the wrong environment. Consider capturing the original NODE_ENV at file scope and restoring it in beforeEach()/afterEach() (similar to how resetEnv() is used).

Comment on lines +117 to +122
test("generateRspackConfig errors if multiple configs are provided", () => {
const { generateRspackConfig } = require("../../../package/rspack/index")

expect(() => generateRspackConfig({}, {})).toThrow(
"use webpack-merge to merge configs before passing them to Shakapacker"
)
Copy link

Choose a reason for hiding this comment

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

Brittle error message assertion

This assertion matches a specific substring that currently differs from the actual thrown message in package/rspack/index.ts (it includes the prefix "Only one extra config may be passed here - ..."). As written, this test will fail even when the code behaves correctly. Align the expectation with the real message (or assert on a more stable substring / error type).

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