webpack/test
Tobias Koppers aed6ab1d89 improve renaming of variables in concatenated modules
more detailed tracking of conflicted references
to avoid renaming variables when possible

fixes #10168
2019-12-23 21:54:57 +01:00
..
__snapshots__ Merge tag 'v4.41.4' 2019-12-19 13:55:43 +01:00
benchmarkCases readd missing space 2017-12-23 08:11:28 +01:00
cases fix parsing of requires in requires 2019-12-23 17:43:41 +01:00
configCases improve renaming of variables in concatenated modules 2019-12-23 21:54:57 +01:00
fixtures fix infinite loop on circular inner graph references 2019-10-07 10:52:35 +02:00
helpers add deprecation testing for config test cases 2019-12-17 17:18:52 +01:00
hotCases use parser state instead of module to store harmony/dynamic exports state 2019-12-07 01:04:38 +01:00
hotPlayground Use fullhash instead of hash 2018-12-28 14:09:35 +01:00
statsCases Refactor how exportsType work 2019-12-06 11:13:08 +01:00
watchCases fix test case 2019-12-07 01:35:46 +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
ChangesAndRemovals.test.js use separate directory for test 2019-11-15 20:31:22 +01:00
Chunk.unittest.js update eslint and lint-staged 2019-08-06 10:57:37 +02:00
Compiler-caching.test.js fix race in test case 2019-11-29 13:01:04 +01:00
Compiler.test.js fix test case 2019-11-04 11:42:12 +01:00
ConfigTestCases.test.js add deprecation testing for config test cases 2019-12-17 17:18:52 +01: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 fix Errors for require.parent/main.require 2019-12-06 11:13:13 +01:00
Examples.test.js fix error for Example test cases 2019-11-10 21:05:31 +01: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 Introduce a Parser base class to improve Parser types 2019-11-30 01:36:28 +01: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 upgrade webpack-sources 2019-11-12 08:59:08 +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 add finishAssets to ProgressPlugin 2019-11-12 16:11:06 +01: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
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 Refactor how exportsType work 2019-12-06 11:13:08 +01:00
StatsTestCases.test.js upgrade webpack-sources 2019-11-12 08:59:08 +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 test caching for concatenated modules 2019-12-16 21:06:29 +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.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 refactor: merge generators in asset modules 2019-11-26 15:42:37 +01: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.