webpack/test
Alexander Akait d32f1711ac
fix: hash options types (#19987)
2025-10-07 17:40:59 +03:00
..
__snapshots__ fix: hash options types (#19987) 2025-10-07 17:40:59 +03:00
benchmarkCases test: stable benchmark 2025-07-23 23:48:44 +03:00
cases fix(warnings): update import.meta warning messages for clarity (#19961) 2025-09-30 17:32:35 +03:00
configCases fix: context modules with import attributes (#19984) 2025-10-07 01:24:44 +03:00
fixtures fixes: #18687 2024-11-03 20:24:46 +05:30
helpers feat: added support for import file from "./file.ext" with { type: "bytes" } to get the content as `Uint8Array` (#19928) 2025-09-24 21:01:10 +03:00
hotCases fix: unify the error handling for hmrDownloadManifest (#19835) 2025-08-25 17:03:25 +03:00
hotPlayground chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
memoryLimitCases/json add memory limit test cases 2022-05-09 20:05:08 +03:00
runner feat: added support for import file from "./file.ext" with { type: "bytes" } to get the content as `Uint8Array` (#19928) 2025-09-24 21:01:10 +03:00
statsCases fix: `assetsByChunkName` should also included assets from `chunk.auxiliaryFiles` (#19921) 2025-09-23 20:30:13 +03:00
typesCases refactor: fix types in hot 2023-05-16 19:01:30 +03:00
watchCases test: stability and avoid extra output (#19974) 2025-10-02 21:55:56 +03:00
AbstractMethodError.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
ArrayHelpers.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
BannerPlugin.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
BenchmarkTestCases.benchmark.mjs chore: update codespeed (#19959) 2025-10-04 13:26:48 +03:00
BinaryMiddleware.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
BuildDependencies.longtest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
ChangesAndRemovals.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Chunk.unittest.js
CleanPlugin.unittest.js fix: fix potential performance issue in CleanPlugin (#19735) 2025-07-26 14:03:53 +03:00
Cli.basictest.js feat: make the `topLevelAwait` experiment stable (#19849) 2025-08-29 14:27:30 +03:00
Compiler-caching.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Compiler-filesystem-caching.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Compiler.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
ConfigCacheTestCases.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
ConfigTestCases.basictest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
ConfigTestCases.template.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
ContextModule.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
ContextModuleFactory.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Defaults.unittest.js fix: dynamic import support in workers using browserslist (#19972) 2025-10-02 19:19:35 +03:00
Errors.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Examples.test.js fix: remove unused `timeout` attribute of script tag (#19823) 2025-08-20 16:48:52 +03:00
FileSystemInfo.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
HotModuleReplacementPlugin.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
HotTestCases.template.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
HotTestCasesAsyncNode.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
HotTestCasesNode.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
HotTestCasesWeb.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
HotTestCasesWebWorker.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
JavascriptParser.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
LazySet.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
LocalModulesHelpers.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
MemoryLimitTestCases.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
ModuleDependencyError.unittest.js
MultiCompiler.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
MultiItemCache.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
MultiStats.test.js fix: types for multi compiler 2025-07-18 15:28:16 +03:00
MultiWatching.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
NodeTemplatePlugin.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
NormalModule.unittest.js chore: eslint more rules (#19648) 2025-07-03 12:06:45 +03:00
NullDependency.unittest.js
PersistentCaching.test.js feat: add `snapshot.contextModule `to configure snapshots for context modules 2025-08-25 22:16:48 +03:00
ProfilingPlugin.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
ProfilingPlugin.unittest.js chore: no `object-shorthand` for tests 2025-04-22 14:09:25 +03:00
ProgressPlugin.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Queue.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
README.md chore: fix eslint 2023-04-14 19:34:10 +03:00
RawModule.unittest.js chore: eslint more rules (#19648) 2025-07-03 12:06:45 +03:00
RequestShortener.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
RuntimeTemplate.unittest.js chore: eslint more rules (#19648) 2025-07-03 12:06:45 +03:00
SemVer.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
SharingUtil.unittest.js chore: fix spellcheck lint 2023-04-18 15:53:45 +00:00
SideEffectsFlagPlugin.unittest.js
SizeFormatHelpers.unittest.js refactor: code 2024-08-02 19:32:31 +03:00
SortableSet.unittest.js chore: eslint more rules (#19648) 2025-07-03 12:06:45 +03:00
Stats.test.js fix: remove unused `timeout` attribute of script tag (#19823) 2025-08-20 16:48:52 +03:00
StatsTestCases.basictest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
Template.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
TestCases.template.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
TestCasesAllCombined.longtest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
TestCasesCachePack.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevelopment.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolCheapSourceMap.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolEval.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolEvalCheapModuleSourceMap.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolEvalCheapSourceMap.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolEvalDeterministicModuleIds.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolEvalNamedModules.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolEvalSourceMap.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolInlineCheapSourceMap.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolInlineSourceMap.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesDevtoolSourceMap.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesHot.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesMinimizedSourceMap.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesModule.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesNormal.basictest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesProdGlobalUsed.test.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
TestCasesProduction.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
URLAbsoluteSpecifier.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
Validation.test.js fix: allow to have any properties in `experiments` to prevent validation errors when an experiment is stable 2025-08-28 20:44:33 +03:00
WasmHashes.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
Watch.test.js ci: fix test (#19830) 2025-08-24 13:50:59 +03:00
WatchCacheUnaffectedTestCases.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
WatchClose.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
WatchDetection.test.js fix: remove unused `timeout` attribute of script tag (#19823) 2025-08-20 16:48:52 +03:00
WatchSuspend.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
WatchTestCases.longtest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
WatchTestCases.template.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
WatcherEvents.test.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
WebpackError.unittest.js chore: more eslint rules (#19667) 2025-07-08 17:46:17 +03:00
checkArrayExpectation.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
cleverMerge.unittest.js chore: eslint more rules (#19648) 2025-07-03 12:06:45 +03:00
compareLocations.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
compareSourceOrder.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
compareStringsNumeric.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
compileBooleanMatcher.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
deterministicGrouping.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
extractSourceMap.unittest.js feat: add `extractSourceMap` option to implement the capabilities of loading source maps by comment 2025-08-27 18:53:50 +03:00
extractUrlAndGlobal.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
formatLocation.unittest.js refactor: code 2024-08-02 19:32:31 +03:00
identifier.unittest.js refactor: code 2024-08-02 19:32:31 +03:00
nonNumericOnlyHash.unittest.js refactor: use `eslint-config-webpack` (#19645) 2025-07-02 15:10:54 +03:00
numberHash.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
objectToMap.unittest.js chore: no `no-var` for tests 2025-04-22 13:49:30 +03:00
patch-node-env.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
propertyAccess.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
propertyName.unittest.js chore: resolve "use strict" TODO (#19705) 2025-07-16 17:29:28 +03:00
setupTestFramework.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00
smartGrouping.unittest.js
target-browserslist.unittest.js fix: dynamic import support in workers using browserslist (#19972) 2025-10-02 19:19:35 +03:00
walkCssTokens.unittest.js style: set `arrowParens` to `true` (#19706) 2025-07-16 19:13:14 +03:00

README.md

Welcome to the webpack test suite!!!!

Every pull request that you submit to webpack (besides README and spelling corrections in comments) requires tests that are created.

But don't give up hope!!! Although our tests may appear complex and overwhelming, once you become familiar with the test suite and structure, adding and creating tests will be fun and beneficial as you work inside the codebase! ❤

tl;dr

Run all tests (this automatically runs the setup):

yarn test

Run an individual suite:

yarn jest ConfigTestCases

Watch mode:

yarn jest --watch ConfigTestCases

See also: Jest CLI docs

Test suite overview

We use Jest for our tests. For more information on Jest you can visit their homepage!

Class Tests

All test files can be found in *.test.js. There are many tests that simply test APIs of a specific class/file (such as Compiler, Errors, Integration, Parser, RuleSet, Validation). If the feature you are contributing involves one of those classes, then best to start there to understand the structure.

xCases

In addition to Class specific tests, there are also directories that end in "Cases". The suites for these cases also have corresponding *.test.js files.

cases (TestCases.test.js) 1

Cases are a set of general purpose tests that will run against a variety of permutations of webpack configurations. When you are making a general purpose change that doesn't require you to have a special configuration, you would likely add your tests here. Inside of the ./test/cases directory you will find tests are broken into thematic sub directories. Take a moment to explore the different options.

To add a new case, create a new directory inside of the top level test groups, and then add an index.js file (and any other supporting files).

By default this file will be the entry point for the test suite and you can add your it()'s there. This will also become bundled so that node env support happens as well.

configCases (ConfigTestCases.basictest.js) 1

If you are trying to solve a bug which is reproducible when x and y properties are used together in a config, then configCases is the place to be!!!!

In addition to an index.js, these configCases require a webpack.config.js is located inside of your test suite. This will run this specific config through webpack just as you were building individually. They will use the same loading/bundling technique of your it() tests, however you now have a more specific config use cases that you can write even before you start coding.

statsCases (StatsTestCases.basictest.js)

Stats cases are similar to configCases except specifically focusing on the expected output of your stats. Instead of writing to the console, however the output of stats will be written to disk.

By default, the "expected" outcome is a pain to write by hand so instead when statsCases are run, runner is checking output using jest's awesome snapshot functionality.

Basically you don't need to write any expected behaviors yourself. The assumption is that the stats output from your test code is what you expect.

Please follow the approach described below:

  • write your test code in statsCases/ folder by creating a separate folder for it, for example statsCases/some-file-import-stats/index.js
import("./someModule");
  • don't forget the webpack.config.js
  • run the test
  • jest will automatically add the output from your test code to StatsTestCases.test.js.snap and you can always check your results there
  • Next time test will run -> runner will compare results against your output written to snapshot previously

You can read more about SnapShot testing right here

Questions? Comments?

If you are still nervous or don't quite understand, please submit an issue and tag us in it, and provide a relevant PR while working on!

Footnotes

1 webpack's parser supports the use of ES2015 features like arrow functions, harmony exports, etc. However as a library we follow Node.js' timeline for dropping older versions of node. Because of this we expect your tests on GitHub Actions to pass all the way back to NodeJS v10; Therefore if you would like specific tests that use these features to be ignored if they are not supported, then you should add a test.filter.js file. This allows you to import the syntax needed for that test, meanwhile ignoring it on node versions (during CI) that don't support it. webpack has a variety of helpful examples you can refer to if you are just starting out. See the ./helpers folder to find a list of the versions.