mocha-loader

2018-10-11 admin

mocha-loader是什么

什么是mocha-loader,Mocha loader for webpack

mocha-loader使用教程帮助文档

npm node deps test chat

<div align=“center”>

Mocha Loader

Allows Mocha tests to be loaded and run via webpack

</div>

Install

npm i -D mocha-loader

Usage

CLI

webpack --module-bind 'mocha-loader!./test'

Require

import test from 'mocha-loader!./test'

Config (recommended)

import test from './test'

webpack.config.js

module.exports = {
  entry: './entry.js',
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
  module: {
    rules: [
      {
        test: /test\.js$/,
        use: 'mocha-loader',
        exclude: /node_modules/
      }
    ]
  }
}

Options

None

Examples

Basic

module.js

module.exports = true

test.js

describe('Test', () => {
  it('should succeed', (done) => {
    setTimeout(done, 1000)
  })

  it('should fail', () => {
    setTimeout(() => {
      throw new Error('Failed')
    }, 1000)
  })

  it('should randomly fail', () => {
    if (require('./module')) {
      throw new Error('Randomly failed')
    }
  })
})

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-42419.html

文章标题:mocha-loader

回到顶部