GithubHelp home page GithubHelp logo

zinserjan / mocha-webpack Goto Github PK

View Code? Open in Web Editor NEW
484.0 484.0 75.0 2.23 MB

mocha test runner with integrated webpack precompiler

Home Page: http://zinserjan.github.io/mocha-webpack/

License: MIT License

JavaScript 99.75% CoffeeScript 0.12% CSS 0.06% TypeScript 0.07%

mocha-webpack's People

Contributors

alexmeah avatar astorije avatar azhang avatar darrinholst avatar ezze avatar flui avatar greenkeeper[bot] avatar jleft avatar modosc avatar nickradford avatar pkuczynski avatar randycoulman avatar terrenceljones avatar thiagoa avatar vikhyat avatar yachaka avatar zinserjan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mocha-webpack's Issues

CSS and SCSS problems

I've spent far too long looking at this problem myself, and need some help.

In my tests I am importing an angular component that imports some CSS files from node_modules, and some SCSS from the same directory.

Like so:

import 'font-awesome/css/font-awesome.css';
import './main.scss';

If I run mocha-webpack I get this:

SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:404:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/beep/dev/test/.tmp/mocha-webpack/f881bff69e3f75b90d6
1f9ea811cbdc0/external "font-awesome/css/font-awesome.css":1:1)

If I comment out the node_modules css and try it with the SCSS file I get:

/home/beep/dev/test/node_modules/style-loader/addStyles.js:31
        if (typeof options.singleton === "undefined") options.singleton = isOldIE();
^
TypeError: Cannot read property 'toLowerCase' of undefined
    a t/home/beep/dev/test/node_modules/style-loader/addStyles.js:14:1
    at /home/beep/dev/test/node_modules/style-loader/addStyles.js:9:1
    at module.exports (/home/beep/dev/test/node_modules/style-loader/addStyles.js:31:
1)
    at Object.<anonymous> (/home/beep/dev/test/src/client/main/main.scss?caf6:7:1)

My webpack config is:

{
  output: {
    devtoolModuleFilenameTemplate: '[absolute-resource-path]',
    devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
  },
  entry: {},
  target: 'node',
  externals: [nodeExternals()],
  devtool: 'cheap-module-source-map',
  module: {
      loaders: [
        { test: /\.tpl.html$/, loader: 'ngtemplate?relativeTo=' + (path.resolve(__dirname, './src/client')) + '/!html-loader' },
        { test: /\.css$/, loader: 'style!css' },
        { test: /\.scss$/, loader: 'style-loader!css-loader!autoprefixer-loader!sass-loader' },
        { test: /\.js$/, exclude: /(node_modules)/, loader: 'ng-annotate!babel' },
        { test: /\.(jpe|jpg|woff|woff2|eot|ttf|svg)(\?.*$|$)/, loader: 'file?name=fonts/[name].[ext]' }
      ]
    }
}

I guess I just need some way of forcing webpack to ignore html, css, scss, etc. But I am unsure on how to do that.

Mocha output style is lost

when using mocha-webpack, I found the original mocha test output color is lost:

image

which should be like below:

image

I know it's not a big deal, but all the passing color just make people happy : )

Trouble with __dirname

My tests have to read (and optionally write) some files relative to the test's .js file. For getting the correct path I used __dirname before switching to mocha-webpack. Now I'm having a hard time making __dirname work. I tried the node.__dirname options in the webpack config, but with no success. Do you have any idea on how to solve this? Mocha-webpack works great otherwise, great job!

Use with VS Code

I'd like to use Visual Studio Code's debugger with mocha-webpack tests. VS Code can debug mocha tests, but you have to tell it to use "node_modules/mocha/bin/_mocha" and not "mocha".

For mocha-webpack I tried both "node_modules/mocha-webpack/bin/mocha-webpack" and "node_modules/mocha-webpack/bin/_mocha" and it would run the tests but not attach the debugger. Not sure what is going wrong. Possibly related to #19

Option to extend mocha.opts file

Is there an --extend option to extend an existing mocha.opts file.
Looks terrible to have two files that are mostly duplicated.

--extend mocha.opts

--watch is not working great with glob

If I use a conditional glob, it's not working well:

mocha-webpack --webpack-config webpack.test.config.js --timeout 50000 --require source-map-support/register --inline-diffs --watch  "@(tests|web_modules)/**/*.test.js" 
  [MAIN APP] Testing rootReducer
    ✓ should exist
  1 passing (3s)
  0 passing (0ms)

But if I remove the conditional case @(tests|web_modules) => web_modules, it works !

mocha-webpack --webpack-config webpack.test.config.js --timeout 50000 --require source-map-support/register --inline-diffs --watch  "web_modules/**/*.test.js" 
  [ADMIN APP] Testing projects actions
    GET /projects calls
      ✓ should leverage a request action on fetch request
      ✓ should leverage a success action on fetch success
      ✓ should leverage a failure action on fetch failure
[...]
  48 passing (6s)
  5 pending

Some glob patterns don't work, sucking up CPU

I have two top-level directories in a repository, called src and lib. Both have tests. I want to run mocha-webpack with --watch to run those tests.

I have a mocha-webpack.opts file like this:

--colors
--include test/setup.js
--reporter spec
--webpack-config webpack/webpack.config.babel.js
{src,lib}/**/__test__/*.spec.js

and in package.json:

    "mocha": "NODE_ENV=test babel-node ./node_modules/.bin/mocha-webpack",
    "mocha:watch": "npm run mocha -- --watch",

(babel-node is used as I write my webpack config in ES6. It's not the cause of this issue, as I've verified the same thing occurs with an ES5 config.)

npm run mocha works fine. Sadly when i run npm run mocha:watch this results in a massive slowdown, some tests don't run, file changes aren't spotted, my fan spins up, dogs howl, etc.

The cause seems to be the leading braces in the file spec in mocha-webpack.opts.

src/**/__test__/*.spec.js  # ok
{src}/**/__test__/*.spec.js  # bad

Some debugging suggests the braces cause some part of the code to hunt through the entire repository, since the constant parent of the file spec glob is .. Naturally, this includes node_modules, and so everything grinds to a halt.

I'm working around this using a simple entry point file, based on your prepareEntry.js code. It's a little grubby but it works:

const isWatch = process.argv.indexOf('--watch') > -1;

// This gets replaced by webpack with the updated files on rebuild
const __webpackManifest__ = []; // eslint-disable-line no-underscore-dangle

const isInManifest = path => __webpackManifest__.indexOf(path) >= 0;
const isAlways = () => true;

// // no, you really can't optimise this, as webpack needs to statically analyse the code.
const contexts = [
    require.context('../src', true, /__test__\/.*\.spec\.js/),
    require.context('../lib', true, /__test__\/.*\.spec\.js/),
];

const run = (testsContext) => {
    testsContext.keys()
    .filter(isWatch ? isInManifest : isAlways)
    .forEach(testsContext);
};

contexts.forEach(run);

I'm not sure if there's a better solution. Perhaps mocha-webpack could accept multiple filespecs and prepareEntry.js could output something like the above?

Cannot integrate with jsdom

when i try to add jsdom with the basic boilerplate in the test-setup.js file

global.document = require('jsdom').jsdom('<body><div id="root"></div></body>');
global.window = document.defaultView;
global.navigator = window.navigator;

and i run npm test it trows some errors

WARNING in ./~/jsdom/lib/jsdom/utils.js
Module not found: Error: Cannot resolve module 'canvas' in /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom
resolve module canvas in /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom
  looking for modules in /Users/wardrakus/projects/react-boilerplate/client
    /Users/wardrakus/projects/react-boilerplate/client/canvas doesn't exist (module as directory)
    resolve 'file' canvas in /Users/wardrakus/projects/react-boilerplate/client
      resolve file
        /Users/wardrakus/projects/react-boilerplate/client/canvas doesn't exist
        /Users/wardrakus/projects/react-boilerplate/client/canvas.js doesn't exist
  looking for modules in /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules
    /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules/canvas doesn't exist (module as directory)
    resolve 'file' canvas in /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules
      resolve file
        /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules/canvas doesn't exist
        /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules/canvas.js doesn't exist
  looking for modules in /Users/wardrakus/projects/react-boilerplate/node_modules
    /Users/wardrakus/projects/react-boilerplate/node_modules/canvas doesn't exist (module as directory)
    resolve 'file' canvas in /Users/wardrakus/projects/react-boilerplate/node_modules
      resolve file
        /Users/wardrakus/projects/react-boilerplate/node_modules/canvas doesn't exist
        /Users/wardrakus/projects/react-boilerplate/node_modules/canvas.js doesn't exist
  looking for modules in /Users/wardrakus/projects/node_modules
    /Users/wardrakus/projects/node_modules/canvas doesn't exist (module as directory)
    resolve 'file' canvas in /Users/wardrakus/projects/node_modules
      resolve file
        /Users/wardrakus/projects/node_modules/canvas doesn't exist
        /Users/wardrakus/projects/node_modules/canvas.js doesn't exist
[/Users/wardrakus/projects/react-boilerplate/client/canvas]
[/Users/wardrakus/projects/react-boilerplate/client/canvas]
[/Users/wardrakus/projects/react-boilerplate/client/canvas.js]
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules/canvas]
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules/canvas]
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/node_modules/canvas.js]
[/Users/wardrakus/projects/react-boilerplate/node_modules/canvas]
[/Users/wardrakus/projects/react-boilerplate/node_modules/canvas]
[/Users/wardrakus/projects/react-boilerplate/node_modules/canvas.js]
[/Users/wardrakus/projects/node_modules/canvas]
[/Users/wardrakus/projects/node_modules/canvas]
[/Users/wardrakus/projects/node_modules/canvas.js]
 @ ./~/jsdom/lib/jsdom/utils.js 343:19-36

WARNING in ./~/jsdom/lib/jsdom/living/xmlhttprequest.js
Critical dependencies:
19:23-30 require function is used in a way in which dependencies cannot be statically extracted
 @ ./~/jsdom/lib/jsdom/living/xmlhttprequest.js 19:23-30
WARNING in ./~/jsdom/lib/jsdom/living/window/History.idl                                                                                                              [12/1355]
Module parse failed: /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/window/History.idl The keyword 'enum' is reserved (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: The keyword 'enum' is reserved (1:0)
    at Parser.pp.raise (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:918:13)
    at Parser.pp.parseIdent (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:669:203)
    at Parser.pp.parseExprAtom (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:283:21)
    at Parser.pp.parseExprSubscripts (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:225:19)
    at Parser.pp.parseMaybeUnary (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:204:17)
    at Parser.pp.parseExprOps (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:151:19)
    at Parser.pp.parseMaybeConditional (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:133:19)
    at Parser.pp.parseMaybeAssign (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:110:19)
    at Parser.pp.parseExpression (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:86:19)
    at Parser.pp.parseStatement (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:1750:23)
    at Parser.pp.parseTopLevel (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:1645:21)
    at Parser.parse (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:1613:17)
    at Object.parse (/Users/wardrakus/projects/react-boilerplate/node_modules/acorn/dist/acorn.js:880:44)
    at Parser.parse (/Users/wardrakus/projects/react-boilerplate/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (/Users/wardrakus/projects/react-boilerplate/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (/Users/wardrakus/projects/react-boilerplate/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/Users/wardrakus/projects/react-boilerplate/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /Users/wardrakus/projects/react-boilerplate/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (/Users/wardrakus/projects/react-boilerplate/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at /Users/wardrakus/projects/react-boilerplate/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)
 @ ./~/jsdom/lib/jsdom/living ^\.\/.*$
ERROR in ./~/jsdom/lib/jsdom/living/generated/DOMPointReadOnly.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../nodes/DOMPointReadOnly-impl.js in /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated
resolve file
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/nodes/DOMPointReadOnly-impl.js doesn't exist
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/nodes/DOMPointReadOnly-impl.js.js doesn't exist
resolve directory
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/nodes/DOMPointReadOnly-impl.js doesn't exist (directory default file)
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/nodes/DOMPointReadOnly-impl.js/package.json doesn't exist (directory description file)
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/nodes/DOMPointReadOnly-impl.js]
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/nodes/DOMPointReadOnly-impl.js.js]
 @ ./~/jsdom/lib/jsdom/living/generated/DOMPointReadOnly.js 135:13-57

ERROR in ./~/jsdom/lib/jsdom/living/generated/ScrollIntoViewOptions.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./ScrollOptions in /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated
resolve file
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated/ScrollOptions doesn't exist
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated/ScrollOptions.js doesn't exist
resolve directory
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated/ScrollOptions doesn't exist (directory default file)
  /Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated/ScrollOptions/package.json doesn't exist (directory description file)
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated/ScrollOptions]
[/Users/wardrakus/projects/react-boilerplate/node_modules/jsdom/lib/jsdom/living/generated/ScrollOptions.js]
 @ ./~/jsdom/lib/jsdom/living/generated/ScrollIntoViewOptions.js 6:22-48

how do you run tests that needs the actual DOM?, it is posible to add jsdom to this setup?

thanks

Pass CLI options to webpack

As far as I know, there are some webpack cli options like --progress which cannot be set in a config file (maybe I'm wrong). If that's the case, it would be pretty nice if there were a way to pass these options to the underlying webpack. --progress is the one I'd really like, but making it more flexible could be good too. What do you think, is it possible to do?

Issue with style-loader

I have an issue with the style-loader when trying to run mocha-webpack in one of my projects:

/home/jan/workspace/repos/special_stuff/node_modules/style-loader/addStyles.js:31
    if (typeof options.singleton === "undefined") options.singleton = isOldIE();
^
ReferenceError: window is not defined
    at /home/jan/workspace/repos/special_stuff/node_modules/style-loader/addStyles.js:14:1
    at /home/jan/workspace/repos/special_stuff/node_modules/style-loader/addStyles.js:9:1
    at module.exports (/home/jan/workspace/repos/special_stuff/node_modules/style-loader/addStyles.js:31:1)
    at Object.<anonymous> (/home/jan/workspace/repos/special_stuff/modules/shared/styles/components/Menu.scss?22f3:7:1)

Here is my test config:

var nodeExternals = require('webpack-node-externals');

module.exports = {
    module: {
        loaders: [
            { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader' },
            { test: /\.scss$/, loaders: ['style', 'css', 'sass'] },
            { test: /\.css$/, loaders: ['style', 'css'] },
            {
                test: /\.(jpe?g|png|gif|svg)$/i,
                loaders: [
                    'file?hash=sha512&digest=hex&name=[hash].[ext]',
                    'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
                ]
            },
            { test: /\.(otf|eot|svg|ttf|woff2?)/i, loader: require.resolve('url-loader') }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    output: {
        // sourcemap support for IntelliJ/Webstorm
        devtoolModuleFilenameTemplate: '[absolute-resource-path]',
        devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
    },
    target: 'node', // in order to ignore built-in modules like path, fs, etc.
    externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
    devtool: "cheap-module-source-map" // faster than 'source-map'
};

Any clue on why I'm getting this error? It's working fine in a different project where I am using the exact same configuration..

Any help would be highly appreciated.

How to avoid jQuery throwing `Error: jQuery requires a window with a document`?

I just ported my tests to run with mocha-webpack, but I'm running into issues with tests that include files with jQuery as a dependency. I have jsdom creating a fake DOM for my tests, but this doesn't seem to work when compiled by Webpack:

  const jsdom = require('jsdom')
  const document = jsdom.jsdom(html, options)
  const window = document.defaultView
  global.document = document
  global.window = window
  window.console = global.console

  // Normally I can access `window` here, but not anymore.

I've also included the following in my config file:

  plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            ...
        }),
       ...
   ]

But that doesn't seem to work either. Is there a recommended way to get jsdom to work with mocha-webpack or somehow provide a window object for jQuery not to error out?

Debug in idea

I found the readme shows how to craete sourcemap file for idea, but it does not shows how to debug it.

Debug tests

  1. Clean the .tmp folder, you can just delete the folder
  2. Run mocha-webpack --growl, then you will see it create an '{uuid}-entry.js' file and a folder name with the same uuid
  3. Create a mocha run/debug configuration, in the Test Directory just choose the folder with an uuid name, more info you can find here
  4. Just click run or debug button

screenshot 1

screenshot 2

Compile tests into memory by default

I think it would be nice to compile the tests into memory rather than into the disk.
That way, no more .tmp directory, which is quite ugly.

What do you think ?
At least, maybe use the filesystem default tmp directory ?

--compilers js:babel-core/register cause argv parse error

I found adding option --compilers js:babel-core/register causes mocha-webpack always return help output, like:

$ ./node_modules/mocha-webpack/bin/mocha-webpack -R spec --require test/setup.js --compilers js:babel-core/register --webpack-config ./test/webpack.config.test.js ./test/index.js
Advanced options:
  --async-only, -A  force all tests to take a callback (async) or return a
                    promise                                            [boolean]
  --recursive       include sub directories                            [boolean]
  --bail, -b        bail after first test failure     [boolean] [default: false]
  --glob            only run files matching <pattern> (only valid for directory
                    entry)                                              [string]
  --grep, -g        only run tests matching <pattern>                   [string]
  --fgrep, -f       only run tests containing <string>                  [string]
  --invert, -i      inverts --grep and --fgrep matches[boolean] [default: false]
  --require, -r     require the given module                            [string]
  --include         include the given module into test bundle           [string]
  --slow, -s        "slow" test threshold in milliseconds       [default: 75 ms]
  --timeout, -t     set testneekeydeMBP:react-webpack-spa neekey$ 

--watch does not re-run tests

When I run with the --watch flag, my tests run and pass. Then if I change a test case (or merely re-save the file without editing), I get 0 passing (1ms). Before I dig deeper, are there any likely causes of this?

From package.json:

{
  "scripts": {
    "test": "mocha-webpack --webpack-config webpack.config.test.js --recursive client/test/",
    "test:watch": "npm test -- --watch",
  }
}

webstorm source maps

Hello! very nice project!

We use webstorm and read hire https://www.npmjs.com/package/mocha-webpack#sourcemaps we can use source maps for this. We done all as written and get source map file into ./.tmp/mocha-webpack folder but anyway get errors like this into output

  1. RemoteModel Zemla.save() "before all" hook:
    TypeError: Cannot read property '_isLoaded' of undefined
    at Function.get (.tmp/mocha-webpack/RemoteModel.Test.js:852:23)
    at Context. (.tmp/mocha-webpack/RemoteModel.Test.js:366:42)
    at boundThen (.tmp/mocha-webpack/RemoteModel.Test.js:3343:26)
    at Context. (.tmp/mocha-webpack/RemoteModel.Test.js:365:25)

can we get the stack trace point to out real files from src folder? Thanks!

Getting "Invariant Violation: webpackConfig must be a plain object"

I have basically tried to set up my project in line with configuration in the thread #19

But I'm getting this error when I try to run mocha-webpack

File [/Users/steve/project/webpack.test.config.js] ignored, nothing could be mapped
/Users/steve/project/node_modules/invariant/invariant.js:49
    throw error;
    ^

Invariant Violation: webpackConfig must be a plain object
    at invariant (/Users/steve/project/node_modules/invariant/invariant.js:42:15)
    at createCompiler (/Users/steve/Project/node_modules/mocha-webpack/lib/webpack/createCompiler.js:32:27)
    at build (/Users/steve/project/node_modules/mocha-webpack/lib/webpack/build.js:19:47)
    at run (/Users/steve/projects/node_modules/mocha-webpack/lib/cli/runner.js:49:23)
    at /Users/steve/project/node_modules/mocha-webpack/lib/cli/index.js:59:21
    at /Users/steve/project/node_modules/mocha-webpack/lib/cli/prepareWebpack.js:188:11
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Function.Module.runMain (module.js:577:11)
    at Function.runMain (/Users/steve/.node-spawn-wrap-5982-492946983996/node:40:10)
    at Object.<anonymous> (/Users/steve/project/node_modules/nyc/bin/wrap.js:22:4)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at Object.<anonymous> (/Users/steve/.node-spawn-wrap-5982-492946983996/node:140:8)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
    at run (bootstrap_node.js:352:7)
    at startup (bootstrap_node.js:144:9)
    at bootstrap_node.js:467:3

in webpack.config.test.js

var webpack         = require('webpack');
var path            = require('path');
var nodeExternals   = require('webpack-node-externals');

// Define the environment
var env             = 'test';

// ==============================
//  Paths
// ==============================
var rootPath        = path.resolve( __dirname );
var nodeModulesPath = path.resolve( __dirname, 'node_modules');
var buildPath       = path.resolve( __dirname, 'build');
var srcPath         = path.resolve( __dirname, 'src' );
var serverPath      = path.resolve( srcPath, 'server' );
var libPath         = path.resolve( srcPath, 'lib' );
var modelPath       = path.resolve( srcPath, 'models' );
var routePath       = path.resolve( srcPath, 'routes' );

// ==============================
//  CommonJS wrap all Externals
// ==============================
var extNodeModules  = nodeExternals();

// ==============================
//  Plugins
// ==============================
var plugins = [

  new webpack.DefinePlugin({
    'process.env': {
      ENV: JSON.stringify(env),
      NODE_ENV: JSON.stringify(env)
    }
  }),

  new webpack.NoErrorsPlugin()
];

// ==============================
//  Pre-loaders
// ==============================
var preLoaders = [
  {
    test: /\.js$/i,
    loaders: ['babel'],
    exclude: [
      nodeModulesPath       // skip anything in node_modules
    ]
  },
  {
    test: /\.js$/i,
    include: srcPath,
    exclude: [
      nodeModulesPath,      // skip anything in node_modules
      /\.spec\.js$/         // skip instrumentaion on *.spec.js files
    ],
    loader: 'istanbul-instrumenter'
  }
];

// ==============================
//  Loaders
// ==============================
var loaders = [
  { test: /\.json$/i, loader: 'json' }
];

module.exports = {
  resolve: {
    alias:{
      root: rootPath,
      server: serverPath,
      src: srcPath,
      lib: libPath,
      models: modelPath,
      routes: routePath,
      node: nodeModulesPath
    },
    extensions: ['', '.js', '.json' ]
  },
  target: 'node',
  externals: [ extNodeModules ],
  plugins: plugins,
  module: {
    preLoaders: preLoaders,
    loaders: loaders
  }
};

in package.json

  "scripts": {
     "test": "NODE_ENV=test BABEL_ENV=test nyc mocha-webpack",
  },
  "nyc": {
    "reporter": [
      "lcov",
      "text-summary"
    ],
    "exclude": [
      "node_modules",
      "test"
    ]
  },
  "devDependencies": {
    "babel-core": "^6.13.2",
    "babel-loader": "^6.2.5",
    "babel-plugin-istanbul": "^2.0.1",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-stage-0": "^6.5.0",
    "istanbul-instrumenter-loader": "^1.0.0",
    "json-loader": "^0.5.3",
    "mocha": "^3.0.2",
    "mocha-webpack": "^0.7.0",
    "nyc": "^8.3.1",
    "webpack": "^1.13.2"
  }

in mocha.options.json

--require babel-core/register
--colors
--reporter spec
--ui bdd
--webpack-config webpack.test.config.js
src/**/*.spec.js

