zinserjan/mocha-webpack

Compilation succeeds but test finish immediately

jglover opened this issue · 9 comments

Hi,
I'm running mocha-webpack in order to utilise path aliasing in Webpack/Typescript TSC and I'm running into an issue where Webpack compilation succeeds but Mocha returns immediately with:
0 Passing. Tests completed successfully
I was previously using the following command to run mocha over the compiled js, which ran without problem.
node_modules/.bin/mocha --require source-map-support/register mocha-setup.js 'compiled/**/*-spec.js'
I've now changed mocha out for mocha-webpack as follows
node_modules/.bin/mocha-webpack --webpack-config webpack.config.js --require source-map-support/register mocha-setup.js 'compiled/**/*-spec.js'

packages are "webpack": "4.12.1" and "mocha-webpack": "2.0.0-beta.0"
I'm unsure what I'm missing, much appreciate any help!

screen shot 2018-06-28 at 10 15 47 am

I have exactly the same issue!

@4lph4-Ph4un I believe TSC is emitting compiled files with aliases that mocha-webpack cannot interpret. I may have been mistaken in my assumption that mocha-webpack had a loader for them.

@jglover I had the same error. But I fixed this by using the --recursive tag for mocha-webpack directly. I (wrongly) assumed it was using my old mocha.opts but it uses it's own config. Hope this helps.

@jglover I had the same issue. Unexpectedly, I found swapping my single quotes 'test/**/*.ts' for double "test/**/*.ts" fixed it for me.

@jglover @4lph4-Ph4un I had the same issue with "webpack@4.28.3" and "mocha-webpack@2.0.0-beta.0". Have you fix it ? Any suggestion ?

@jglover @Gmadges I have the same issue. Is there any successful demo can show me ? thanks

anlek commented

I'm in the same boat, anyone knows what caused this?

anlek commented

For me, it seemed to be something to do with "Single File Components" in Vue and SCSS processing.
I patched it by just removing all CSS and SCSS rules and adding a null-loader for those:

// In my webpack-test-config.js
const newRules = config.module.rules.reduce((memo, r) => {
  if (r.test === undefined) return memo
  if (r.test.test('.css') || r.test.test('.scss')) return memo

  memo.push(r)
  return memo
}, [])

newRules.push({ test: /.(s)?css$/, loader: 'null-loader' })
config.module.rules = newRules

module.exports = config

Fixed my problem, however, I'm working on a large private project and I'm unable to share the code to help resolve the bug :(

@anlek That tip did it for me!

I used a null-loader in my webpack.mocha.js config file

    {
      test: /\.(css|scss)$/,
      use: 'null-loader'
    },

Then specified that config file for mochapack to use. This is is my line in
This is my line in package.json:

"unit-tests": "mochapack --webpack-config config/webpack.mocha.js  --require 'src/test/setup.js' --reporter spec --colors --glob '*.test.js' src --recursive"