-
Notifications
You must be signed in to change notification settings - Fork 128
testing
There are two ways to test web applications:
- In-browsers: You get a more realistic test, but you need some more complex infrastructure and the test usually take longer. You can test DOM access.
- with node.js: You cannot test DOM access, but testing is usually faster.
The mocha-loader executes your code with the mocha framework. If you run the code it'll show the results in the web page.
webpack "mocha!./test.js" testBundle.js
# index.html is a HTML page which loads testBundle.js
open index.html
The webpack-dev-server do automatically create a HTML page which loads the script. It also reexecutes the tests when files have changed.
webpack-dev-server "mocha!./test.js" --output-file test.js
open http://localhost:8080/webpack-dev-server/test
Hint: Use --hot
and it'll only execute tests which have changed or have changed dependencies.
You can use webpack with karma. Add "webpack"
as preprocessor to your karma config.
If you write your web app only in CommonJs and don't use loaders or other webpack-specific features, you can test it in node.js. Just use a node.js testing framework, i. e. mocha.
mocha test/*
If you use webpack-specific features it may not possible to run the code with node.js. webpack allows to configure a target system: i. e. you can compile code so that it can run in node.js (configuration option target: "node"
). Than use a node.js testing framework to run the bundle.
webpack test.js /tmp/testBundle.js --target node
mocha /tmp/testBundle.js
TODO
webpack 👍