in babel.rc

{
  "presets": ["es2015", "stage-0"],
  "env": {
    "test": {
      "plugins": ["istanbul"]
    }
  }
}

--watch crashing on errors

Thanks for a great tool – excited to be able to hot-reload my test code.

Any insights on how to prevent --watch from crashing, and exiting, when errors are introduced into a test file? Do I have a configuration option set incorrectly in webpack?

Pass `--debug` or `--inspect` flags?

Is there a way to pass the new --inspect or legacy --debug / --debug-brk flags to mocha-webpack?

I'd like to be able to debug my tests using the new Chrome Dev Tools integration.

Thanks for mocha-webpack- loving it!

Support multiple entry files/patterns/directories

At the moment mocha-webpack supports only a single argument (file, directory or pattern).

We should support multiple entries to support the following cases:

  • code is organized into multiple src folders (e.g. src & lib) #27
  • code coverage reports for whole codebase, not just with files that are referenced in test files #19
  • allow execution of individual test files #8

Examples:

# run all test files in src & lib folder
mocha-webpack src/**/__test__/*.spec.js lib/**/__test__/*.spec.js

# run only a few tests
mocha-webpack test/es6/Browser.spec.js test/es6/ErrorHandler.spec.js src/templates/TemplateComponent.spec.js

Support for webpack 2

Hey guys.
Is there plans to support webpack 2 with this module? Or will a separate project be needed?

include babel-polyfill

Hi,

I need to include babel polyfill to use generator functions inside my generated test code. It is not possible to specify it in the webpack entry since this project overrides the provided entry config. How would you achieve the same here? maybe we can enable it using a command line arg

Devtool eval

First, thanks a lot for creating this.

I spent some time tonight trying to get it running in webpack 2. Without watch it worked out of the box, with, it crashed. I don't know the details but it seems as if webpack has changed how evaled modules are handled as the built files contained:

With devtool eval:

eval("[...] __webpackManifest__ = ["file1", "file2"] [...]")

Which obviously does not work. But, by escaping in https://github.com/zinserjan/mocha-webpack/blob/master/src/webpack/InjectChangedFilesPlugin.js#L88

I.e. const changedFiles = JSON.stringify(this.hotFiles.concat(this.failedFiles)).replace(/"/g, '\\"');

Watch mode works flawlessly.

can run 1 file but not directory

Hi, I have just setup mocha-webpack.
When I specify a single file in the mocha-webpack.opts and run npm test, it runs the tests in the file but when I specify the parent directory it says 0 tests. Below are the relevant files

`const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
var nodeExternals = require('webpack-node-externals');

const config = {
// Gives you sourcemaps without slowing down rebundling
output: {
// sourcemap support for IntelliJ/Webstorm
devtoolModuleFilenameTemplate: '[absolute-resource-path]',
devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
},
target: 'node', // in order to ignore built-in modules like path, fs, etc.
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
devtool: "cheap-module-source-map", // faster than 'source-map',
module: {
noParse: [],
loaders: [
{ test: /.jsx?$/, exclude: /(node_modules|bower_components)/, loader: 'babel-loader' },
{ test: /.css$/, loader: 'style-loader!css-loader' },
{ test: /.eot(?v=\d+.\d+.\d+)?$/, loader: 'file' },
// { test: /.ttf(?v=\d+.\d+.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{ test: /.svg(?v=\d+.\d+.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' },
{ test: /.png$/, loader: 'url-loader', query: { mimetype: 'image/png' } },
{ test: /.jpg$/, loader: 'url-loader', query: { mimetype: 'image/jpg' } },
{ test: /.gif$/, loader: 'url-loader', query: { mimetype: 'image/gif' } },
{ test: /.scss$/, loaders: ['style', 'css', 'sass'] }
]
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.NoErrorsPlugin()
],
sassLoader: {
includePaths: [path.resolve(__dirname, './sass')]
}
};

module.exports = config;`

mocha-webpack.opts

--colors
--webpack-config app/webpack.config-testing.js
--recursive
// -- no tests run
./app/tests/components
// -- 4 tests run
./app/tests/components/ChapterTester.js

I'm just running
"test": "mocha-webpack ",

I feel like I'm really close, please let me know what you think
Thanks,
Raif

sorry formatting doesn't seem to be working :(

Finds files, but says "0 passing" tests

Finally got my mocha-webpack setup to parse my es6 etc.

My package.json contains:

"scripts": {
    "test": "mocha-webpack --webpack-config webpack.config.test.js \"./tests/js/**/*.test.js\""
}

