Closed millerdev closed 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.
-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?
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.
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');
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?
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
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.
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
If any of you have a publicly accessible reproduction of your issue, I will look into it.
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
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.
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
?
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.
Fixed in mocha-phantomjs-core 1.3.0
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.
Yes you can use that too. Thanks for the good easy reproduction. I pulled that in as a test.