|
|
6 years ago | |
|---|---|---|
| .. | ||
| basic | 6 years ago | |
| chunk-name-dashes | 6 years ago | |
| circular-dependencies | 6 years ago | |
| disabled | 6 years ago | |
| etp-content-hash | 6 years ago | |
| etp-path-join | 6 years ago | |
| hwp-custom-template | 6 years ago | |
| hwp-integrity-attributes | 6 years ago | |
| hwp-output-parent-dir | 6 years ago | |
| hwp-public-path | 6 years ago | |
| hwp-subdirectories | 6 years ago | |
| mini-css-extract-plugin | 6 years ago | |
| multiple-common-chunks | 6 years ago | |
| mutually-dependent-chunks | 6 years ago | |
| no-error-invalid-config | 6 years ago | |
| no-warn-filename | 6 years ago | |
| plugin-order-sri-uglify | 6 years ago | |
| plugin-order-uglify-sri | 6 years ago | |
| warn-checksum | 6 years ago | |
| warn-hot-reload | 6 years ago | |
| webpack4-contenthash | 6 years ago | |
| webpack4-contenthash-issue-83 | 6 years ago | |
| README.md | 6 years ago | |
README.md
Examples / Test Cases
This folder contains a number of test cases which can also serve as usage examples.
Each folder contains a bog-standard Webpack project and an optional
file test.js for more intricate tests.
Adding a Test Case
In order to create a new test case, it's probably best to start by
copying an existing example. Simply copy the directory to a new name,
then edit README.md, webpack.config.js and optionally test.js.
You can run all examples using yarn mocha, or a specific example
using yarn mocha --grep 'titlehere'.
The simplest kind of example is an end-to-end test. This is just a
vanilla Webpack project: a webpack.config.js and any files that you
want to bundle. To pass a test, such an example should provide an
index.html and use console.log somewhere to output ok when
loaded in a web browser. To fail, it should output error. (If it
doesn't output either ok or error it will time out.)
However, end-to-end tests are also the slowest performing and aren't
well suited to examining the Webpack build output. For your case it
might be better to add a file test.js with contents as follows:
-
For examining only webpack build output, export a function
checkwith one argumentstats:module.exports.check = function check(stats) { }The function should examine stats and throw in case of error. It can also return a promise.
-
For examining Webpack build output with a web server serving the output spun up, add another argument
url:module.exports.check = function check(stats, url) { } -
If you want a Puppeteer browser instance, add yet another argument
browser. Your tests will be skipped on Node versions < 6.4.module.exports.check = function check(stats, url, browser) { } -
You can export a function
skipif you want to skip the test conditionally. The function should return a truthy value when the test should be skipped.
Reference
Any sub-directories of this directory are processed as follows:
Each sub-directory should contain a file called webpack.config.js
which exports a standard Webpack configuration as default.
It can optionally contain a file called test.js with the following
exports:
-
check: a function that will be invoked after Webpack compilation finishes successfully. It should return a Promise that resolves if the test succeeds and rejects if it fails. Synchronous tests can also return a non-promise value or throw.The function can receive between zero and three arguments. The first argument, if needed, is the
statsobject that the Webpack compilation returns. The second argument, if needed, is the URL of a web server hosting the results of the Webpack compilation. The third argument, if needed, is a Puppeteer browser instance.If the function accepts all three arguments, it will only run on Node >= 6.4 since that is the minimum requirement of Puppeteer. Therefore, don't specify the third argument if you don't need it so that your test can run on Node 4.
The web server will only be spun up if the function accepts two arguments or more. Therefore, don't specify the second argument if you don't need it so that your test runs faster.
If the
checkexport is not present (or the wholetest.jsfile is missing), a default check will be run. The default check ensures that there were no compilation errors, then loadsindex.htmlwith Puppeteer and waits for it to log eitherokorerrorto the console. -
skip: a function that, if present, will be invoked without arguments. Its return code determines whether the test should be skipped (truthy return value means to skip the test, falsey means to run it.)