But when I run it, I get:

$ npm run test

> [email protected] test /Users/jordan/Code/kiddom/teacher-web
> mocha-webpack --webpack-config webpack.config.test.js "./tests/js/**/*.test.js"




  0 passing (0ms)

I've tried specifying a single file but get the same output:

$ $(npm bin)/mocha-webpack --webpack-config webpack.config.test.js tests/js/components/content_type_select.test.js 



  0 passing (0ms)

Lastly, if I ask it to run a missing test, now i see that the file is missing.

$ $(npm bin)/mocha-webpack --webpack-config webpack.config.test.js tests/js/components/conteect.test.js 
/Users/jordan/Code/kiddom/teacher-web/node_modules/mocha-webpack/lib/cli/index.js:56
    throw err;
    ^

Error: File/Directory not found: tests/js/components/conteect.test.js
    at /Users/jordan/Code/kiddom/teacher-web/node_modules/mocha-webpack/lib/cli/prepareWebpack.js:203:10
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)
    at Function.Module.runMain (module.js:459:11)
    at startup (node.js:138:18)
    at node.js:974:3

This makes me think I'm not doing something to "register" my tests, somehow? Here are the contents of tests/js/components/content_type_select.test.js:

import React from 'react';
import { shallow, mount } from 'enzyme';
import {expect} from 'chai';
import sinon from 'sinon/pkg/sinon';

