nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

--bail option not bailing #215

Closed millerdev closed 8 years ago

millerdev commented 8 years ago
$ mocha-phantomjs --bail -s loadImages=false index.html?grep="[Rr]ich text"
  Rich text utilities
    simple conversions
      1) from text to html: /data/text
      ✓ from text to html with output value: /data/text
      2) from text to html: ...
      ... many more failures
$ mocha-phantomjs --version
3.5.3
$ phantomjs --version
1.9.8
nathanboktae commented 8 years ago

I've had a test for bail for a long time now. Does -b work for you? what about the latest version of mocha-phantomjs, 4.0.1? it had a major rewrite.

millerdev commented 8 years ago

-b does not work either. I was not able to easily test 4.0.1. I got this error:

mocha was not initialized before the page finished loading. Make sure to include mocha.js as a direct script and call `mocha.ui` or `mocha.setup`.

I'm using requirejs to load the module that calls mocha.setup. Is that not supported in v4.0.1?

nathanboktae commented 8 years ago

See nathanboktae/mocha-phantomjs-core#9 for require.js stuff and comment there if you have questions. It should be fine though if you aren't using require.js to load mocha (but even then, you should get a different error.

millerdev commented 8 years ago

I'm not sure I'm hitting a the same issue that you linked above. This is how my tests are being loaded:

<script src="node_modules/mocha/mocha.js"></script>
<script data-main="tests/main" src="bower_components/requirejs/require.js"></script>

The first statement in tests/main.js is

mocha.setup('bdd');
nathanboktae commented 8 years ago

That is exactly the issue it's talking about.... hmm can you confirm the version of mocha-phantomjs-core is 1.1.0 or higher?

millerdev commented 8 years ago

Not sure. Looks like it's not installed?

$ npm list mocha-phantomjs-core
...
└── (empty)

npm ERR! code 1

$ npm list mocha-phantomjs
...
└── mocha-phantomjs@3.5.3
millerdev commented 8 years ago

oh, you were asking about when I have mocha-phantomjs v4.0.1 installed... I'll get back to you on that when I have time to try upgrading again.

bmark1111 commented 8 years ago

I am running into this same problem. I am loading mocha.js as a direct script and it makes no difference. The tests work in the browser but not using mocha-phantomjs. I have version 4.0.1

nathanboktae commented 8 years ago

If any of you have a publicly accessible reproduction of your issue, I will look into it.

bmark1111 commented 8 years ago

Unfortunately I cannot show my code. However I can tell you that this is related to using requirejs. When not using requirejs this seems to work fine

nathanboktae commented 8 years ago

Unfortunately I cannot show my code. However I can tell you that this is related to using requirejs.

Well I have a test for requirejs that is passing, so you'll have to show me how your setup is different and causing an issue.

millerdev commented 8 years ago

I got around to making up a toy project to reproduce the issue of not being able to use requirejs with mocha-phantomjs: https://github.com/millerdev/mocha-phantom-requirejs

In the process I also discovered a workaround for the "mocha was not initialized..." issue, and can verify that --bail works with 4.0.1 in the toy project. However, I also noticed that window.mochaPhantomJS is now undefined. Is there a new way to detect if tests are being run by mocha-phantomjs?

nathanboktae commented 8 years ago

Thanks @millerdev I see the issue now. Even though I allow a timeout for run I don't for the first setup call.

However, I also noticed that window.mochaPhantomJS is now undefined. Is there a new way to detect if tests are being run by mocha-phantomjs?

window.callPhantom is the proper way to detect phantomjs. See the v4 release notes. For mocha-phantomjs, you can't currently detect it, but that will change as I will be exposing initMochaPhantomJS always - see nathanboktae/mocha-phantomjs-core#13.

nathanboktae commented 8 years ago

Fixed in mocha-phantomjs-core 1.3.0

millerdev commented 8 years ago

Thanks @nathanboktae. I also found mocha.env, which seems to be a reliable indicator that tests have been invoked by mocha-phantomjs. It's referenced in mocha-phantomjs-core docs under Environment variables.

nathanboktae commented 8 years ago

Yes you can use that too. Thanks for the good easy reproduction. I pulled that in as a test.