Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finds files, but says "0 passing" tests #48

Closed
jfeldstein opened this issue Sep 22, 2016 · 15 comments
Closed

Finds files, but says "0 passing" tests #48

jfeldstein opened this issue Sep 22, 2016 · 15 comments

Comments

@jfeldstein
Copy link

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

> teacherdashboard@1.0.0 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?

@zinserjan
Copy link
Owner

This makes me think I'm not doing something to "register" my tests, somehow?

"test": "mocha-webpack --webpack-config webpack.config.test.js \"./tests/js/**/*.test.js\"" is just enough.

There isn't a debug or verbose flag

Unfortunately not.

Any ideas?

Everything looks good to me. Can you provide me an failing example?

@citizen-stig
Copy link

I also have this problem

@dola
Copy link

dola commented Oct 13, 2016

I'm experiencing the same issue when using mocha-webpack with typescript. I put together a minimal example for you to check out here: https://github.com/dola/mocha-webpack-fail

I suspect that it might fail because all files have a .ts extension and not .js

@IanVS
Copy link

IanVS commented Oct 24, 2016

I had this problem when attempting to use brace expansion. For example, to find all .js and .jsx files, my pattern was: "client/**/*.spec{.jsx,.js}". That worked fine when I was using gulp-mocha, but with mocha-webpack, I would get the mentioned 0 passing message.

The fix for me was to put the period outside of the braces. "client/**/*.spec.{jsx,js}" works fine for me.

@chipit24
Copy link

I'm having the same problem, even if the file I'm pointing to is empty. It complains if the file doesn't exist, but it doesn't actually seem to execute anything inside the file.

@CodyReichert
Copy link

I had this problem when running from the command line. The fix for me was to make sure I had quotes around my file glob. Eg,

Doesn't work

$ moch-webpack --webpack-config webpack.config.test.js test/**/*-test.js

Did work

$ moch-webpack --webpack-config webpack.config.test.js "test/**/*-test.js"

@zinserjan
Copy link
Owner

All issues mentioned in this thread (except the terminal quotes) will be fixed with 1.0.0.

@Izhaki
Copy link

Izhaki commented Jul 13, 2017

As mentioned in the linked dola/mocha-webpack-fail#1

this seems to solve it:

npm install --save-dev mocha-webpack@next

@yinjinit
Copy link

I just installed mocha-webpack but it's not working yet. still saying "0 passing (0 ms)".

@alakhera
Copy link

I am also facing the same issue.

@dmiranda2791
Copy link

This is happening to me even for a file that does not exists.
"test": "mocha-webpack --webpack-config webpack.test.config.js noexists.spec.js"

0 passing (0ms)

 MOCHA  Tests completed successfully

@bgschiller
Copy link

I was seeing this issue, but in my case the fix was different.

I was trying to set up some a variable that would be used in several it('...') blocks. The value was the result of a promise, so my describe callback was marked async. That turned out not to work.

It would be nice to have a warning when passing a promise to describe(). Maybe that's something that needs to be changed in mocha itself, though.

To sum up, this fails:

describe('availableDevices', async () => {
  const fakeFfmpegOutput = async () => `
ffmpeg version N-89524-g74f408c-tessus Copyright (c) 2000-2017 the FFmpeg developers
... lots of lines cut here ...
  : Input/output error`;

  const devices = await availableDevices(fakeFfmpegOutput);

  it('Excludes cameras from the list', () => {
    expect(_.map(devices, 'deviceId')).to.not.include.any('1', '2');
  });

but this works:

describe('availableDevices', () => {
  const fakeFfmpegOutput = async () => `
ffmpeg version N-89524-g74f408c-tessus Copyright (c) 2000-2017 the FFmpeg developers
... lots of lines cut here ...
  : Input/output error`;

  it('Excludes cameras from the list', async () => {
    const devices = await availableDevices(fakeFfmpegOutput);
    expect(_.map(devices, 'deviceId')).to.not.include.any('1', '2');
  });

I take from this that if the callback to describe is given a promise, that promise will not be waited on.

@Nulifier
Copy link

Just in case someone else has this issue and the above fixes don't work.

I'm sharing a webpack config between my normal build and the unit tests and I had optimization.runtimeChunk = "single" in my config. Removing that for the test environment solved my problem.

@ccarstens
Copy link

@Nulifier you saved my life! <3

@Jeandcc
Copy link

Jeandcc commented May 17, 2021

This here deserves more praise!

I was seeing this issue, but in my case the fix was different.

I was trying to set up some a variable that would be used in several it('...') blocks. The value was the result of a promise, so my describe callback was marked async. That turned out not to work.
(...)

So, to sum it up: Your describe blocks should not take async functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests