You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Tobias Koppers 457055cbcc fix test case 1 week ago
..
__snapshots__ make module info comment more pretty 1 week ago
benchmarkCases readd missing space 2 years ago
cases Refactor how exportsType work 1 week ago
configCases Refactor how exportsType work 1 week ago
fixtures fix infinite loop on circular inner graph references 2 months ago
helpers filter DeprecationWarnings from captured stdio 2 months ago
hotCases use parser state instead of module to store harmony/dynamic exports state 1 week ago
hotPlayground Use fullhash instead of hash 11 months ago
statsCases Refactor how exportsType work 1 week ago
watchCases fix test case 1 week ago
AbstractMethodError.unittest.js #9391 resolve super call discussion 5 months ago
BenchmarkTestCases.benchmark.js Merge tag 'v4.34.0' into next 6 months ago
BuildDependencies.test.js Best effort to capture resolving of file build dependencies 3 months ago
ChangesAndRemovals.test.js use separate directory for test 4 weeks ago
Chunk.unittest.js update eslint and lint-staged 4 months ago
Compiler-caching.test.js fix race in test case 2 weeks ago
Compiler.test.js fix test case 1 month ago
ConfigTestCases.test.js update eslint and lint-staged 4 months ago
ContextModuleFactory.unittest.js update eslint and lint-staged 4 months ago
Dependencies.lint.js refactor filesystem interfaces 6 months ago
Errors.test.js fix Errors for require.parent/main.require 1 week ago
Examples.test.js fix error for Example test cases 1 month ago
HotModuleReplacementPlugin.test.js Merge tag 'v4.39.0' into next 4 months ago
HotTestCases.template.js update eslint and lint-staged 4 months ago
HotTestCasesAsyncNode.test.js Refactor HMR for runtime modules 1 year ago
HotTestCasesNode.test.js Refactor HMR for runtime modules 1 year ago
HotTestCasesWeb.test.js Refactor HMR for runtime modules 1 year ago
HotTestCasesWebWorker.test.js Refactor HMR for runtime modules 1 year ago
JavascriptParser.unittest.js Introduce a Parser base class to improve Parser types 2 weeks ago
LocalModulesHelpers.unittest.js update eslint and lint-staged 4 months ago
ModuleDependencyError.unittest.js Cleanup error location and origin information 1 year ago
MultiCompiler.test.js update eslint and lint-staged 4 months ago
MultiStats.test.js update eslint and lint-staged 4 months ago
MultiWatching.unittest.js Merge tag 'v4.35.0' into next 5 months ago
NodeTemplatePlugin.test.js update eslint and lint-staged 4 months ago
NormalModule.unittest.js upgrade webpack-sources 1 month ago
NullDependency.unittest.js Merge branch 'master' of https://github.com/webpack/webpack into jest 1 year ago
ProfilingPlugin.test.js refactor filesystem interfaces 6 months ago
ProfilingPlugin.unittest.js refactor: the `outputPath` option of `ProfilingPlugin` plugin now accepts only absolute path 4 months ago
ProgressPlugin.test.js add finishAssets to ProgressPlugin 1 month ago
README.md test: modify JavaScript example in README 9 months ago
RawModule.unittest.js refactor Module.source() and Module.getRuntimeRequirements() into Module.codeGeneration 2 months ago
RequestShortener.unittest.js Add unit tests for RequestShortener 2 months ago
Schemas.lint.js allow pattern in linting 1 month ago
SideEffectsFlagPlugin.unittest.js replace micromatch with glob-to-regexp for sideEffects flag 7 months ago
SizeFormatHelpers.unittest.js update eslint and lint-staged 4 months ago
SortableSet.unittest.js update eslint and lint-staged 4 months ago
Stats.test.js Refactor how exportsType work 1 week ago
StatsTestCases.test.js upgrade webpack-sources 1 month ago
Template.unittest.js correct spelling mistake, update identifer to identifier 8 months ago
TestCases.template.js test serialization of PureExpressionDependency 3 months ago
TestCasesAllCombined.test.js refactor: `devtool` option 1 month ago
TestCasesCachePack.test.js fix managed items in context hash or timestamp hash 1 month ago
TestCasesDevelopment.test.js refactor: `devtool` option 1 month ago
TestCasesDevtoolCheapSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolEval.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolEvalCheapModuleSourceMap.test.js fix source map devtools in test cases 1 month ago
TestCasesDevtoolEvalCheapSourceMap.test.js fix source map devtools in test cases 1 month ago
TestCasesDevtoolEvalDeterministicModuleIds.test.js add moduleIds deterministic for simpler long term caching 1 year ago
TestCasesDevtoolEvalNamedModules.test.js Refactor module id plugins to be independent 1 year ago
TestCasesDevtoolEvalSourceMap.test.js refactor: `devtool` option 1 month ago
TestCasesDevtoolInlineCheapSourceMap.test.js fix source map devtools in test cases 1 month ago
TestCasesDevtoolInlineSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolSourceMap.test.js refactor: `devtool` option 1 month ago
TestCasesHot.test.js Refactor webpack main 1 year ago
TestCasesHotMultiStep.test.js Refactor webpack main 1 year ago
TestCasesMinimizedHashedModules.test.js Refactor module id plugins to be independent 1 year ago
TestCasesMinimizedSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesNormal.test.js run prettier on existing code 1 year ago
TestCasesProduction.test.js run prettier on existing code 1 year ago
Validation.test.js refactor: merge generators in asset modules 2 weeks ago
WatchDetection.test.js update eslint and lint-staged 4 months ago
WatchSuspend.test.js update eslint and lint-staged 4 months ago
WatchTestCases.test.js fix problem with snapshotting managed items 1 month ago
WatcherEvents.test.js update eslint and lint-staged 4 months ago
WebpackError.unittest.js Update unit tests 7 months ago
checkArrayExpectation.js add Dependency.getCondition and conditional ModuleGraphConnections 1 month ago
compareLocations.unittest.js replace Object.assign with object spread 5 months ago
compileBooleanMatcher.unittest.js don't emit and load JS files for chunks without JS modules 6 months ago
formatLocation.unittest.js fix unit test, add handling for line only location 1 year ago
identifier.unittest.js update eslint and lint-staged 4 months ago
numberHash.unittest.js correct spelling mistake, update identifer to identifier 8 months ago
objectToMap.unittest.js update eslint and lint-staged 4 months ago
setupTestFramework.js update eslint and lint-staged 4 months ago

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.