webpack/test
tsangint 1d95e524b3 Update Jest URL 2018-08-09 01:27:40 +08:00
..
__snapshots__ Merge pull request #7628 from reduckted/dllreferenceplugin-graceful-json-parse-failure 2018-07-23 10:37:47 +02:00
benchmarkCases readd missing space 2017-12-23 08:11:28 +01:00
browsertest Merge branch 'master' of https://github.com/webpack/webpack into jest 2018-04-10 23:36:20 +02:00
cases fix #7778 2018-08-03 09:20:23 +02:00
configCases fix #7829 2018-08-03 11:09:26 +02:00
fixtures Handle module.require, require.main.require, and module.parent.require 2018-07-19 13:41:58 -07:00
helpers update watch test cases for new jest integration 2018-08-02 16:58:41 +02:00
hotCases Improve error reporting while recompilation in HotCases 2018-08-03 08:10:53 +02:00
hotPlayground run prettier on existing code 2018-02-25 11:46:17 +01:00
statsCases Merge pull request #7628 from reduckted/dllreferenceplugin-graceful-json-parse-failure 2018-07-23 10:37:47 +02:00
watchCases upgrade jest 2018-07-10 16:02:02 +02:00
BenchmarkTestCases.benchmark.js Update prettier to v1.13 2018-05-29 16:14:16 +02:00
CachePlugin.unittest.js Merge branch 'master' into jest 2018-02-25 12:00:09 +01:00
CaseSensitiveModulesWarning.unittest.js Merge branch 'master' into jest 2018-02-25 12:00:09 +01:00
Chunk.unittest.js Replace sinon by jest's mocks 2018-05-07 15:26:09 +02:00
Compiler-caching.test.js Update prettier to v1.13 2018-05-29 16:14:16 +02:00
Compiler.test.js fix order of occurrence order plugin 2018-07-13 16:15:01 +02:00
ConfigTestCases.test.js improve way of adding exported tests to test tree 2018-08-02 14:45:50 +02:00
ContextModuleFactory.unittest.js run prettier on existing code 2018-02-25 11:46:17 +01:00
DelegatedModule.unittest.js run prettier on existing code 2018-02-25 11:46:17 +01:00
Errors.test.js Handle module.require, require.main.require, and module.parent.require 2018-07-19 13:41:58 -07:00
Examples.test.js increase test timeout in Examples.test 2018-04-27 12:01:45 +02:00
ExternalModule.unittest.js Align 'Cannot find module' message with native NodeJS 2018-05-15 09:24:16 +03:00
HarmonyExportImportedSpecifierDependency.unittest.js convert to integration test 2018-04-07 18:12:43 -07:00
HotModuleReplacementPlugin.test.js fix order of occurrence order plugin 2018-07-13 16:15:01 +02:00
HotTestCases.test.js Improve error reporting while recompilation in HotCases 2018-08-03 08:10:53 +02:00
Integration.test.js increase timeouts to address multi-threaded failures on CI 2018-04-18 21:17:12 +02:00
LocalModulesHelpers.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
ModuleDependencyError.unittest.js Cleanup error location and origin information 2018-06-04 10:35:46 +02:00
ModuleReason.unittest.js run prettier on existing code 2018-02-25 02:00:20 +01:00
MultiCompiler.test.js Upgrade jest 2018-05-24 12:52:48 +02:00
MultiStats.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
MultiWatching.unittest.js Replace sinon by jest's mocks 2018-05-07 15:26:09 +02:00
NodeTemplatePlugin.test.js run prettier on existing code 2018-02-25 11:46:17 +01:00
NormalModule.unittest.js Add matchResource feature (for loaders) 2018-06-01 15:37:17 +02:00
NullDependency.unittest.js Merge branch 'master' of https://github.com/webpack/webpack into jest 2018-04-27 09:50:48 +02:00
Parser.unittest.js Change Parser unit test to be compatible with node < 10 2018-06-06 21:30:53 +02:00
ProfilingPlugin.unittest.js Merge branch 'v4-beta3' into jest 2018-02-25 11:41:05 +01:00
ProgressPlugin.test.js Add a test 2018-05-15 07:19:53 -04:00
README.md Update Jest URL 2018-08-09 01:27:40 +08:00
RawModule.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
RemovedPlugins.unittest.js fix unit test 2018-04-12 09:23:02 +02:00
RuleSet.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
Schemas.lint.js run prettier across the codebase 2018-04-10 22:52:22 +02:00
SideEffectsFlagPlugin.unittest.js run prettier on existing code 2018-02-25 11:46:17 +01:00
SizeFormatHelpers.unittest.js Merge branch 'master' of https://github.com/webpack/webpack into jest 2018-04-18 19:54:24 +02:00
SortableSet.unittest.js Migrate unit tests to Jest 2018-01-24 17:29:57 +01:00
SourceMapDevToolModuleOptionsPlugin.unittest.js fix prettier issue after merge 2018-04-27 10:00:33 +02:00
Stats.test.js run prettier on existing code 2018-02-25 11:46:17 +01:00
Stats.unittest.js Cleanup error location and origin information 2018-06-04 10:35:46 +02:00
StatsTestCases.test.js fix order of occurrence order plugin 2018-07-13 16:15:01 +02:00
Template.unittest.js run prettier on existing code 2018-02-25 11:46:17 +01:00
TestCases.template.js improve way of adding exported tests to test tree 2018-08-02 14:45:50 +02:00
TestCasesAllCombined.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevelopment.test.js split TestCases into mulitple files for better batching in jest 2018-02-25 01:16:11 +01:00
TestCasesDevtoolCheapEvalModuleSourceMap.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevtoolCheapEvalSourceMap.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevtoolCheapInlineSourceMap.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +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
TestCasesDevtoolEvalNamedModules.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesDevtoolEvalSourceMap.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +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 migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesHot.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesHotMultiStep.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesMinimizedHashedModules.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +02:00
TestCasesMinimizedSourceMap.test.js migration of new tests and changes after merge of master 2018-04-11 20:31:28 +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 serve property in webpack configuration 2018-05-15 16:12:54 +02:00
WatchDetection.test.js fix eslint problems 2018-04-12 00:11:04 +02:00
WatchTestCases.test.js update watch test cases for new jest integration 2018-08-02 16:58:41 +02:00
WatcherEvents.test.js fix eslint problems 2018-04-12 00:11:04 +02:00
WebEnvironmentPlugin.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
WebpackError.unittest.js Migrate unit tests to Jest 2018-01-24 17:29:57 +01:00
WebpackMissingModule.unittest.js Align 'Cannot find module' message with native NodeJS 2018-05-15 09:24:16 +03:00
checkArrayExpectation.js run prettier on existing code 2018-02-25 11:46:17 +01:00
compareLocations.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
formatLocation.unittest.js run prettier on existing code 2018-02-25 11:46:17 +01:00
identifier.unittest.js Merge branch 'profiling-race' into jest 2018-03-07 21:56:06 +01:00
objectToMap.unittest.js Migrate unit tests to Jest 2018-01-24 17:29:57 +01:00
setupTestFramework.js run prettier on existing code 2018-02-25 11:46:17 +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 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);

** dont's 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.