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 8006117bae make status logging 1 char shorter 2 weeks ago
..
__snapshots__ improve tests for different infrastructure logging levels 2 weeks ago
benchmarkCases readd missing space 1 year ago
browsertest Merge branch 'master' of https://github.com/webpack/webpack into jest 1 year ago
cases Prefer the IDL 'nonce' property over .getAttribute('nonce') 1 month ago
configCases add test cases 2 weeks ago
fixtures Added test to account for module parsing failure for binary files 2 months ago
helpers improve tests for different infrastructure logging levels 2 weeks ago
hotCases fix rejection when removing and readding self-accepted module 2 months ago
hotPlayground run prettier on existing code 1 year ago
statsCases improve tests for different infrastructure logging levels 2 weeks ago
watchCases fix prettierignore file and run prettier 6 months ago
AbstractMethodError.unittest.js #9391 resolve super call discussion 1 month ago
BenchmarkTestCases.benchmark.js pretty files 2 months ago
CachePlugin.unittest.js Merge branch 'master' into jest 1 year ago
CaseSensitiveModulesWarning.unittest.js Merge branch 'master' into jest 1 year ago
Chunk.unittest.js Replace sinon by jest's mocks 1 year ago
Compiler-caching.test.js Update prettier to v1.13 1 year ago
Compiler.test.js fix Compiler logging test 2 weeks ago
ConfigTestCases.test.js fix deprecation messages in test 3 weeks ago
ContextModuleFactory.unittest.js run prettier on existing code 1 year ago
DelegatedModule.unittest.js run prettier on existing code 1 year ago
Dependencies.lint.js add lint step to avoid non-npm dependencies in graph 5 months ago
Errors.test.js Added test to account for module parsing failure for binary files 2 months ago
Examples.test.js increase test timeout in Examples.test 1 year ago
HarmonyExportImportedSpecifierDependency.unittest.js fix liniting 6 months ago
HotModuleReplacementPlugin.test.js Apply suggestions from code review 3 weeks ago
HotTestCases.test.js fix liniting 6 months ago
Integration.test.js increase timeouts to address multi-threaded failures on CI 1 year ago
LocalModulesHelpers.unittest.js Merge branch 'profiling-race' into jest 1 year ago
ModuleDependencyError.unittest.js Cleanup error location and origin information 1 year ago
ModuleReason.unittest.js Migrate unit tests to Jest 1 year ago
MultiCompiler.test.js Upgrade jest 1 year ago
MultiStats.unittest.js Merge branch 'profiling-race' into jest 1 year ago
MultiWatching.unittest.js test(watching): add tests 2 months ago
NodeTemplatePlugin.test.js increase test timeout 9 months ago
NormalModule.unittest.js fix liniting 6 months ago
NullDependency.unittest.js Merge branch 'master' of https://github.com/webpack/webpack into jest 1 year ago
Parser.unittest.js HookMap: replace .tap() with .for().tap() 3 weeks ago
ProfilingPlugin.test.js Increase Jest timeout for profiling plugin test 7 months ago
ProfilingPlugin.unittest.js Merge branch 'v4-beta3' into jest 1 year ago
ProgressPlugin.test.js make status logging 1 char shorter 2 weeks ago
README.md test: modify JavaScript example in README 5 months ago
RawModule.unittest.js Merge branch 'profiling-race' into jest 1 year ago
RemoveFiles.test.js exclude watch test cases 9 months ago
RemovedPlugins.unittest.js run prettier on existing code 1 year ago
RuleSet.unittest.js Merge branch 'profiling-race' into jest 1 year ago
Schemas.lint.js fix issues with absolutePath, allOf and anyOf 11 months ago
SideEffectsFlagPlugin.unittest.js run prettier on existing code 1 year ago
SizeFormatHelpers.unittest.js fix liniting 6 months ago
SortableSet.unittest.js Migrate unit tests to Jest 1 year ago
SourceMapDevToolModuleOptionsPlugin.unittest.js fix prettierignore file and run prettier 6 months ago
Stats.test.js run prettier on existing code 1 year ago
Stats.unittest.js fix unit test 4 weeks ago
StatsTestCases.test.js fix Progress and Stats Tests for colors and output 2 weeks ago
Template.unittest.js run prettier on existing code 1 year ago
TestCases.template.js test(TestCases): don't return a value at `describe.skip` and `it` 4 months ago
TestCasesAllCombined.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevelopment.test.js split TestCases into mulitple files for better batching in jest 1 year ago
TestCasesDevtoolCheapEvalModuleSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolCheapEvalSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolCheapInlineSourceMap.test.js migration of new tests and changes after merge of master 1 year 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
TestCasesDevtoolEvalNamedModules.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolEvalSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolInlineSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesDevtoolSourceMap.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesHot.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesHotMultiStep.test.js migration of new tests and changes after merge of master 1 year ago
TestCasesMinimizedHashedModules.test.js migration of new tests and changes after merge of master 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 update snapshot 3 weeks ago
WatchDetection.test.js fix eslint problems 1 year ago
WatchSuspend.test.js test(watching): add integration test 2 months ago
WatchTestCases.test.js fix liniting 6 months ago
WatcherEvents.test.js fix eslint problems 1 year ago
WebEnvironmentPlugin.unittest.js Merge branch 'profiling-race' into jest 1 year ago
WebpackError.unittest.js Migrate unit tests to Jest 1 year ago
WebpackMissingModule.unittest.js Align 'Cannot find module' message with native NodeJS 1 year ago
checkArrayExpectation.js Switch from uglifyjs-webpack-plugin to terser-webpack-plugin 9 months ago
compareLocations.unittest.js Merge branch 'profiling-race' into jest 1 year ago
formatLocation.unittest.js run prettier on existing code 1 year ago
identifier.unittest.js Merge branch 'profiling-race' into jest 1 year ago
objectToMap.unittest.js Migrate unit tests to Jest 1 year ago
setupTestFramework.js Run additional tests to ensure compilation stablility 10 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.