TESTING_DOCS.md
This document explains the structure of the test/ directory in the Webpack project using Jest. The directory is organized into multiple folders and files, each serving a specific purpose in testing various aspects of Webpack’s functionality.
__snapshots__/benchmarkCases/cases/configCases/fixtures/helpers/hotCases/hotPlayground/memoryLimitCases/jsonstatsCases/typesCases/test262-cases/git submodule update --init test/test262-cases. Test runner: test/test262.spectest.js.watchCases/*.unittest.jsBannerPlugin.test.jsBannerPlugin functionality.Many Webpack tests simulate small projects that are compiled during the test run.
For example, a configuration test may look like:
test/configCases/entry/simple/ index.js webpack.config.js expected.txt
Explanation:
During the test run, webpack compiles this project and compares the result with the expected output to ensure behavior remains consistent.
To execute all tests:
yarn test
Choose test command based on modified directory:
| Modified directory/file | Command |
|---|---|
test/*.unittest.js | yarn test:base -- --testPathPatterns="<filename>" |
test/cases/ | yarn test:basic |
test/configCases/ | yarn test:basic -- --testPathPatterns="ConfigTestCases" |
test/statsCases/ | yarn test:basic -- --testPathPatterns="StatsTestCases" |
test/watchCases/ | yarn test:base -- --testPathPatterns="WatchTestCases" |
test/hotCases/ | yarn test:base -- --testPathPatterns="HotTestCases" |
test/benchmarkCases/ | FILTER="<case-name>" yarn benchmark |
test/test262-cases/ | yarn test:test262 (requires git submodule update --init test/test262-cases first) |
Running a single test case with --testNamePattern. The test name format is <category> <case-name> (e.g., css basic, asset url):
yarn test:basic -- --testPathPatterns="ConfigTestCases" --testNamePattern="css basic"
Multiple patterns can be combined with |:
yarn test:basic -- --testPathPatterns="ConfigTestCases" --testNamePattern="css basic|css url"
yarn test before pushing changes to validate functionality.