import ContentTypeSelect from 'content_type_select';

describe('<ContentTypeSelect />', () => {
  describe('event handlers', () => {
    it('fires onChange', () => {
      const onChange = sinon.spy();
      const wrapper = mount(<ContentTypeSelect onChange={onChange}/>);
      wrapper.find('.js-button').simulate('click');
      expect(onChange).to.have.property('callCount', 1)
    })

  })
});

There isn't a debug or verbose flag in --help. I'd love to see if it's seeing & disregarding my files/tests, or what...

Any ideas?

Weird error messages on failing tests

In my current setup I get some weird errors... any idea?

TypeError: (0 , _chai.expect)(...).to.be is not a function
      at Context.that.should (.tmp/mocha-webpack/1125819f4470d55ab4c318bd8d350078/1125819f4470d55ab4c318bd8d350078-output.js:140:3

Should I add source maps or not, ie. --require source-map-support/register?
I'm using babel 6.18 with webpack 2.1 beta 25.

Does support ES6?

I got following error with React import:

(function (exports, require, module, __filename, __dirname) { import React from 'react';
                                                                                                    ^^^^ ^^
SyntaxError: Unexpected token import
...

Clean test output - getting rid of default node error msg

Do you know of any way to disable the regular node error output!?
Could I disable process.on('error') or something to mute it?

Operator: code
    an instance
      1) have a name


  0 passing (7ms)
  1 failing

  1) Operator: code an instance have a name:
     AssertionError: expected { opts: 'kris' } to deeply equal true
      at Context.that.should (eval at <anonymous> (.tmp/mocha-webpack/28cf7d614cc45dc0abdbbfe10ec37561/28cf7d614cc45dc0abdbbfe10ec37561-output.js:85:1), <anonymous>:17:32)


--- I don't need the rest of this SHIT ---

npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "mocha:test"
npm ERR! node v7.0.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] mocha:test: `npm run lint & mocha-webpack --opts test/config/mocha/mocha-webpack.opts`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] mocha:test script 'npm run lint & mocha-webpack --opts test/config/mocha/mocha-webpack.opts'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the code-operator-js package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run lint & mocha-webpack --opts test/config/mocha/mocha-webpack.opts

Thanks :)

How to exclude "node_modules"

How can I exclude node_modules from the run?

mocha-webpack

I thought that webpack-node-externals were meant for this task. This is my webpack.test-config.js:

const nodeExternals = require('webpack-node-externals');
const config = {};

// in order to ignore built-in modules like path, fs, etc.
config.target = 'node';

// in order to ignore all modules in node_modules folder
config.externals = [nodeExternals()];

config.output = {
    // sourcemap support for IntelliJ/Webstorm
    devtoolModuleFilenameTemplate: '[absolute-resource-path]',
    devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
};

// 'cheap-module-source-map' faster than 'source-map'
config.devtool = "source-map";


module.exports = config;

I run the tests from package.json:

"test": "mocha-webpack --webpack-config webpack.config-test.js \"**/test/*.test.js\"",

Never quits

The test runner never seems to quit after running tests, I always have to kill it with ^C.

I'm running via this in package.json:

{
  "scripts": {
    "test": "mocha-webpack --colors --webpack-config webpack.config.js --require source-map-support/register --recursive test",
  }
}

although the same happens when I run from the command line using the same params.

Apart from this is a very useful tool though - good work!

Use of Webpack aliases and loaders?

I've got an existing Webpack config that runs my whole test suite and dependencies through Webpack and Babel. That means that my test files themselves are written in ES6, including use of "import". I also have a number of aliases for folders inside my src folder, ie, $REPO/src/components/SomeComponent.jsx can be referred to as simply "components/SomeComponent".

I'm trying to set up mocha-webpack, and I'm pointing it at a slightly cut-down version of my existing Webpack test config (removed "entry" and "output", etc). At the moment, it does not appear that it actually makes any use of my config's loaders or aliases. Pointing it at a specific test file with ES6 syntax produced "Unexpected token" errors indicating unsupported syntax, and when I switched my "import" statements to "require" statements, it then complained that it couldn't find the files referred to by my aliases.

Is there a particular bit of configuration I need to pass to mocha-webpack to have it use the loaders on the test code, is there something obvious I'm missing, or does mocha-webpack not support transpiling the test files themselves?

Use os.tmpdir() instead of .tmp

(I can send a PR for this if you'd like.)

Until #25 lands (which I think is great, but complicated), rather than .tmp/, we could use require("os").tmpdir(), which does what it says :)

Watching files and running test in docker container.

I would like to run tests inside a docker container and use the watch feature. The source directory is mounted into the container, which is problematic in terms of watching files. The fix is to use polling. With webpack you can use:

watchOptions: {
    poll: true
}

This works well for me when running webpack -w but with mocha-webpack test are only rerun sporadically when files change. Taking a quick look at the source it seems like mocha-webpack takes the webpack.config file and uses webpack for watching. So it should work too.

It would be great if I could get this working reliably.

need a way to set the tmp dir.

I needed to move the .tmp dir somewhere else so I
ln -s /tmp .tmp

and tried to run but got

ERROR in /tmp/mocha-webpack/3b4322aaa3a221e1139cdef1c99b0e0c-entry.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../../src in /tmp/mocha-webpack
resolve file
resolve directory
/src doesn't exist
@ /tmp/mocha-webpack/3b4322aaa3a221e1139cdef1c99b0e0c-entry.js 5:23-58

// This gets replaced by webpack with the updated files on rebuild
var __webpackManifest__ = [];

var testsContext = require.context("../../src", false);

Write to and read from memory

Currently, mocha-webpack compile the webpack bundle to .tmp folder and let mocha read it from there. This process is time-consuming.

I suggest we should write the bundle to memory and let mocha read it from memory. This blog shows that it is a feasible way by using an undocumented mocha api.

If this looks good to you, I would like to give it a try :)

