webpack/test
Tobias Koppers 98ea582bf0 watch package.json for managed directories 2021-11-15 17:06:04 +01:00
..
__snapshots__ update snapshot 2021-11-15 10:44:29 +01:00
benchmarkCases
cases fix #14662 2021-11-05 17:24:25 +01:00
configCases watch package.json for managed directories 2021-11-15 17:06:04 +01:00
fixtures fix using single quotes with esm files 2021-11-09 12:24:53 +01:00
helpers refactor and add test case 2021-10-25 12:12:52 +02:00
hotCases fix port 2021-10-30 19:45:33 +03:00
hotPlayground
statsCases split chunks `chunks` filter also affects fallbackCacheGroup 2021-11-02 13:23:09 +01:00
typesCases refactor, rename, extend, fix, add tests 2021-11-03 12:38:05 +01:00
watchCases watch package.json for managed directories 2021-11-15 17:06:04 +01:00
AbstractMethodError.unittest.js
ArrayHelpers.unittest.js perf: Prevent running regexs over the same strings twice 2021-11-10 01:22:09 +00:00
BenchmarkTestCases.benchmark.js pretty files 2021-05-11 09:31:46 +02:00
BinaryMiddleware.unittest.js
BuildDependencies.longtest.js move some test suites to long tests 2021-10-20 15:09:16 +02:00
ChangesAndRemovals.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
Chunk.unittest.js
Cli.basictest.js update snapshot and move cli test to basic tests 2021-11-05 11:31:10 +01:00
Compiler-caching.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
Compiler.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
ConfigCacheTestCases.longtest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
ConfigTestCases.basictest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
ConfigTestCases.template.js fix null module externals 2021-09-03 13:47:09 +02:00
ContextModuleFactory.unittest.js
Defaults.unittest.js Merge pull request #14718 from webpack/fix-managed-path 2021-11-12 14:42:05 +01:00
Errors.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
Examples.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
FileSystemInfo.unittest.js allow to configure all hash functions used 2021-09-23 14:55:13 +02:00
HotModuleReplacementPlugin.test.js
HotTestCases.template.js keep state of chunk loading during hmr updates 2021-08-16 13:50:43 +02:00
HotTestCasesAsyncNode.test.js
HotTestCasesNode.test.js
HotTestCasesWeb.test.js
HotTestCasesWebWorker.test.js
JavascriptParser.unittest.js
LazySet.unittest.js Fix perf issues with lazy sets 2021-06-17 18:42:39 +00:00
LocalModulesHelpers.unittest.js
ModuleDependencyError.unittest.js
MultiCompiler.test.js close watching when closing compiler 2021-08-30 15:01:24 +02:00
MultiStats.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
MultiWatching.unittest.js
NodeTemplatePlugin.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
NormalModule.unittest.js
NullDependency.unittest.js
PersistentCaching.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
ProfilingPlugin.test.js add test case 2021-11-10 15:03:44 +01:00
ProfilingPlugin.unittest.js
ProgressPlugin.test.js improve test stability 2021-09-08 18:35:00 +02:00
README.md split up integration tests for windows 2021-07-15 16:37:54 +02:00
RawModule.unittest.js
RequestShortener.unittest.js
SemVer.unittest.js
SideEffectsFlagPlugin.unittest.js
SizeFormatHelpers.unittest.js
SortableSet.unittest.js
Stats.test.js keep state of chunk loading during hmr updates 2021-08-16 13:50:43 +02:00
StatsTestCases.basictest.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
Template.unittest.js
TestCases.template.js allow to disable some deprecations 2021-11-05 09:54:51 +01:00
TestCasesAllCombined.longtest.js run test cases for cacheUnaffected 2021-10-05 15:08:20 +02:00
TestCasesCachePack.longtest.js split up integration tests for windows 2021-07-15 16:37:54 +02: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 partially fix test cases 2021-06-24 10:05:37 +02:00
TestCasesNormal.basictest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
TestCasesProdGlobalUsed.test.js assign class property keys to the correct top level symbol 2021-06-21 09:48:14 +02:00
TestCasesProduction.longtest.js split up integration tests for windows 2021-07-15 16:37:54 +02:00
URLAbsoluteSpecifier.unittest.js
Validation.test.js add `asyncChunks: boolean` option to disable creation of async chunks 2021-11-10 15:04:44 +01:00
WasmHashes.unittest.js fix bugs with the new hashing implementation 2021-11-04 09:42:27 +01:00
WatchCacheUnaffectedTestCases.longtest.js optimization.sideEffects is compatible with cacheUnaffected 2021-10-05 16:54:51 +02:00
WatchClose.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
WatchDetection.test.js add test cases 2021-05-19 15:48:00 +02:00
WatchSuspend.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
WatchTestCases.longtest.js run test cases for cacheUnaffected 2021-10-05 15:08:20 +02:00
WatchTestCases.template.js fix duplication due to unsafe cache 2021-10-12 22:46:50 +02:00
WatcherEvents.test.js
WebpackError.unittest.js
checkArrayExpectation.js refactor and add test cases 2021-11-02 18:29:47 +01:00
cleverMerge.unittest.js
compareLocations.unittest.js
compileBooleanMatcher.unittest.js
deterministicGrouping.unittest.js fix some edge cases in deterministicGrouping and add more tests 2021-03-31 16:55:30 +02:00
extractUrlAndGlobal.unittest.js
formatLocation.unittest.js
identifier.unittest.js allow to place runtime outside of the output path 2021-03-16 13:07:58 +01:00
numberHash.unittest.js
objectToMap.unittest.js
setupTestFramework.js fix DEBUG_INFO env var 2021-07-13 10:20:21 +02:00
smartGrouping.unittest.js
target-browserslist.unittest.js

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 API's 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 NodeJS's timeline for dropping older versions of node. Because of this we expect your tests on Travis 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.