webpack/test
Ivan Kopeykin ce56e3b61c add NonceRuntimeModule 2022-05-09 21:45:42 +03:00
..
__snapshots__ chore(deps): replace `json-parse-better-errors` to `json-parse-even-better-errors` 2022-04-16 15:01:53 +03:00
benchmarkCases Replace deprecated String.prototype.substr() 2022-03-13 22:54:18 +01:00
cases Merge pull request #15660 from webpack/add-provided-info-tests 2022-04-19 15:06:33 +02:00
configCases add NonceRuntimeModule 2022-05-09 21:45:42 +03:00
fixtures chore: update cSpell globs and fix typos 2021-12-12 16:57:14 -05:00
helpers Replace deprecated String.prototype.substr() 2022-03-13 22:54:18 +01:00
hotCases Merge branch 'main' into fix-12408 2022-04-04 11:24:52 +02:00
hotPlayground improve typings and test them in CI 2020-04-21 09:25:43 +02:00
statsCases hash source types correctly for caching 2022-03-28 11:31:46 +02:00
typesCases refactor, rename, extend, fix, add tests 2021-11-03 12:38:05 +01:00
watchCases fix lint and tests 2022-04-04 13:17:46 +03:00
AbstractMethodError.unittest.js #9391 resolve super call discussion 2019-07-15 17:27:59 +03:00
ArrayHelpers.unittest.js perf: Prevent running regexs over the same strings twice 2021-11-10 01:22:09 +00:00
BannerPlugin.test.js Allow banner to be placed as a footer 2022-04-01 12:29:34 -06:00
BenchmarkTestCases.benchmark.js pretty files 2021-05-11 09:31:46 +02:00
BinaryMiddleware.unittest.js improve BinaryMiddleware test cases 2021-02-03 11:53:03 +01:00
BuildDependencies.longtest.js support node.js builtin modules in esm build dependencies 2022-04-01 14:52:53 +02:00
ChangesAndRemovals.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
Chunk.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
Cli.basictest.js Merge branch 'main' into cspell-globs 2022-01-18 10:40:25 +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 check more files and fix spelling issues 2022-01-18 10:38:06 +01: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 support arrow function in umd 2022-03-18 18:58:50 +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 support context in Dependency 2022-03-25 17:01:48 +03:00
Defaults.unittest.js Merge pull request #15002 from TrickyPi/fix-14927 2022-03-15 11:44:23 +01:00
Errors.test.js chore: update cSpell globs and fix typos 2021-12-12 16:57:14 -05:00
Examples.test.js Replace deprecated String.prototype.substr() 2022-03-13 22:54:18 +01:00
FileSystemInfo.unittest.js allow to configure all hash functions used 2021-09-23 14:55:13 +02:00
HotModuleReplacementPlugin.test.js keep hmr update with output.clean=true based on timestamp 2022-02-26 15:28:33 +03:00
HotTestCases.template.js Replace deprecated String.prototype.substr() 2022-03-13 22:54:18 +01:00
HotTestCasesAsyncNode.test.js Refactor HMR for runtime modules 2018-11-29 16:22:29 +01:00
HotTestCasesNode.test.js Refactor HMR for runtime modules 2018-11-29 16:22:29 +01:00
HotTestCasesWeb.test.js Refactor HMR for runtime modules 2018-11-29 16:22:29 +01:00
HotTestCasesWebWorker.test.js Refactor HMR for runtime modules 2018-11-29 16:22:29 +01:00
JavascriptParser.unittest.js Replace deprecated String.prototype.substr() 2022-03-13 22:54:18 +01:00
LazySet.unittest.js Fix perf issues with lazy sets 2021-06-17 18:42:39 +00:00
LocalModulesHelpers.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
ModuleDependencyError.unittest.js Cleanup error location and origin information 2018-06-04 10:35:46 +02:00
MultiCompiler.test.js close watching when closing compiler 2021-08-30 15:01:24 +02:00
MultiItemCache.unittest.js use forEachBail from enhanced-resolve 2022-01-10 14:00:18 +01:00
MultiStats.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
MultiWatching.unittest.js Merge tag 'v4.35.0' into next 2019-06-21 09:15:49 +02:00
NodeTemplatePlugin.test.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
NormalModule.unittest.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
NullDependency.unittest.js Merge branch 'master' of https://github.com/webpack/webpack into jest 2018-04-27 09:50:48 +02:00
PersistentCaching.test.js add separate webpack warmup step with large timeout 2021-07-15 16:37:54 +02:00
ProfilingPlugin.test.js Pass all attributes of old tap with only overidden fn 2022-02-12 17:18:29 -08:00
ProfilingPlugin.unittest.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
ProgressPlugin.test.js fix ProgressPlugin log 2022-02-23 16:01:47 +03:00
README.md Merge branch 'main' into cspell-globs 2022-01-18 10:40:25 +01:00
RawModule.unittest.js refactor Module.source() and Module.getRuntimeRequirements() into Module.codeGeneration 2019-10-08 23:59:48 +02:00
RequestShortener.unittest.js make RequestShortener simpler, only use relative path 2020-01-15 18:48:37 +01:00
RuntimeTemplate.unittest.js fix RuntimeTemplate 2021-11-29 23:00:37 +03:00
SemVer.unittest.js improve parseRange, add test cases 2022-02-01 10:57:42 +03:00
SideEffectsFlagPlugin.unittest.js replace micromatch with glob-to-regexp for sideEffects flag 2019-05-16 21:54:03 +02:00
SizeFormatHelpers.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
SortableSet.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
Stats.test.js update snapshots 2021-12-29 20:41:04 +08:00
StatsTestCases.basictest.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
Template.unittest.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
TestCases.template.js Replace deprecated String.prototype.substr() 2022-03-13 22:54:18 +01:00
TestCasesAllCombined.longtest.js run test cases for cacheUnaffected 2021-10-05 15:08:20 +02:00
TestCasesCachePack.longtest.js remove big assets case from allowlist 2022-02-15 13:26:56 +01:00
TestCasesDevelopment.test.js refactor: `devtool` option 2019-10-18 14:43:21 +02:00
TestCasesDevtoolCheapSourceMap.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevtoolEval.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevtoolEvalCheapModuleSourceMap.test.js fix source map devtools in test cases 2019-10-18 15:06:58 +02:00
TestCasesDevtoolEvalCheapSourceMap.test.js fix source map devtools in test cases 2019-10-18 15:06:58 +02:00
TestCasesDevtoolEvalDeterministicModuleIds.test.js fix test case naming which causes weird CI failures 2019-12-20 13:54:12 +01:00
TestCasesDevtoolEvalNamedModules.test.js Refactor module id plugins to be independent 2018-09-03 20:45:44 +02:00
TestCasesDevtoolEvalSourceMap.test.js refactor: `devtool` option 2019-10-18 14:43:21 +02:00
TestCasesDevtoolInlineCheapSourceMap.test.js fix source map devtools in test cases 2019-10-18 15:06:58 +02:00
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 Refactor webpack main 2018-12-09 15:32:03 +01:00
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 improve windows absolute path detection 2020-07-03 10:18:41 +02:00
Validation.test.js Merge branch 'main' into cspell-globs 2022-01-18 10:40:25 +01:00
WasmHashes.unittest.js check more files and fix spelling issues 2022-01-18 10:38:06 +01: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 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 ProfilingPlugin for watch scenarios 2022-01-13 01:18:17 -08:00
WatcherEvents.test.js refactor: invoke createFsFromVolume as a function 2020-02-18 20:22:26 +05:30
WebpackError.unittest.js Update unit tests 2019-05-10 09:55:58 +02:00
checkArrayExpectation.js refactor and add test cases 2021-11-02 18:29:47 +01:00
cleverMerge.unittest.js improve handling of non-object values in clever merge 2021-01-06 10:51:44 +01:00
compareLocations.unittest.js replace Object.assign with object spread 2019-06-19 13:16:05 +02:00
compileBooleanMatcher.unittest.js fix #12255 2020-12-22 12:29:08 +01:00
deterministicGrouping.unittest.js fix some edge cases in deterministicGrouping and add more tests 2021-03-31 16:55:30 +02:00
extractUrlAndGlobal.unittest.js feat: throw error for invalid remotes 2021-11-28 18:08:25 +08:00
formatLocation.unittest.js fix unit test, add handling for line only location 2018-07-15 09:57:36 +02:00
identifier.unittest.js fix regexp 2022-02-04 18:12:20 +03:00
nonNumericOnlyHash.unittest.js fit in hex digest 2022-02-02 19:04:31 +03:00
numberHash.unittest.js correct spelling mistake, update identifer to identifier 2019-04-12 10:29:41 -06:00
objectToMap.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
setupTestFramework.js check more files and fix spelling issues 2022-01-18 10:38:06 +01:00
smartGrouping.unittest.js add grouping of assets 2020-09-01 18:16:43 +02:00
target-browserslist.unittest.js fix: more 2020-11-02 18:21:37 +03:00
walkCssTokens.unittest.js add support for `@keyframes`, `animation`, CSS Variables 2021-12-16 20:42:44 +01: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.