Too many non-option arguments: got 2, maximum of 1

Hi there,

I've spent a couple of hours trying to get mocha-webpack to do anything but no matter what I throw at it, it keeps returning the error "Too many non-option arguments: got 2, maximum of 1". Even requesting the version number fails.

It seems as if it fails in receiving any command-line arguments.

"mocha": "^2.4.5",
"mocha-webpack": "^0.3.0",
node: 5.7.0
"webpack": "^1.13.0"

Any help is greatly appreciated.

Run into several issues

Hi there. I've got this software more or less working but I've hit a few issues. My repository is here:

https://github.com/Linode/manager

I'm having two main issues:

  1. I can't figure out how to get source maps working, so errors during tests don't have meaningful stack traces
  2. I can't figure out how to import the rest of the code. Doing it in test/setup.js causes errors with jsdom's window not being available and there's no other clear place where it's appropriate to make sure everything gets imported - which will be useful when I try to add code coverage to the mix later.

Strange failure

I'm getting a very strange failure whenever I attempt to run tests in node
environment. The tests run fine in the browser though (using a slightly different configuration).

I created a test script in package.json like so:
"test": "mocha-webpack --colors --webpack-config webpack.config-test.js \"test/start.js\""

webpack.config-test.js contains the following:

var webpack = require("webpack");
var nodeExternals = require("webpack-node-externals");

module.exports = {
  target: "node",
  externals: [nodeExternals()],
  module: {
    preLoaders: [
      { test: /\.js$/, exclude: /node_modules/, loader: "eslint" }
    ],
    loaders: [
      {
        test: /.js$/,
        loader: "babel",
        exclude: /node_modules/,
        query: {
          presets: ["es2015"],
          cacheDirectory: true
        }
      },
      { test: /\.json$/, loader: "json" },
      { test: /\.css$/, loader: "css" },
      { test: /\.html$/, loader: "dom!html" },
    ]
  },
  plugins: [
    new webpack.DefinePlugin({PRODUCTION: false,
                              BROWSER: false}),
  ],
  devtool: "source-map"
};

Whenever I run npm test, the following very strange output is produced:

$ npm test
> [email protected] test /home/miguelg/work/html-highlighter
> mocha-webpack --colors --webpack-config webpack.config-test.js "test/start.js"


WARNING in ./~/mocha-loader/EnhancedMocha.js
Critical dependencies:
29:24-37 the request of a dependency is an expression
 @ ./~/mocha-loader/EnhancedMocha.js 29:24-37

