istanbul
istanbul copied to clipboard
Windows support
My istanbul cover
commands fail on windows, but the vows --spec ./test/foo.js
works fine.
I get this error:
YUI@WINDOWS7 ~/Desktop/play/cpr (master)
$ npm test
> [email protected] pretest c:\Users\YUI\Desktop\play\cpr
> jshint --config ./node_modules/yui-lint/jshint.json ./lib/
> [email protected] test c:\Users\YUI\Desktop\play\cpr
> istanbul cover --print both -- vows --spec ./tests/full.js
c:\Users\YUI\Desktop\play\cpr\node_modules\.bin\vows.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by np
^
Unexpected token :
SyntaxError: Unexpected token :
at Module._compile (module.js:437:25)
at Module._extensions..js (module.js:467:10)
at Object.Module._extensions..js (c:\Users\YUI\Desktop\play\cpr\node_modules
\istanbul\lib\hook.js:101:13)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:492:10)
at runFn (c:\Users\YUI\Desktop\play\cpr\node_modules\istanbul\lib\command\co
mmon\run-with-cover.js:80:16)
at c:\Users\YUI\Desktop\play\cpr\node_modules\istanbul\lib\command\common\ru
n-with-cover.js:148:17
at c:\Users\YUI\Desktop\play\cpr\node_modules\istanbul\lib\util\file-matcher
.js:52:16
at c:\Users\YUI\Desktop\play\cpr\node_modules\istanbul\lib\util\file-matcher
.js:35:9
No coverage information was collected, exit without writing coverage information
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
YUI@WINDOWS7 ~/Desktop/play/cpr (master)
$
For reference, that vows is running:
YUI@WINDOWS7 ~/Desktop/play/cpr (master)
$ ./node_modules/.bin/vows --spec ./tests/full.js
♢ CPR Tests
should be loaded
✓ should have cpr method
should fail on non-existant from dir
✓ should return an error in the callback
should be loaded and should NOT copy node_modules
✓ does not have ./out/1
✓ and threw an error
should be loaded and should not copy graceful-fs from function
✓ and has ./out/3
✓ and dirs are not equal
✓ and from directory has graceful-fs dir
✓ and to directory does not have graceful-fs dir
should be loaded and should copy node_modules
✓ has ./out/0
✓ and dirs are equal
✓ and from directory has graceful-fs dir
✓ and to directory has graceful-fs dir
should be loaded and should not copy yui-lint from regex
✓ and has ./out/2
✓ and dirs are not equal
✓ and from directory has yui-lint dir
✓ and to directory does not have yui-lint dir
should be loaded and should copy node_modules with overwrite flag
✓ has ./out/0
✓ and dirs are equal
✓ and from directory has graceful-fs dir
✓ and to directory has graceful-fs dir
✓ OK » 20 honored (10.885s)
YUI@WINDOWS7 ~/Desktop/play/cpr (master)
$
Something screwy with the colon character in the path name that is confusing istanbul.
Damn, I wish I had an easy way to reproduce windows issues. Do you have a VM or something I can use to play with this.
Windows is the biggest gap in tests for istanbul
I have a personal Windows 7 VM that I have setup with Node and git, but nothing that I can share as its in my server closet in IL ;)
Could you run istanbul cover -v
and paste the output just in case there is any additional info to be had from verbose logging?
The output of -v
is exactly the same as above.
Ok, here's some info for you.
If I change my test script to:
istanbul --cover -v --print both -- ./node_modules/vows/bin/vows --spec ./tests/full.js
From:
istanbul --cover -v --print both -- vows --spec ./tests/full.js
It works.
On Windows, the ./node_modules/.bin/vows.cmd
is a windows bat script. So istanbul
needs to know how to deal with that.
Thanks for the info. This is going to be really tricky, if not impossible....
Bascially, the "command processing" is done using node-which
and the result of this operation is assumed to be a JS file that is passed directly to the module loader as in: Module.runMain(file)
.
Also, off-topic - does the HTML reporting work correctly on Windows? I don't have a single test for this and it's the reporting that has path-delimiter specific code.
Yeah, I figured as much. If I have some time, I may see what I can come up with to help out since I have a fully functional windows dev environment here.
The reporting works and looks ok. It renders all the /
in the HTML as \
, which just doesn't quite look right to me. Besides, the reports should be pretty close to exact no matter what system they are generated on. (thinking about coverage files that are checked into source control).
Let me work on getting a Windows machine up and running - I think I'll pinch my son's machine for this. Totally agree that everything should work the same on windows.
Everything seems to be working ok on Windows, but I have one small question:
Say I have the following folder structure:
lib/
- lib1.js
- lib2.js
tests/
- lib1.js
- lib2.js
index.js (main file that requires all the tests)
If I run istanbul cover index.js
besides the coverage\ folder it creates .html files in lib/ and a index.html && index.js.html file inside the root.
The main html coverage stats file is in coverage, but shouldn't the rest also be there... ? (I haven't had time to test the library in OSX / Ubuntu yet to see if it's the same there).
I really hate having all those .html files laying around everywhere. Thanks
@gotwarlost @davglass
Ok followup: so normally istanbul should put the html files inside /coverage/lcov-report/ (and specific files inside the folder ProjectName).
The thing is in Windows it only puts /coverage/lcov-report/index.html there, the rest of the html files are dispersed all over the place (wherever there's a covered_test_file.js it will put the html in the same folder).
More details about my setup: Windows 7 and:
$ node -v && npm -v
v0.6.11
1.1.1
Anyway, I'm happy it works in OSX/Linux :D
Can you install the latest node on Windows and check it against that first? 0.6.11
is quite old ;)
Anyone else still having problems in Windows? I still get that same kind of error like this:
c:\Users\JGough\AppData\Roaming\npm\_mocha.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by np
^
SyntaxError: Unexpected token :
at Module._compile (module.js:437:25)
at Module._extensions..js (module.js:467:10)
at Object.Module._extensions..js (c:\Users\JGough\AppData\Roaming\npm\node_m
odules\istanbul\lib\hook.js:101:13)
ok, so the "magic" expansion of commands to JS files only works on Mac/ Unix because the executable files directly resolve to the JS files that have shebangs in them.
On windows, you need to actually pass the JS file name that the mocha command uses, since in that environment the commands resolve to batch files and not JS files.
Hmm.. well, I'm installing a linux vm irght now :-P
But, I tried this too:
istanbul cover test.js
And it told me it could not find 'describe'. So, I assume I somehow have to include mocha in the command.
$ istanbul cover test.js
c:\Projects\v1.NETSdk.GitHub\Versionone.AppCatalog.Web.Git\VersionOne.AppCatalog
.Web\test.js:6
;var should=require('should');__cov_xnGr93WTzh3NigP_PMZaIQ.s['3']++;describe('
^
ReferenceError: describe is not defined
at Object.<anonymous> (c:\Projects\v1.NETSdk.GitHub\Versionone.AppCatalog.We
b.Git\VersionOne.AppCatalog.Web\test.js:6:194)
at Object.<anonymous> (c:\Projects\v1.NETSdk.GitHub\Versionone.AppCatalog.We
b.Git\VersionOne.AppCatalog.Web\test.js:6:406)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (c:\Users\JGough\AppData\Roaming\npm\node_m
odules\istanbul\lib\hook.js:99:20)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:492:10)
at runFn (c:\Users\JGough\AppData\Roaming\npm\node_modules\istanbul\lib\comm
and\common\run-with-cover.js:86:16)
at c:\Users\JGough\AppData\Roaming\npm\node_modules\istanbul\lib\command\com
mon\run-with-cover.js:185:17
at c:\Users\JGough\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-m
atcher.js:52:16
right - describe
is added as a global by mocha.
@JogoShugh @gotwarlost I ran into the issue with describe is not defined
when running mocha. My solution was to update the mocha dependency to the latest version (1.13.0 at the time of writing).
When trying to run istanbul using istanbul cover _mocha -- -u exports -R spec
on my project, I get the following error:
(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0
^
No coverage information was collected, exit without writing coverage information
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Module._extensions..js (module.js:474:10)
at Object.Module._extensions..js (C:\Users\Sony\AppData\Roaming\npm\node_modules\istanbul\lib\hook.js:101:13)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at runFn (C:\Users\Sony\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:110:16)
at C:\Users\Sony\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:213:17
at C:\Users\Sony\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:52:16
at C:\Users\Sony\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:35:9
I've updated mocha to the latest version and everything works fine and all tests pass. Any idea what could be causing this?
See my previous comment, reproduced for your benefit:
so the "magic" expansion of commands to JS files only works on Mac/ Unix because the executable files directly resolve to the JS files that have shebangs in them.
On windows, you need to actually pass the JS file name that the mocha command uses, since in that environment the commands resolve to batch files and not JS files.
@gotwarlost Thanks for the response. I just skimmed through the thread - silly me. Sorry for the inconvenience!
I didn't understand at all what @gotwarlost was saying, since file expansion could apply to istanbul or mocha, but then I saw @mscdex link an issue that contains a PR with the actual fix. Posting here if anyone else was confused:
https://github.com/component/path-to-regexp/pull/29/files
@gotwarlost Could the "magic" expansion be fixed if you added a command line flag to trigger a lookup through the module loader?
Add a flag that is used like this:
istanbul cover --bin <package>[/<command>] --
Which transforms the parameter in a manner similar to this:
var path = require('path');
function lookupBinPath(inputCommandName) {
var parts = inputCommandName.split('/');
var packageName = parts[0], commandName = parts[1];
// If no slash is present, look for a command with the same name as the package
if (commandName == undefined) commandName = packageName;
// Look up the package.json
var packageJSON = require(packageName+'/package.json');
//Extract the binary path
var relativeBinaryPath = packageJSON.bin[commandName];
// prepend the module name and pass it to require.resolve
return require.resolve(path.join(packageName, relativeBinaryPath));
}
I am using this command istanbul cover C:\Users\abhisek.user\AppData\Roaming\npm\node_modules\mocha\bin_mocha test But it is giving this as out put and not generating the report. Transformation error; return original code [TypeError: Object #<Object> has no method 'isIdentifierPart'] // // No coverage information was collected, exit without writing coverage information
That seems to be an error in parsing your Javascript. Are you sure it is well-formed?
Yes it is well formed. will be a reason for node.js?
Using latest version of karma...
cmi-alvinmilton-1089-mbp:ng-desc-tests alvin.milton$ istanbul cover test/*-spec.js No coverage information was collected, exit without writing coverage information /Users/alvin.milton/Development/ng-desc-tests/test/add-spec.js:7
describe('add', function () { ^
ReferenceError: describe is not defined
describe('add', function () { var add; beforeEach(function () {...
I can confirm that this is still an issue on windows 10.
C:\Program Files (x86)\nodejs\npm.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
^
SyntaxError: Unexpected token :
...
I am running it this way (without flags for readability):
istanbul cover npm run test:server
Please understand that this command works fine
npm run test:server
So there is no "magic" expansion of variables and I have no idea what you mean by that.
Technical details:
$ node -v
v5.1.1
$ npm -v
3.5.1
$ cat package.json | grep istanbul
"istanbul": "0.3.17",
$ cat package.json | grep mocha
"mocha": "2.3.3",
I tested and can confirm that it persists in istanbul 0.4.1
I am using the latest version of Istanbul and I have a similiar problem in Windows 8. This does not work:
istanbul cover jasmine-node spec
No coverage information was collected, exit without writing coverage information
C:\Users\x\AppData\Roaming\npm\jasmine-node.CMD:1
(function (exports, require, module, __filename, __dirname) { @IF EXIST "%~dp0\node.exe" (
^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\x\AppData\Roaming\npm\node_modules\istanbul\lib\hook.js:109:37)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at runFn (C:\Users\x\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
at C:\Users\x\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
at C:\Users\x\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
But if I add the path to the jasmine executable it works:
istanbul cover node_modules\jasmine-node\bin\jasmine-node spec
....
Finished in 12.51 seconds
4 tests, 7 assertions, 0 failures, 0 skipped