webpack/test
Leon Weidauer 152575c2b0 Fix Stats and BinTestCases after adding "Built at"
In order to pass the tests, a similar
test replacement as with the millisecond values
needs to happen.

For the "Built at" stat all dates are replaces with
Thu Jan 01 1970 00:00:00 GMT.

Related to issue #5305

add semicolon
2018-01-29 19:51:49 -08:00
..
benchmarkCases readd missing space 2017-12-23 08:11:28 +01:00
browsertest Refactor chunk graph 2018-01-19 19:21:30 +01:00
cases Deprecate System.import() parser plugin 2018-01-18 11:34:02 +01:00
configCases Leave top level scope when traversing Class nodes 2018-01-25 09:57:47 +01:00
fixtures chore: remove temp files 2017-05-29 13:49:35 -05:00
helpers Improve `PluginEnvironment` helper to support tapable's hooks 2017-12-06 15:12:41 +01:00
hotCases Refactor chunk graph 2018-01-19 19:21:30 +01:00
hotPlayground code linting 2017-01-11 12:29:01 +01:00
statsCases Fix Stats and BinTestCases after adding "Built at" 2018-01-29 14:59:13 -08:00
watchCases Merge branch 'master' into next 2018-01-22 08:48:30 +01:00
BenchmarkTestCases.benchmark.js fix linting errors 2017-11-15 14:08:11 +01:00
CachePlugin.unittest.js Cleanup: don't check plugins for apply function in tests, schema does the check for this. 2017-12-23 09:28:00 +01:00
CaseSensitiveModulesWarning.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
Chunk.unittest.js fix(lib/Chunk): typo in `getNumberOfGroups` return value 2018-01-23 08:54:19 +01:00
Compiler-caching.test.js change "defaultedProduction" to undefined 2018-01-03 16:43:24 +01:00
Compiler.test.js remove bad unit tests 2018-01-03 18:07:40 +01:00
ConfigTestCases.test.js Refactor chunk graph 2018-01-19 19:21:30 +01:00
ContextModuleFactory.unittest.js Merge branch 'master' into next 2017-10-19 21:31:35 +02:00
DelegatedModule.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
DependenciesBlockVariable.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
Errors.test.js Refactor chunk graph 2018-01-19 19:21:30 +01:00
Examples.test.js Refactor chunk graph 2018-01-19 19:21:30 +01:00
ExternalModule.unittest.js add output.globalObject configuration option 2017-12-27 18:46:37 +01:00
HarmonyExportImportedSpecifierDependency.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
HotModuleReplacementPlugin.test.js fix linting errors 2017-11-15 14:08:11 +01:00
HotTestCases.test.js Refactor chunk graph 2018-01-19 19:21:30 +01:00
Integration.test.js Use hooks in test cases 2017-12-21 07:17:27 +01:00
LocalModulesHelpers.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
ModuleDependencyError.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
ModuleReason.unittest.js Don't use deprecate APIs in unit tests 2017-12-22 20:17:53 +01:00
MultiCompiler.test.js Forward run and watchRun calls when using MultiCompiler 2017-12-29 17:25:25 +01:00
MultiStats.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
MultiWatching.unittest.js migrate missed watchClose hook 2017-11-28 16:23:43 +01:00
NodeTemplatePlugin.test.js Enable minimizing in production mode 2017-12-14 00:06:56 +01:00
NodeWatchFileSystem.unittest.js refactor: adjustments per PR comments 2018-01-24 00:55:53 -05:00
NormalModule.unittest.js move source generation into separate module 2018-01-24 11:33:38 +01:00
NullDependency.unittest.js remove outdated unittest 2017-11-19 09:13:26 +01:00
Parser.unittest.js Deprecate System.import() parser plugin 2018-01-18 11:34:02 +01:00
ProfilingPlugin.unittest.js feat(profiling): add profiling plugin 2018-01-18 19:02:27 -08:00
README.md fix filename reference for StatsTestCases.test.js 2017-12-27 23:01:06 -06:00
RawModule.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
RuleSet.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
Schemas.lint.js Merge branch 'master' into next 2017-11-20 20:18:03 +01:00
SizeFormatHelpers.unittest.js Rename SizeFormatHelpers.test.js to SizeFormatHelpers.unittest.js 2017-10-19 19:47:49 +02:00
SortableSet.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
SourceMapDevToolModuleOptionsPlugin.unittest.js Cleanup: don't check plugins for apply function in tests, schema does the check for this. 2017-12-23 09:28:00 +01:00
Stats.test.js `-!` keeps post loader instead of pre loader 2017-12-30 19:34:14 +01:00
Stats.unittest.js Refactor chunk graph 2018-01-19 19:21:30 +01:00
StatsTestCases.test.js Fix Stats and BinTestCases after adding "Built at" 2018-01-29 19:51:49 -08:00
Template.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
TestCases.test.js Use hooks in test cases 2017-12-21 07:17:27 +01:00
Validation.test.js Merge branch 'next' into feature/add-entry-default-value 2017-12-30 18:23:53 -06:00
WatchDetection.test.js Merge pull request #6165 from ooflorent/watch_flag 2017-12-21 09:31:38 +01:00
WatchTestCases.test.js Merge branch 'master' into next 2018-01-22 08:48:30 +01:00
WatcherEvents.test.js Merge pull request #6165 from ooflorent/watch_flag 2017-12-21 09:31:38 +01:00
WebEnvironmentPlugin.unittest.js separate integration and unit tests, use codecov flags 2017-10-19 17:35:20 +02:00
WebpackError.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
WebpackMissingModule.unittest.js Avoid extra semicolons in bundled files. Don't recreate the function on an each iteration. 2018-01-06 05:18:40 +03:00
checkArrayExpectation.js fix linting errors 2017-11-15 14:08:11 +01:00
compareLocations.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
formatLocation.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
identifier.unittest.js fix linting errors 2017-11-15 14:08:11 +01:00
lint-mocha.opts add linting for schemas 2017-11-16 13:15:15 +01:00
mocha.opts Mark Base64 as global in mocha 2017-12-19 15:52:38 +01:00
objectToMap.unittest.js test: add test for objectToMap util 2018-01-24 01:33:26 -05: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 (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 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.