webpack/test
donocode 174fd4e21b Prevent NormalModule contextify from contextifying query parameters
When passing a path as part of a loader query string the contextify
function incorrectly modifies the query string paths, most notably
converting windows separators
2017-08-29 23:50:22 +02:00
..
benchmarkCases fixed linting 2017-03-31 16:00:00 +02:00
binCases remove console.log statement 2017-08-02 20:12:50 +02:00
browsertest fix browsertests 2017-05-25 13:12:34 +02:00
cases also generate a new identifier for interop name 2017-08-10 12:14:31 +02:00
configCases fix invalid generated code with scope hoisting and non-number ids 2017-08-08 13:09:47 +02:00
fixtures chore: remove temp files 2017-05-29 13:49:35 -05:00
helpers improve code coverage 2017-04-13 12:37:30 +02:00
hotCases set compatiblity flag correctly even after incremental build 2017-08-16 14:59:09 +02:00
hotPlayground code linting 2017-01-11 12:29:01 +01:00
statsCases fix stats tests 2017-08-11 16:59:45 +02:00
watchCases Warnings and Errors contribute to hash 2017-08-11 14:35:08 +02:00
AmdMainTemplatePlugin.test.js Update mocked chunk in tests 2017-06-25 16:40:35 +02:00
BenchmarkTestCases.benchmark.js changing async to asyncLib 2017-04-05 21:06:23 +08:00
BinTestCases.test.js fixes incorrect CLI stats output 2017-06-01 15:03:26 +02: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 Use a Set to store modules in a chunk 2017-05-16 11:50:50 +02:00
Compiler-caching.test.js optimize OccurenceOrderPlugin 2017-06-02 01:24:55 +02:00
Compiler.test.js - Fix compiler test as discussed in PR 2017-07-07 09:11:15 -04:00
ConfigTestCases.test.js feat: support config functions with multi-compiler 2017-07-01 13:28:20 -05: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 example scripts and test to allow nested folders 2017-07-27 13:24:56 +02:00
ExternalModule.test.js implementing review suggestions 2017-06-08 13:22:58 -07: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 Disallow Scope Hoisting when using HMR 2017-08-12 11:00:55 +02: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 test: add for namedDefine true and false 2017-05-29 14:06:42 -05: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
ModuleReason.test.js use Set for ModuleReason chunk rewriting 2017-06-14 16:52:51 -04: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 fixes incorrect CLI stats output 2017-06-01 15:03: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 lib/node/NodeMainTemplatePlugin.js #4099 2017-06-19 17:35:05 +09:00
NodeWatchFileSystem.test.js - Edit PR to use normal functions again due to ‘arguments’ not working with arrow functions 2017-07-07 10:52:07 -04:00
NormalModule.test.js Prevent NormalModule contextify from contextifying query parameters 2017-08-29 23:50:22 +02:00
NullDependency.test.js refactor(ES6): NullDependency.test.js 2017-02-17 10:39:13 -08:00
Parser.test.js [Parser] rename `this` in `.call(this)` 2017-07-12 00:12:15 +08:00
README.md fix typo, ‘exapmles’ to ‘examples’ in test/README.md 2017-06-30 15:37:47 -04:00
RawModule.test.js fix RawModule hashing 2017-06-18 10:25:03 -07:00
RecordIdsPlugin.test.js unify makeRelative method used in aggresivesplittingplugin and recordsidsplugin 2017-04-05 23:38:15 +10:00
RequireJsStuffPlugin.test.js fix test case 2017-07-07 11:37:07 +02:00
RuleSet.test.js refactor(ES6): RuleSet.test.js 2017-02-04 17:06:42 +05:30
SortableSet.test.js fix linting/formatting issues 2017-06-21 08:12:22 +10:00
SourceMapDevToolModuleOptionsPlugin.test.js refactor(ES6): SourceMapDevToolModuleOptionsPlugin.test.js 2017-01-18 20:36:05 +05:30
Stats.test.js fixes incorrect CLI stats output 2017-06-01 15:03:26 +02:00
Template.test.js feat(template): cleanup template a bit, add a test for toPath 2017-08-25 14:34:05 -06:00
TestCases.test.js fix($chore): put back TestCases.test.js to original 2017-07-26 13:12:59 +02:00
Validation.test.js fix validation output test 2017-08-11 16:22:46 +02:00
WatchDetection.test.js close watchers correctly when closing watching 2017-03-15 15:50:05 +01:00
WatchTestCases.test.js integrate the delegated module better into the exports flagging process 2017-07-26 10:12:40 +02:00
WatcherEvents.test.js add timeout and code style 2017-05-29 10:52:30 +02: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 Merge pull request #4907 from paraboom/feature/add_request_timeout_configurable 2017-05-28 12:40:09 +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 examples you can refer to if you are just starting out. See the ./helpers folder to find a list of the versions.