webpack/test
Tobias Koppers 65915d55aa fix managed items in context hash or timestamp hash 2019-11-06 00:43:43 +01:00
..
__snapshots__ consistency and bugfixes for reexporting json 2019-11-05 10:39:12 +01:00
benchmarkCases readd missing space 2017-12-23 08:11:28 +01:00
cases fix problem with accessing the default named export of json 2019-11-05 10:39:14 +01:00
configCases add support for tree-shaking JSON modules 2019-11-05 10:37:59 +01:00
fixtures fix infinite loop on circular inner graph references 2019-10-07 10:52:35 +02:00
helpers filter DeprecationWarnings from captured stdio 2019-10-09 09:51:34 +02:00
hotCases Deprecate MainTemplate, ChunkTemplate, ModuleTemplate 2019-10-08 23:46:26 +02:00
hotPlayground Use fullhash instead of hash 2018-12-28 14:09:35 +01:00
statsCases avoid writing to same filename in array config 2019-11-05 10:04:01 +01:00
watchCases fix problem with snapshotting managed items 2019-11-05 23:12:02 +01:00
AbstractMethodError.unittest.js #9391 resolve super call discussion 2019-07-15 17:27:59 +03:00
BenchmarkTestCases.benchmark.js Merge tag 'v4.34.0' into next 2019-06-13 10:51:12 +02:00
BuildDependencies.test.js Best effort to capture resolving of file build dependencies 2019-08-20 14:50:14 +02:00
Chunk.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
Compiler-caching.test.js fix test case 2019-11-04 11:42:12 +01:00
Compiler.test.js fix test case 2019-11-04 11:42:12 +01:00
ConfigTestCases.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
ContextModuleFactory.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
Dependencies.lint.js refactor filesystem interfaces 2019-06-11 17:32:58 +02:00
Errors.test.js update test cases and snapshots 2019-11-04 21:11:16 +01:00
Examples.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
HotModuleReplacementPlugin.test.js Merge tag 'v4.39.0' into next 2019-08-05 13:12:09 +02:00
HotTestCases.template.js update eslint and lint-staged 2019-08-06 10:57:37 +02: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 move BasicEvaluatedExpression and JavascriptParserHelpers to javascript directory 2019-10-22 09:27:52 +02: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 update eslint and lint-staged 2019-08-06 10:57:37 +02:00
MultiStats.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
MultiWatching.unittest.js Merge tag 'v4.35.0' into next 2019-06-21 09:15:49 +02:00
NodeTemplatePlugin.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
NormalModule.unittest.js add presentational dependencies which are cheaper, but allow only templating 2019-10-30 07:49:20 +01:00
NullDependency.unittest.js Merge branch 'master' of https://github.com/webpack/webpack into jest 2018-04-27 09:50:48 +02:00
ProfilingPlugin.test.js refactor filesystem interfaces 2019-06-11 17:32:58 +02:00
ProfilingPlugin.unittest.js refactor: the `outputPath` option of `ProfilingPlugin` plugin now accepts only absolute path 2019-08-07 20:36:27 +03:00
ProgressPlugin.test.js hide number of active modules in progress, it's useless 2019-10-10 19:08:51 +02:00
README.md test: modify JavaScript example in README 2019-03-01 19:43:33 +09:00
RawModule.unittest.js refactor Module.source() and Module.getRuntimeRequirements() into Module.codeGeneration 2019-10-08 23:59:48 +02:00
RemoveFiles.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
RequestShortener.unittest.js Add unit tests for RequestShortener 2019-10-03 13:00:43 +03:00
Schemas.lint.js allow pattern in linting 2019-10-19 13:54:09 +02: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 consistency and bugfixes for reexporting json 2019-11-05 10:39:12 +01:00
StatsTestCases.test.js update test cases and snapshots 2019-11-04 21:11:16 +01:00
Template.unittest.js correct spelling mistake, update identifer to identifier 2019-04-12 10:29:41 -06:00
TestCases.template.js test serialization of PureExpressionDependency 2019-09-04 09:08:44 +02:00
TestCasesAllCombined.test.js refactor: `devtool` option 2019-10-18 14:43:21 +02:00
TestCasesCachePack.test.js fix managed items in context hash or timestamp hash 2019-11-06 00:43:43 +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 add moduleIds deterministic for simpler long term caching 2018-09-18 17:49:19 +02: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.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevtoolSourceMap.test.js refactor: `devtool` option 2019-10-18 14:43:21 +02:00
TestCasesHot.test.js Refactor webpack main 2018-12-09 15:32:03 +01:00
TestCasesHotMultiStep.test.js Refactor webpack main 2018-12-09 15:32:03 +01:00
TestCasesMinimizedHashedModules.test.js Refactor module id plugins to be independent 2018-09-03 20:45:44 +02:00
TestCasesMinimizedSourceMap.test.js fix devtool spelling in test 2019-10-19 13:54:39 +02:00
TestCasesNormal.test.js run prettier on existing code 2018-02-25 11:46:17 +01:00
TestCasesProduction.test.js run prettier on existing code 2018-02-25 11:46:17 +01:00
Validation.test.js allow all possible combinations with pattern 2019-10-18 14:58:50 +02:00
WatchDetection.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
WatchSuspend.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
WatchTestCases.test.js fix problem with snapshotting managed items 2019-11-05 23:12:02 +01:00
WatcherEvents.test.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
WebpackError.unittest.js Update unit tests 2019-05-10 09:55:58 +02:00
checkArrayExpectation.js add Dependency.getCondition and conditional ModuleGraphConnections 2019-10-30 07:48:32 +01:00
compareLocations.unittest.js replace Object.assign with object spread 2019-06-19 13:16:05 +02:00
compileBooleanMatcher.unittest.js don't emit and load JS files for chunks without JS modules 2019-05-22 13:12:15 +02:00
formatLocation.unittest.js fix unit test, add handling for line only location 2018-07-15 09:57:36 +02:00
identifier.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02: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 update eslint and lint-staged 2019-08-06 10:57:37 +02: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 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.test.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.test.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 your self. The assumption is that the stats output from your test code is what you expect.

Please follow the approach described bellow:

  • 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 v0.12; 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.