How to compile and run `tap` tests with `webpack`?

I can't find any right config to run tap (or tape) tests in the browser while compiling with webpack + babel.

Here is a dead simple example:

import test from 'tap';

test('random test', function(t){
    t.ok(true, 'great!');
});

Trying to compile the above generate following errors as nodejs modules aren't polyfilled:

ERROR in ./~/tap/lib/test.js
Module not found: Error: Cannot resolve module 'child_process' in /Users/arnaud/projects/chrome-tap/node_modules/tap/lib
 @ ./~/tap/lib/test.js 30:12-36

ERROR in ./~/tap/lib/test.js
Module not found: Error: Cannot resolve module 'module' in /Users/arnaud/projects/chrome-tap/node_modules/tap/lib
 @ ./~/tap/lib/test.js 33:13-30

ERROR in ./~/tap/lib/test.js
Module not found: Error: Cannot resolve module 'fs' in /Users/arnaud/projects/chrome-tap/node_modules/tap/lib
 @ ./~/tap/lib/test.js 34:9-22

Or with tape:

ERROR in ./~/tape/lib/default_stream.js
Module not found: Error: Cannot resolve module 'fs' in /Users/arnaud/projects/chrome-tap/node_modules/tape/lib
 @ ./~/tape/lib/default_stream.js 2:9-22

I can compile and run tape tests using browserify + babel but I’d be interested in using webpack instead.

Alternatively, is there any pure ES6 (ie non nodejs) TAP library?

Answers


I use karma to run tape tests via webpack. This blog post was really helpful in helping me get it set up -- there are karma addons for tap, webpack and for istanbul (if you want coverage). Basically you tell karma you're using webpack, add your webpack config to your karma config, and make the webpack entry point a module that requires all of your spec modules.

I had to add

node: {
    fs: "empty"
}

to my testing webpack config to prevent a reference error somewhere along the way.


Need Your Help

Inversion count value of inversion in merge sort

c++ c count mergesort inversion

The following below is a code to count inversions in a an array.I have a doubt in this part:

Saving HTML5 canvas image then sending via e-mail with PHP

javascript php ajax canvas html5-canvas

So I have a form on my website (www.100danish.com) which includes an HTML5 canvas element for the user to draw a picture along with their form.