Find file History
Latest commit db45446 Jan 18, 2017 @sokra sokra committed on GitHub Merge pull request #3904 from willmendesneto/adding-web-environment-p…
…lugin-test

test(WebEnvironmentPlugin): adding missed test
Permalink
..
Failed to load latest commit information.
benchmarkCases add more benchmark cases Jan 18, 2017
binCases Fix regression with watch cli opt, add tests for this case Jan 17, 2017
browsertest code linting Jan 11, 2017
cases hoist exports declarations too Jan 16, 2017
configCases add tests for harmony with devtools Jan 17, 2017
fixtures No errors plugin deprecate (#3570) Dec 30, 2016
helpers Add tests for CachePlugin (#3840) Jan 8, 2017
hotCases fixes an error where errors are not cleared in cached module Dec 16, 2016
hotPlayground code linting Jan 11, 2017
statsCases remove error for CommonJs/AMD in ESM Jan 15, 2017
watchCases code linting Jan 11, 2017
AmdMainTemplatePlugin.test.js Add maintemplateplugin tests (#3839) Jan 8, 2017
BenchmarkTestCases.benchmark.js interpolate between data points Jan 18, 2017
BinTestCases.test.js Fix regression with watch cli opt, add tests for this case Jan 17, 2017
CachePlugin.test.js Add tests for CachePlugin (#3840) Jan 8, 2017
CaseSensitiveModulesWarning.test.js Convert CaseSensitiveModulesWarning to es2015 Jan 10, 2017
Chunk.test.js refactor(Chunk): upgrade to ES6 (#3694) Jan 4, 2017
Compiler-caching.test.js Update missing should type check calls Jan 2, 2017
Compiler.test.js Update missing should type check calls Jan 2, 2017
ConfigTestCases.test.js feat(test): increase coverage for target: 'webworker' (#3204) Dec 28, 2016
DependenciesBlockVariable.test.js refactor(DependenciesBlockVariable): upgrade to ES6 (#3772) Jan 5, 2017
Errors.test.js Update missing should type check calls Jan 2, 2017
Examples.test.js add test Sep 18, 2016
HotModuleReplacementPlugin.test.js bigger timeout Jan 30, 2016
HotTestCases.test.js fixes an error where errors are not cleared in cached module Dec 16, 2016
HotUpdateChunkTemplate.test.js Add tests for HotUpdateChunkTemplate (#3867) Jan 10, 2017
Integration.test.js Update missing should type check calls Jan 2, 2017
JsonpExportMainTemplatePlugin.test.js Add maintemplateplugin tests (#3839) Jan 8, 2017
JsonpHotUpdateChunkTemplatePlugin.test.js Add hotupdatechunktemplateplugin tests (#3700) Jan 3, 2017
LibraryTemplatePlugin.test.js Add tests for LibraryTemplatePlugin (#3835) Jan 7, 2017
MultiCompiler.test.js Add tests for MultiCompiler (#3802) Jan 7, 2017
MultiStats.test.js linter fixes Jan 11, 2017
MultiWatching.test.js Add tests for MultiCompiler (#3802) Jan 7, 2017
NodeHotUpdateChunkTemplatePlugin.test.js Add hotupdatechunktemplateplugin tests (#3700) Jan 3, 2017
NodeTemplatePlugin.test.js Update missing should type check calls Jan 2, 2017
NodeWatchFileSystem.test.js Run quick NodeWatchFileSystem tests as part of test run (#3863) Jan 10, 2017
Parser.test.js Add async/await support to Parser Oct 31, 2016
README.md chore(test): Add README.me, CONTRIBUTOR update (#3569) Dec 27, 2016
RawModule.test.js remove time test to be safe Jan 6, 2017
RecordIdsPlugin.test.js Test identifier caching Oct 4, 2016
RequireJsStuffPlugin.test.js move rest of requireJsStuffPlugin to es6 Jan 4, 2017
RuleSet.test.js beautify, remove comments, debuggers Dec 22, 2016
SourceMapDevToolModuleOptionsPlugin.test.js Add tests for SourceMapDevToolModuleOptionsPlugin Jan 2, 2017
Stats.test.js add support for multiple different stats objects Jan 11, 2017
Template.test.js update test to fix typo Nov 1, 2016
TestCases.test.js chore(test): Add README.me, CONTRIBUTOR update (#3569) Dec 27, 2016
Validation.test.js Dynamic entry support (#3634) Jan 9, 2017
WarnCaseSensitiveModulesPlugin.test.js Add tests for WarnCaseSensitiveModulesPlugin (#3865) Jan 10, 2017
WatchDetection.test.js feat(perfbudgets): added errorOnHint flag defaulting to false for opt-in Dec 7, 2016
WatchTestCases.test.js Include child compilation hash into parent hash computation (#3744) Jan 6, 2017
WebEnvironmentPlugin.test.js test(WebEnvironmentPlugin): adding missed test Jan 11, 2017
WebWorkerHotUpdateChunkTemplatePlugin.test.js Add tests for WebWorkerHotUpdateChunkTemplatePlugin (#3685) Jan 3, 2017
checkArrayExpectation.js give hint what warnings were expected and which file (#3842) Jan 8, 2017
compareLocations.test.js Add tests for compareLocations Jan 1, 2017
formatLocation.test.js fixes and tests for #3755 (#3862) Jan 10, 2017
mocha.opts chore(test): move mocha command line option to file Oct 26, 2016

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.
    • npm run test or npm t
  • 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.