Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 8, 2019. It is now read-only.
/docsPublic archive
John Leith edited this pageFeb 14, 2017 ·18 revisions

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 tests usually take longer. You can test DOM access.
  • with node.js: You cannot test DOM access, but testing is usually faster.

In-browser testing

mocha-loader

The mocha-loader executes your code with the mocha framework. If you run the code it'll show the results in the web page.

Tip: when using! in the bash command line, you must escape it by prepending a\

webpack'mocha!./test.js' testBundle.js# index.html is a HTML page which loads testBundle.jsopen index.html

webpack-dev-server

The webpack-dev-server will automatically create a HTML page which loads the script. It also re-executes the tests when files have changed.

webpack-dev-server'mocha-loader!./test.js' --hot --inline --output-filename test.jsopen http://localhost:8080/test

Tip: Use--hot and it'll only execute tests which have changed or have changed dependencies.

karma and webpack

You can use webpack with karma. Add"webpack" as preprocessor to your karma config.

node.js testing

CommonJs only

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/*

Compile and test

If you use webpack-specific features it may not be 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 optiontarget: "node"). Then use a node.js testing framework to run the bundle.

webpack test.js /tmp/testBundle.js --target nodemocha /tmp/testBundle.js

Hint: You can use thenull-loader for stylesheets instead of thestyle-loader!css-loader.style-loader doesn't work in node.js as it requires a DOM.

To make debugging tests easier, you can add source map support usingnode-source-map-support:

webpack test.js /tmp/testBundle.js --target nodemocha --require source-map-support/register /tmp/testBundle.js

Make sure to configure thedevtool option to output the source map.

enhanced-require

TODO

webpack 👍

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp