Because Rspack uses a mix of Rust and Node.js code, different testing strategies are used for each.
Rust test cases are only suitable for unit testing. To test the complete build process, please add Node.js test cases.
You can run the Rust code's test cases using ./x test rust
or cargo test
.
Test cases are written within the Rust code. For example:
For more information, please refer to: Rust: How to Write Tests
Node.js testing provides three test suites:
Rspack copied the whole Webpack test suite to the webpack-test
folder to check the compatibility of webpack. If you need to add new test cases, it is recommended to first check if the case has been exists in this folder. You can enable a test case by removing the test.filter.js
file or modifying its return value to true
.
You can run Webpack tests by running ./x test webpack
or pnpm run test:webpack
at the root folder.
If you encounter any problems, please do not modify the original code of the Webpack test cases. You can copy it and follow the Rspack Testing to create new test cases in packages/rspack-test-tools/tests
.
For more details, please refer to: Webpack Testing.
Rspack's test cases are stored in the packages/rspack-test-tools/tests
folder, including unique test cases and cases that require modification for Webpack and Webpack plugins.
You can run Rspack tests by running ./x test unit
or pnpm run test:unit
at the root folder.
You can also go to the packages/rspack-test-tools
folder and run npm run test
to run test cases and add some arguments:
-u
, like npm run test -- -u
-t
, like npm run test -- -t config/asset
to only run test cases from the packages/rspack-test-tools/configCases/asset
folder (config
will be automatically mapped to configCases
, and other folders work similarly). Pattern matching supports regex, see jest for details.For more details, please refer to: Rspack Testing.
Due to implementation differences and performance considerations, Rspack will internally support some Webpack plugins. Similarly, the test suites for these plugins are copied to the plugin-test
folder to test the compatibility of the plugins.
You can run Webpack plugin tests by running ./x test plugin
or pnpm run test:plugin
at the root folder.
In most cases, even if you modify the functionality of the corresponding plugin, you only need to follow Rspack Testing to add new test cases.
Only when you native implement a new Webpack plugin and need to copy its test cases, you can add them to this suite.
For more details, please refer to: Webpack Plugin Testing.