webpack/test
Rafael De Leon 6752a9cb7e Enable use of sourceMapFilename: "[file].map?[contenthash]" as a useful workaround for this bug in chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=508270 2017-07-12 07:56:37 +02:00
..
benchmarkCases fixed linting 2017-03-31 16:00:00 +02:00
binCases fixed linting 2017-03-31 16:00:00 +02:00
browsertest remove labeled modules leftovers 2017-02-25 01:10:38 +11:00
cases fix variable injection in require.ensure 2017-05-25 06:32:11 +02:00
configCases Enable use of sourceMapFilename: "[file].map?[contenthash]" as a useful workaround for this bug in chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=508270 2017-07-12 07:56:37 +02:00
fixtures No errors plugin deprecate (#3570) 2016-12-30 09:52:37 +01:00
helpers improve code coverage 2017-04-13 12:37:30 +02:00
hotCases fixes an error where errors are not cleared in cached module 2016-12-16 19:12:47 +01:00
hotPlayground code linting 2017-01-11 12:29:01 +01:00
statsCases Use Promise only when chunk load is triggered 2017-05-24 14:58:23 +02:00
watchCases Merge pull request #4471 from SteveMieskoski/increase-coverage-for-AutomaticPrefetchPlugin 2017-03-18 15:32:05 +01:00
AmdMainTemplatePlugin.test.js fix tests 2017-02-20 20:29:32 +11:00
BenchmarkTestCases.benchmark.js changing async to asyncLib 2017-04-05 21:06:23 +08:00
BinTestCases.test.js rename variable for future compatibility 2017-04-09 13:49:27 +10:00
CachePlugin.test.js refactor(ES6): CachePlugin.test.js 2017-01-17 20:01:48 +05:30
CaseSensitiveModulesWarning.test.js cleaned up arrow functions and enabled strict mode 2017-01-18 23:58:57 +05:30
Chunk.test.js two small changes 2017-03-30 18:10:41 -04:00
Compiler-caching.test.js Revert "make flanky test stable" 2017-04-06 13:52:55 +02:00
Compiler.test.js fixup spacing 2017-02-28 18:26:49 +01:00
ConfigTestCases.test.js removed changes to original banner plugin test 2017-04-11 18:51:14 -04:00
ContextDependencyTemplateAsId.test.js fix double semicolon 2017-04-05 12:45:07 +02:00
ContextReplacementPlugin.test.js fix paths for windows 2017-02-20 13:42:30 -06:00
DependenciesBlockVariable.test.js fix require call 2017-02-28 15:28:44 +01:00
Errors.test.js refacotr(ES6): Errors.test.js 2017-01-18 15:59:38 +05:30
Examples.test.js refactor(ES6): Examples.test.js 2017-01-18 16:03:28 +05:30
ExternalModule.test.js more tests for external modules 2017-02-19 13:44:42 +11:00
HarmonyExportImportedSpecifierDependency.test.js Add test case. 2017-02-25 13:25:12 +01:00
HarmonyModulesHelpers.test.js refactor(HarmonyModulesHelpers): upgrade to ES6 2017-02-22 22:33:56 +11:00
HotModuleReplacementPlugin.test.js refactor(ES6): HotModuleReplacementPlugin.test.js 2017-01-18 16:08:06 +05:30
HotTestCases.test.js Merge pull request #4017 from shubheksha/refactor-test-HotTestCases 2017-02-28 12:56:20 +01:00
HotUpdateChunkTemplate.test.js refactor(ES6): HotUpdateChunkTemplate.test.js 2017-01-18 16:19:03 +05:30
Integration.test.js refactor(ES6): Integration.test.js 2017-01-18 16:23:19 +05:30
JsonpExportMainTemplatePlugin.test.js add use strict 2017-02-09 23:39:59 +01:00
JsonpHotUpdateChunkTemplatePlugin.test.js refactor(ES6): JsonpHotUpdateChunkTemplatePlugin.test.js 2017-01-18 16:33:28 +05:30
LibraryTemplatePlugin.test.js Add tests for LibraryTemplatePlugin (#3835) 2017-01-07 14:27:22 -06:00
LocalModulesHelpers.test.js refactor(LocalModulesHelpers): using export instead static methods in a class 2017-02-23 19:23:17 +11:00
ModuleDependencyError.test.js refactor(ES6): ModuleDependencyError.test.js 2017-02-17 13:00:47 -08:00
MultiCompiler.test.js Merge pull request #4169 from kball/IS4156-multicompiler-watch-options 2017-04-04 18:21:13 +02:00
MultiStats.test.js Merge branch 'master' into refactor-MultiStats 2017-04-05 12:56:26 +02:00
MultiWatching.test.js emit watch-close event when watcher closes 2017-03-06 14:32:34 +11:00
NodeHotUpdateChunkTemplatePlugin.test.js refactor(ES6): NodeHotUpdateChunkTemplatePlugin.test.js 2017-01-18 19:16:31 +05:30
NodeTemplatePlugin.test.js refactor(ES6): NodeTemplatePlugin.test.js 2017-01-18 19:23:20 +05:30
NodeWatchFileSystem.test.js fix test cases for prototype-less timestamps object 2017-02-23 23:18:26 +01:00
NormalModule.test.js added test for DependenciesBlock#hasDependencies 2017-04-04 02:07:14 +03:00
NullDependency.test.js refactor(ES6): NullDependency.test.js 2017-02-17 10:39:13 -08:00
Parser.test.js Merge pull request #4700 from webpack/bug/future-var-declaration 2017-04-13 15:23:48 +02:00
README.md elaborate on running tests and use yarn instead of npm 2017-01-21 10:46:31 -07:00
RawModule.test.js reformatting 2017-02-09 23:38:39 +01:00
RecordIdsPlugin.test.js unify makeRelative method used in aggresivesplittingplugin and recordsidsplugin 2017-04-05 23:38:15 +10:00
RequireJsStuffPlugin.test.js Merge pull request #4044 from shubheksha/refactor-test-RequireJsStuffPlugin 2017-01-27 02:08:40 -06:00
RuleSet.test.js refactor(ES6): RuleSet.test.js 2017-02-04 17:06:42 +05:30
SourceMapDevToolModuleOptionsPlugin.test.js refactor(ES6): SourceMapDevToolModuleOptionsPlugin.test.js 2017-01-18 20:36:05 +05:30
Stats.test.js fixup function to be able to use arguments 2017-04-09 00:20:40 +10:00
Template.test.js refactor(ES6): Template.test.js 2017-01-18 20:47:10 +05:30
TestCases.test.js add NamedChunksPlugin to "all case" test-cases 2017-03-26 20:30:52 +11:00
UglifyJsPlugin.test.js Updates UglifyJs to 2.8.x to accept additional compress options 2017-03-04 18:31:39 -08:00
Validation.test.js Suggest course of action 2017-03-24 22:29:55 +01:00
WatchDetection.test.js close watchers correctly when closing watching 2017-03-15 15:50:05 +01:00
WatchTestCases.test.js run watch cases with more timeout 2017-03-16 08:43:22 +01:00
WatcherEvents.test.js emit watch-close event when watcher closes 2017-03-06 14:32:34 +11:00
WebEnvironmentPlugin.test.js add use strict 2017-02-09 23:35:55 +01:00
WebWorkerChunkTemplatePlugin.test.js added tests for WebWorkerChunkTemplatePlugin 2017-01-17 18:49:15 +05:30
WebWorkerHotUpdateChunkTemplatePlugin.test.js refactor(ES6): WebWorkerHotUpdateChunkTemplatePlugin.test.js 2017-01-18 21:22:37 +05:30
WebWorkerMainTemplatePlugin.test.js Use Promise only when chunk load is triggered 2017-05-24 14:58:23 +02:00
WebpackError.test.js Create base WebpackError class with inspect method. 2017-04-03 10:42:53 -04:00
WebpackMissingModule.test.js test(WebpackMissingModule): adding unit tests 2017-03-10 23:41:34 +11:00
checkArrayExpectation.js Refactor CheckArrayExpectation to ES6 2017-04-06 16:17:43 +08:00
compareLocations.test.js fix: remove unreasonable comparelocation logic and update test cases 2017-01-24 18:47:55 +08:00
formatLocation.test.js refactor(ES6): formatLocation.test.js 2017-01-18 16:05:43 +05:30
identifier.test.js make paths for records agnostic of OS 2017-04-07 23:37:42 +10:00
mocha.opts Revert "chore(test): skip failure for global var in macaddress" 2017-01-18 13:23:40 +01:00
removeAndDo.test.js refactor(removeAndDo): upgrading to ES6 2017-03-12 13:57:24 +11: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

  • Clone repo

  • install and link deps

    • yarn install && yarn link && yarn link webpack
    • yarn test
  • To run an individual suite: (recommended during development for easier isolated diffs)

Example: $(npm bin)/mocha --grep ConfigTestCases

Test suite overview

We use MochaJS for our tests. For more information on Mocha 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 (Stats.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 the following happens:

  • Checks for expected.txt file containing expected results.
  • If the expected.txt doesn't match what is output, then an actual.txt stats output file will be created and the test will fail. (A typical workflow for stats cases is to fail the test and copy the results from actual.txt to expected.txt.)
  • If the actual output matches expected.txt, the tests passes and you are free to submit that PR with pride!!!

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 exapmles you can refer to if you are just starting out. See the ./helpers folder to find a list of the versions.