webpack/test
Jack Works cf1dc2f131
feat: implement tc39 Defer Module Evaluation (experiment)
* feat: implement tc39 defer import proposal

Co-authored-by: Nicolo Ribaudo <hello@nicr.dev>

* fix: keys of DeferredNamespaceObject

* refactor: MakeDeferredNamespaceObjectRuntimeModule

---------

Co-authored-by: Nicolo Ribaudo <hello@nicr.dev>
Co-authored-by: Hai <haijie0619@gmail.com>
2025-07-02 15:02:03 +03:00
..
__snapshots__ feat: implement tc39 Defer Module Evaluation (experiment) 2025-07-02 15:02:03 +03:00
benchmarkCases chore: migrate on tinybench (#19533) 2025-05-15 18:43:29 +03:00
cases feat: support `using` keyword 2025-06-26 20:10:49 +03:00
configCases feat: implement tc39 Defer Module Evaluation (experiment) 2025-07-02 15:02:03 +03:00
fixtures fixes: #18687 2024-11-03 20:24:46 +05:30
helpers feat: support `using` keyword 2025-06-26 20:10:49 +03:00
hotCases test: update tests for ESM HMR 2025-06-24 17:44:54 +03:00
hotPlayground chore: no `no-var` for tests 2025-04-22 13:49:30 +03:00
memoryLimitCases/json add memory limit test cases 2022-05-09 20:05:08 +03:00
runner feat: HMR support for ESM 2025-06-23 15:22:23 +03:00
statsCases fix: a lot of types (#19486) 2025-05-01 17:36:51 +03:00
typesCases refactor: fix types in hot 2023-05-16 19:01:30 +03:00
watchCases chore: refactor test (#19608) 2025-06-20 17:08:04 +03:00
AbstractMethodError.unittest.js
ArrayHelpers.unittest.js perf: Prevent running regexs over the same strings twice 2021-11-10 01:22:09 +00:00
BannerPlugin.test.js chore: no `object-shorthand` for tests 2025-04-22 14:09:25 +03:00
BenchmarkTestCases.benchmark.mjs test: refactor test code (#19564) 2025-05-28 17:40:54 +03:00
BinaryMiddleware.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
BuildDependencies.longtest.js chore: no `camelcase` for tests 2025-04-22 14:12:34 +03:00
ChangesAndRemovals.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
Chunk.unittest.js
CleanPlugin.unittest.js fix: CleanPlugin unlink same file twice (#19595) 2025-06-10 17:18:43 +03:00
Cli.basictest.js style: improve 2024-08-02 19:32:22 +03:00
Compiler-caching.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
Compiler-filesystem-caching.test.js fix: respect the `cause` of any errors and the `errors` of `AggregateError` in stats 2025-04-23 00:36:13 +03:00
Compiler.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
ConfigCacheTestCases.longtest.js use infrastructure-log file 2022-02-15 09:08:02 +03:00
ConfigTestCases.basictest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
ConfigTestCases.template.js chore: refactor test (#19608) 2025-06-20 17:08:04 +03:00
ContextModule.unittest.js Revert "Revert "Merge pull request #15332 from webpack/fix/context-resolve-issue-11335"" 2022-02-21 11:58:44 +03:00
ContextModuleFactory.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
Defaults.unittest.js refactor: reimplement hmrDownloadManifest in ESM to support more platforms 2025-06-26 21:11:41 +03:00
Errors.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
Examples.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
FileSystemInfo.unittest.js refactor: improve eslint configuration and better types 2025-03-12 04:56:14 +03:00
HotModuleReplacementPlugin.test.js fix: hash to fullhash 2025-03-18 10:13:47 +05:30
HotTestCases.template.js feat: HMR support for ESM 2025-06-23 15:22:23 +03:00
HotTestCasesAsyncNode.test.js
HotTestCasesNode.test.js
HotTestCasesWeb.test.js
HotTestCasesWebWorker.test.js
JavascriptParser.unittest.js fix: types and test (#19558) 2025-05-23 16:39:55 +03:00
LazySet.unittest.js
LocalModulesHelpers.unittest.js
MemoryLimitTestCases.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
ModuleDependencyError.unittest.js
MultiCompiler.test.js refactor: code 2024-08-02 19:32:31 +03:00
MultiItemCache.unittest.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
MultiStats.test.js refactor: improve code 2024-08-02 19:32:29 +03:00
MultiWatching.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
NodeTemplatePlugin.test.js chore: avoid eslint warning after running tests (#19534) 2025-05-15 18:16:26 +03:00
NormalModule.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
NullDependency.unittest.js
PersistentCaching.test.js style: improve 2024-08-02 19:32:22 +03:00
ProfilingPlugin.test.js refactor: code 2024-08-02 19:32:31 +03:00
ProfilingPlugin.unittest.js chore: no `object-shorthand` for tests 2025-04-22 14:09:25 +03:00
ProgressPlugin.test.js test: refactor test code (#19564) 2025-05-28 17:40:54 +03:00
Queue.unittest.js perf: a faster Queue implementation 2024-11-20 16:51:43 +03:00
README.md chore: fix eslint 2023-04-14 19:34:10 +03:00
RawModule.unittest.js
RequestShortener.unittest.js
RuntimeTemplate.unittest.js fix RuntimeTemplate 2021-11-29 23:00:37 +03:00
SemVer.unittest.js chore: deps update 2024-06-19 20:48:41 +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
Stats.test.js fix: types 2025-06-24 17:43:58 +03:00
StatsTestCases.basictest.js chore: update Jest to `v30` (#19604) 2025-06-12 15:17:12 +03:00
Template.unittest.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
TestCases.template.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
TestCasesAllCombined.longtest.js test: more 2024-01-12 18:34:17 +03:00
TestCasesCachePack.longtest.js remove big assets case from allowlist 2022-02-15 13:26:56 +01:00
TestCasesDevelopment.test.js
TestCasesDevtoolCheapSourceMap.test.js
TestCasesDevtoolEval.test.js
TestCasesDevtoolEvalCheapModuleSourceMap.test.js
TestCasesDevtoolEvalCheapSourceMap.test.js
TestCasesDevtoolEvalDeterministicModuleIds.test.js
TestCasesDevtoolEvalNamedModules.test.js
TestCasesDevtoolEvalSourceMap.test.js
TestCasesDevtoolInlineCheapSourceMap.test.js
TestCasesDevtoolInlineSourceMap.longtest.js move some test suites to long tests 2021-10-20 15:09:16 +02:00
TestCasesDevtoolSourceMap.longtest.js move some test suites to long tests 2021-10-20 15:09:16 +02:00
TestCasesHot.test.js
TestCasesMinimizedSourceMap.longtest.js move some test suites to long tests 2021-10-20 15:09:16 +02:00
TestCasesModule.test.js
TestCasesNormal.basictest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
TestCasesProdGlobalUsed.test.js
TestCasesProduction.longtest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
URLAbsoluteSpecifier.unittest.js refactor: code 2024-08-02 19:32:31 +03:00
Validation.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
WasmHashes.unittest.js refactor: code 2024-08-02 19:32:31 +03:00
Watch.test.js add test case 2021-11-20 11:16:54 +01:00
WatchCacheUnaffectedTestCases.longtest.js optimization.sideEffects is compatible with cacheUnaffected 2021-10-05 16:54:51 +02:00
WatchClose.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
WatchDetection.test.js chore: more jsdocs 2025-04-22 15:44:21 +03:00
WatchSuspend.test.js refactor: improve code 2024-08-02 19:32:29 +03:00
WatchTestCases.longtest.js run test cases for cacheUnaffected 2021-10-05 15:08:20 +02:00
WatchTestCases.template.js chore: refactor test (#19608) 2025-06-20 17:08:04 +03:00
WatcherEvents.test.js style: improve style of code 2024-08-02 19:32:14 +03:00
WebpackError.unittest.js
checkArrayExpectation.js test: refactor test code (#19564) 2025-05-28 17:40:54 +03:00
cleverMerge.unittest.js
compareLocations.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
compareStringsNumeric.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
compileBooleanMatcher.unittest.js style: improve 2024-08-02 19:32:22 +03:00
deterministicGrouping.unittest.js style: improve style of code 2024-08-02 19:32:14 +03:00
extractUrlAndGlobal.unittest.js feat: throw error for invalid remotes 2021-11-28 18:08:25 +08: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 fit in hex digest 2022-02-02 19:04:31 +03:00
numberHash.unittest.js
objectToMap.unittest.js chore: no `no-var` for tests 2025-04-22 13:49:30 +03:00
patch-node-env.js style: improve style of code 2024-08-02 19:32:14 +03:00
propertyAccess.unittest.js Initial take 2023-05-04 20:41:15 -07:00
propertyName.unittest.js Initial take 2023-05-04 20:41:15 -07:00
setupTestFramework.js refactor: improve code 2024-08-02 19:32:29 +03:00
smartGrouping.unittest.js
target-browserslist.unittest.js
walkCssTokens.unittest.js test: fix 2024-11-06 22:18:34 +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.