Mocha tests don't run with Webpack and mocha-loader

前端 未结 2 1379
春和景丽
春和景丽 2020-12-07 17:27

Background

I am porting some npm scripts to Webpack loaders to better learn how Webpack works and I’ve got everything working except for my Mocha tests: I have one

2条回答
  •  难免孤独
    2020-12-07 17:39

    I liked JimSkerritt's answer, but couldn't get it to work on my computer for some reason. With the two config files below you can run the app via:

    npm start              // then http://localhost:8080/bundle
    

    and run your tests with:

    npm test              // then http://localhost:8081/webpack-dev-server/test
    

    both servers auto-reload && you can run both simultaneously!

    Config Files

    webpack.config.js

    module.exports = {
        entry: "./index.js",
        output: {
            path: __dirname + "/build",
            filename: "bundle.js"
        },
        module: {
            loaders: [
                { test: /\.css$/, loader: "style!css" }
            ]
        }
    };
    

    package.json

    {
      "name": "2dpointfinder",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "start": "webpack-dev-server --inline",
        "test": "webpack-dev-server 'mocha!./tests/test.js' --output-filename test.js --port 8081"
      },
      "author": "",
      "license": "ISC",
      "dependencies": {
        "css-loader": "^0.19.0",
        "style-loader": "^0.12.4"
      },
      "devDependencies": {
        "mocha": "^2.3.3",
        "mocha-loader": "^0.7.1",
        "should": "^7.1.0"
      }
    }
    

提交回复
热议问题