WARNING in ./~/mocha-loader/README.md
Module parse failed: /home/miguelg/work/html-highlighter/node_modules/mocha-loader/README.md Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '#' (1:0)
    at Parser.pp$4.raise (/home/miguelg/work/html-highlighter/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp$7.getTokenFromCode (/home/miguelg/work/html-highlighter/node_modules/webpack/node_modules/acorn/dist/acorn.js:2756:10)
    at Parser.pp$7.readToken (/home/miguelg/work/html-highlighter/node_modules/webpack/node_modules/acorn/dist/acorn.js:2477:17)
    at Parser.pp$7.nextToken (/home/miguelg/work/html-highlighter/node_modules/webpack/node_modules/acorn/dist/acorn.js:2468:15)
    at Parser.parse (/home/miguelg/work/html-highlighter/node_modules/webpack/node_modules/acorn/dist/acorn.js:515:10)
    at Object.parse (/home/miguelg/work/html-highlighter/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
    at Parser.parse (/home/miguelg/work/html-highlighter/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (/home/miguelg/work/html-highlighter/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (/home/miguelg/work/html-highlighter/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/home/miguelg/work/html-highlighter/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /home/miguelg/work/html-highlighter/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (/home/miguelg/work/html-highlighter/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at /home/miguelg/work/html-highlighter/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)
 @ ./~/mocha-loader ^\.\/.*$




  0 passing (0ms)

  1) fix test errors

  0 passing (4ms)
  1 failing

  1)  fix test errors:
     Error: Cannot find module '!!/home/miguelg/work/html-highlighter/node_modules/babel-loader/index.js?{"presets":["es2015"],"cacheDirectory":true}!/home/miguelg/work/html-highlighter/node_modules/eslint-loader/index.js!/home/miguelg/work/html-highlighter/src/htmlhighlighter_test.js'.
      at .tmp/mocha-webpack/start.js:182:42
      at webpackContextResolve (.tmp/mocha-webpack/start.js:182:90)
      at webpackContext (.tmp/mocha-webpack/start.js:179:30)
      at Mocha.EnhancedMocha.loadFiles (.tmp/mocha-webpack/start.js:119:48)
      at Mocha.EnhancedMocha.watch (.tmp/mocha-webpack/start.js:139:8)
      at Object.<anonymous> (.tmp/mocha-webpack/start.js:85:8)
      at __webpack_require__ (.tmp/mocha-webpack/start.js:20:30)
      at webpackContext (.tmp/mocha-webpack/start.js:65:10)
      at Array.forEach (native)
      at Object.map../htmlhighlighter_test.js (.tmp/mocha-webpack/start.js:55:17)
      at __webpack_require__ (.tmp/mocha-webpack/start.js:20:30)
      at .tmp/mocha-webpack/start.js:40:18
      at Object.<anonymous> (.tmp/mocha-webpack/start.js:43:10)
      at require (internal/module.js:20:19)
      at Array.forEach (native)
      at node_modules/mocha-webpack/lib/cli/runner.js:59:11
      at Compiler.<anonymous> (node_modules/mocha-webpack/lib/webpack/createCompiler.js:76:7)
      at Compiler.applyPlugins (node_modules/tapable/lib/Tapable.js:26:37)
      at Compiler.<anonymous> (node_modules/webpack/lib/Compiler.js:193:12)
      at Compiler.emitRecords (node_modules/webpack/lib/Compiler.js:282:37)
      at Compiler.<anonymous> (node_modules/webpack/lib/Compiler.js:187:11)
      at node_modules/webpack/lib/Compiler.js:275:11
      at Compiler.applyPluginsAsync (node_modules/tapable/lib/Tapable.js:60:69)
      at Compiler.afterEmit (node_modules/webpack/lib/Compiler.js:272:8)
      at Compiler.<anonymous> (node_modules/webpack/lib/Compiler.js:267:14)
      at node_modules/async/lib/async.js:52:16
      at done (node_modules/async/lib/async.js:246:17)
      at node_modules/async/lib/async.js:44:16
      at node_modules/graceful-fs/graceful-fs.js:43:10
      at FSReqWrap.oncomplete (fs.js:82:15)



npm ERR! Test failed.  See above for more details.

I'm baffled. Notice the warning on the README.md file and the wrong tests
being run ("fix test errors").

Any thoughts as to what is happening?

Error with source maps & jsdom

Using mocha-babel with jsdom seems to causes some confusion with source-map-support...

$ $(npm bin)/mocha-webpack --opts test/mocha-webpack.opts
/Users/thom/dev/sandbox/app-client/node_modules/source-map-support/source-map-support.js:411
      var hasStack = (arguments[1] && arguments[1].stack);
                                                  ^

TypeError: Invalid URL

My webpack test config, pretty much straight from the docs:

const nodeExternals = require('webpack-node-externals');

module.exports = {
  target: 'node', // in order to ignore built-in modules like path, fs, etc.
  externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
  module: { .... }
  output: {
    // sourcemap support for IntelliJ/Webstorm
    devtoolModuleFilenameTemplate: '[absolute-resource-path]',
    devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
  },
  devtool: 'cheap-module-source-map',
};

mocha-webpack.opts:

--recursive
--colors
--reporter list
--ui bdd
--timeout 2000
--require source-map-support/register
--require test/register.js
--webpack-config config/webpack.test.config.js
**/__tests__/*.js

test/register.js sets up jsdom:

//require('babel-register')({
  // make sure you use the same presets as in webpack.config.js:
//  presets: ['react', 'es2015', 'stage-1'],
//});
const jsdom = require('jsdom').jsdom;

const exposedProperties = ['window', 'navigator', 'document'];

const document = jsdom('');
global.document = document;
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
  if (typeof global[property] === 'undefined') {
    exposedProperties.push(property);
    global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js',
};

I've tried adding require('source-map-support/register'); at the top or bottom of register.js and also tried changing the order of --register lines in my mocha-webpack.opts with no success...

Incompatible with unpublished thrid-party reporter

I have a third-party mocha reporter would like to use, but checkReporter does not allow that.
In checkReporter we have two checks, require("mocha/lib/reporters/" + reporter); and require(reporter); which applies to mocha's built-in reporter and published reporter. However unpublished reporter in my project will always fail.

Error: reporter "test/test-lib/specReporterWithLineNumber" does not exist
...

I think an extra require("mocha/../../" + reporter); to check against unpublished thrid-party reporter would be nice to have. It's a bad pattern though. Currently I have to use NODE_PATH=. to solve this issue, which is not ideal either.

`--watch` works, otherwise crash on `import` token

screen shot 2016-04-26 at 11 12 51

The right hand side runs all tests successfully. The left not so.

Repro: causiq/sdk@5e2db69

npm install && npm build && npm run test versus npm install && npm build && npm run test:watch.

Misc

Log:

> [email protected] test /Users/h/dev/haf/logary-js
> NODE_ENV=dev mocha-webpack --webpack-config webpack-test.config.js --colors --require source-map-support/register ./test/unit/*.js

SyntaxError: Unexpected token import
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /Users/h/dev/haf/logary-js/node_modules/mocha-webpack/lib/cli/index.js:42:3
    at Array.forEach (native)
    at Object.<anonymous> (/Users/h/dev/haf/logary-js/node_modules/mocha-webpack/lib/cli/index.js:41:17)

webpack-test.config.js:

var path = require("path"),
    webpack = require("webpack"),
    loaders = require('./webpack-loaders');

var createConfig = function(version) {
  return {
    cache: true,
    devtool: 'inline-source-map',
    output: {
      devtoolModuleFilenameTemplate: '[absolute-resource-path]',
      devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]',
      libraryTarget: "umd",
      library: "logary"
    },
    module: {
      loaders: loaders
    },
    resolve: {
      extensions: ['', '.js']
    }
  }
};

module.exports = createConfig('1.0.0');

Versions

[email protected] /Users/h/dev/haf/logary-js
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │   └── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   ├── [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   ├── [email protected]
│ │   ├── [email protected]
│ │   └─┬ [email protected]
│ │     └── [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   └─┬ [email protected]
│     ├─┬ [email protected]
│     │ └── [email protected]
│     └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   ├─┬ [email protected]
│ │   │ ├─┬ [email protected]
│ │   │ │ ├─┬ [email protected]
│ │   │ │ │ └── [email protected]
│ │   │ │ └── [email protected]
│ │   │ ├── [email protected]
│ │   │ ├─┬ [email protected]
│ │   │ │ └── [email protected]
│ │   │ ├── [email protected]
│ │   │ └─┬ [email protected]
│ │   │   └── [email protected]
│ │   ├── [email protected]
│ │   └── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │   ├── [email protected]
│ │ │   └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └─┬ [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ └── [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ └── [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ └── [email protected]
│ │ │   │ └─┬ [email protected]
│ │ │   │   ├── [email protected]
│ │ │   │   ├─┬ [email protected]
│ │ │   │   │ ├── [email protected]
│ │ │   │   │ └── [email protected]
│ │ │   │   ├── [email protected]
│ │ │   │   └── [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ └── [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ └─┬ [email protected]
│ │ │   │ │   ├── [email protected]
│ │ │   │ │   └── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ └── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ └── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ ├─┬ [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ ├─┬ [email protected]
│ │ │   │ │ │ │ └── [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ └── [email protected]
│ │ │   │ │ ├─┬ [email protected]
│ │ │   │ │ │ └── [email protected]
│ │ │   │ │ ├─┬ [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ ├─┬ [email protected]
│ │ │   │ │ │ │ └── [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ └── [email protected]
│ │ │   │ │ └─┬ [email protected]
│ │ │   │ │   └── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ ├── [email protected]
│ │ │   │ │ ├── [email protected]
│ │ │   │ │ ├── [email protected]
│ │ │   │ │ └── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ ├── [email protected]
│ │ │   │ │ ├─┬ [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ ├── [email protected]
│ │ │   │ │ │ └── [email protected]
│ │ │   │ │ └─┬ [email protected]
│ │ │   │ │   ├── [email protected]
│ │ │   │ │   ├─┬ [email protected]
│ │ │   │ │   │ └── [email protected]
│ │ │   │ │   ├── [email protected]
│ │ │   │ │   ├── [email protected]
│ │ │   │ │   ├── [email protected]
│ │ │   │ │   └── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ └── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ └── [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ └─┬ [email protected]
│ │ │   │   ├─┬ [email protected]
│ │ │   │   │ └── [email protected]
│ │ │   │   ├── [email protected]
│ │ │   │   ├─┬ [email protected]
│ │ │   │   │ └─┬ [email protected]
│ │ │   │   │   ├── [email protected]
│ │ │   │   │   └── [email protected]
│ │ │   │   ├─┬ [email protected]
│ │ │   │   │ └── [email protected]
│ │ │   │   └── [email protected]
│ │ │   ├── [email protected]
│ │ │   ├─┬ [email protected]
│ │ │   │ ├── [email protected]
│ │ │   │ ├─┬ [email protected]
│ │ │   │ │ └── [email protected]
│ │ │   │ └── [email protected]
│ │ │   └─┬ [email protected]
│ │ │     ├─┬ [email protected]
│ │ │     │ └── [email protected]
│ │ │     ├─┬ [email protected]
│ │ │     │ └─┬ [email protected]
│ │ │     │   └─┬ [email protected]
│ │ │     │     ├── [email protected]
│ │ │     │     └── [email protected]
│ │ │     ├─┬ [email protected]
│ │ │     │ └── [email protected]
│ │ │     ├─┬ [email protected]
│ │ │     │ ├── [email protected]
│ │ │     │ ├── [email protected]
│ │ │     │ ├── [email protected]
│ │ │     │ ├── [email protected]
│ │ │     │ └── [email protected]
│ │ │     └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   └─┬ [email protected]
│ │     ├── [email protected]
│ │     └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├─┬ [email protected]
│ │ │ │ │ └── [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├─┬ [email protected]
│ │ │ │ │ └── [email protected]
│ │ │ │ └── [email protected]
│ │ │ └─┬ [email protected]
│ │ │   ├── [email protected]
│ │ │   └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │   ├── [email protected]
│ │ │   ├── [email protected]
│ │ │   └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └─┬ [email protected]
│ │ │ │   └── [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │   ├── [email protected]
│ │   ├── [email protected]
│ │   ├── [email protected]
│ │   └── [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   └── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   ├─┬ [email protected]
│ │   │ └── [email protected]
│ │   ├─┬ [email protected]
│ │   │ ├─┬ [email protected]
│ │   │ │ └─┬ [email protected]
│ │   │ │   ├── [email protected]
│ │   │ │   ├── [email protected]
│ │   │ │   ├── [email protected]
│ │   │ │   └── [email protected]
│ │   │ ├── [email protected]
│ │   │ └── [email protected]
│ │   ├─┬ [email protected]
│ │   │ └── [email protected]
│ │   ├── [email protected]
│ │   ├── [email protected]
│ │   ├─┬ [email protected]
│ │   │ └── [email protected]
│ │   ├─┬ [email protected]
│ │   │ ├─┬ [email protected]
│ │   │ │ └── [email protected]
│ │   │ └── [email protected]
│ │   ├─┬ [email protected]
│ │   │ ├── [email protected]
│ │   │ └── [email protected]
│ │   └─┬ [email protected]
│ │     ├── [email protected]
│ │     └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│   ├── [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   ├── [email protected]
│   ├─┬ [email protected]
│   │ └─┬ [email protected]
│   │   └── [email protected]
│   ├── [email protected]
│   └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │   └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   ├── [email protected]
│ │   ├─┬ [email protected]
│ │   │ ├─┬ [email protected]
│ │   │ │ ├─┬ [email protected]
│ │   │ │ │ └── [email protected]
│ │   │ │ └── [email protected]
│ │   │ ├── [email protected]
│ │   │ └── [email protected]
│ │   └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│   └── [email protected]
└─┬ [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  │ │ └─┬ [email protected]
  │ │   └── [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ ├─┬ [email protected]
  │ │ └─┬ [email protected]
  │ │   └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ └─┬ [email protected]
  │   └── [email protected]
  ├── [email protected]
  ├── [email protected]
  ├── [email protected]
  └── [email protected]


--require not working as expected

Thank you so much for this package! It is making my testing workflow so much better!

I'm running into an issue with --require. I have the following mocha-webpack.opts file:

--colors
--require client/__tests__/specHelper.js
--reporter spec
--webpack-config webpack.config.js
--glob *-spec.js
--recursive
client

My specHelper.js file is being required properly, but its effects are not being made visible to my tests when they run.

specHelper.js looks like this:

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const sinonChai = require('sinon-chai')

chai.use(chaiAsPromised)
chai.use(sinonChai)

When I run my tests, I get the error: TypeError: (0 , _chai.expect)(...).to.become is not a function, which means that chai-as-promised is not available.

When I previously ran my specs using mocha directly, the --require option worked as I expected.

If I rename specHelpler.js to specHelper-spec.js, then it works as I expect; however, if I run mocha-webpack with the --watch option and then change a test, I get the same error message again because the specHelper-spec.js file wasn't reloaded by --watch.

At this point, the only workaround I can think of is to explicitly import my spec helper into all of my test files.

I've had a look at the code, and I don't see any obvious problems with it. Somehow it seems like the webpack-compiled code doesn't have access to the chai object that was configured by the spec helper.

Path resolution problem? can't see to find / run tests, but it knows folder..

Can't seem to get mocha-webpack to run the tests.

config is..

var config = require('./webpack.config.js');
var nodeExternals = require('webpack-node-externals');
config.target = 'node';
config.externals = [nodeExternals()];
config.devtool = "#cheap-module-source-map";
module.exports = config;

opts is..

--colors
--webpack-config webpack.config-test.js
test/*-test.js

Have two test files (demo-test.js, proj-test.js) in a folder called test under the root folder where the webpack.config.js is located.

Key defs in the core webpack.config.js are..

/////////////////////////////////////////////////////////////////////////////////
// CONFIGURATION

var basePath = path.normalize(path.join('./static/', dist_dir, '/'));
var codePath = 'js/';

var config = {
    context: __dirname,

    devtool: 'source-map',

    entry: {
        main: ['./app/main'],
        style: ['./theme/react.less'],
        common: Object.keys(pjson.dependencies)
    },

    output: {
        path: basePath,
        filename: codePath + "[name].js",
        publicPath: '/' + basePath
    },

    plugins: [
        new CommonsPlugin({
            name: "common"
        }),
        // new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
        new ExtractTextPlugin(cssPath + 'site.min.css')
    ],

    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                include: [path.join(__dirname, 'app'), path.join(__dirname, 'test')],
                exclude: /node_modules/,
                loaders: ['react-hot', 'babel']
            },
        ]
    },

    resolve: {
        root: path.resolve(__dirname),
        extensions: ['', '.js', '.jsx'],
    },

    externals: {
        routes: 'Routes'
    }

};

running the test...

npm run test

always results in

0 passing (1ms)

If I remove the folder, it fails, so I know it's detecting the folder. It doesn't act like it globs the file itself.

I'm at a loss how to get mocha-webpack to run the tests against the two files in the test folder.

running mocha does run the test.

but running it manually as well, also results in 0 passing...

$ ./node_modules/mocha-webpack/bin/mocha-webpack --webpack-config webpack.config-test.js --colors test/demo-test.js 
  0 passing (1ms)

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.