nathanboktae / mocha-phantomjs

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

HTML spec files with UTF8+BOM result in 'Failed to start mocha: Init timeout' #152

Closed mhoyer closed 9 years ago

mhoyer commented 10 years ago

I actually tried to play around with gulp-mocha-phantomjs and got stuck for some hours to actually find the reason why it was not working in my scenario.

Therefore I stepped down into dependent npm modules and tried to figure out which component is in charge for my errors and it seems to be an issue in lib/mocha-phantomjs.coffee. Thus, I could reproduce the issue also with just using mocha-phantomjs.

The problem

I (actually the gulp-mocha-phantomjs package) tried to run this command on my Windows box: c:\Temp\node_modules\phantomjs\lib\phantom\phantomjs.exe c:\Temp\node_modules\mocha-phantomjs\lib\mocha-phantomjs.coffee c:/Temp/index.html spec

Without absolute paths this might look like phantomjs.exe lib\mocha-phantomjs.coffee c:/Temp/index.html

The error was Failed to start mocha: Init timeout after some seconds.

Now the funny thing is, this error occurs only in the following scenario:

For simplification I created this sample:

c:
mkdir \Temp
cd \Temp
npm install mocha-phantomjs
bower install mocha

Save this file into c:\Temp\index.html:

<!doctype html>
<html>
    <body>
        <div id="mocha"></div>
        <script src="bower_components/mocha/mocha.js"></script>
        <script>mocha.setup('bdd')</script>

        <script>
            if (window.mochaPhantomJS) {
                mochaPhantomJS.run();
            } else {
                mocha.run();
            }
        </script>
    </body>
</html>

Now run this:

cd c:\Temp
node_modules\phantomjs\lib\phantom\phantomjs.exe node_modules\mocha-phantomjs\lib\mocha-phantomjs.coffee c:/Temp/index.html spec

^^ play around with saving the index.html with plain UTF8 encoding and UTF8+BOM encoding.

nathanboktae commented 9 years ago

Sorry for not responding to you originally, but I couldn't reproduce this with mocha-phantomjs v4. Either way it's highly likely an issue with phantomjs anyways, but if you're still having issues, let me know. Perhaps it was a specific phantomjs version?