Giter Club home page Giter Club logo

tap-webpack-plugin's Introduction

tap-webpack-plugin

travis js-standard-style npm

Run TAP tests on every compile with webpack

This is a plugin for webpack that runs the generated output bundle with Node.js and parses the output as TAP. This works well with webpack --watch as it will run your tests every time a file changes.

Note: You should use the target: 'node' option in your webpack configuration as the generated output will be run with Node.js.

Using a TAP Reporter

By default this plugin will parse the TAP output and report any errors from the TAP output to webpack. If instead you want to pass the TAP output to a TAP reporter, just use the reporter option, like this:

new TapWebpackPlugin({ reporter: 'tap-spec' })

The reporter option specifies the command line for the reporter. It will be run in a shell, so you can pass arguments such as 'tap-spec --no-color'. Output from the TAP reporter will be written directly to the stdout of the webpack process. If the TAP reporter command exits with a non-zero exit code, the plugin will report an error to webpack.

Example

// Your webpack.config.js
var TapWebpackPlugin = require('tap-webpack-plugin')

module.exports = {
  target: 'node',

  entry: ['./test'],

  output: {
    path: 'output',
    filename: 'test.js'
  },

  plugins: [
    new TapWebpackPlugin(),

    // or with a reporter:
    new TapWebpackPlugin({ reporter: 'tap-spec' })
  ]
}
// test.js
var test = require('tape')

test('successful test', function (t) {
  t.equal(1, 1)
  t.end()
})

Example App

You can also generate your main application bundle and a test bundle by exporting an array of configuration objects in the webpack.config.js:

// Your webpack.config.js
var TapWebpackPlugin = require('tap-webpack-plugin')

module.exports = [
  // main bundle configuration
  {
    entry: ['./main'],
    output: {
      path: 'output/dist',
      filename: 'main.js'
    }
  },

  // test bundle configuration
  {
    target: 'node',

    entry: ['./test'],

    output: {
      path: 'output',
      filename: 'test.js'
    },

    plugins: [
      new TapWebpackPlugin()
    ]
  }
];

Then run webpack just like normal and your main bundle will be generated and your tests will be compiled and run, all in one command!

tap-webpack-plugin's People

Contributors

conradz avatar

Watchers

James Cloos avatar jmarceli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.