Comments (49)
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.
from istanbul.
Still an issue with
istanbul cover mocha
but
istanbul cover node_modules/mocha/bin/_mocha
works
from istanbul.
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",
from istanbul.
This is still an issue for me on Windows 10 using git-bash from git for Windows 2.8.3-64 from [1].
$ istanbul cover _mocha -- --recursive
No coverage information was collected, exit without writing coverage information
C:\Users\scott\AppData\Roaming\npm\_mocha.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\scott\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\scott\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
at C:\Users\scott\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
at C:\Users\scott\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
but if I pass the full path to _mocha it works,
$ istanbul cover node_modules/mocha/bin/_mocha -- --recursive
Here are some details of what is installed on my system:
$ istanbul help 2>&1 |grep version
istanbul version:0.4.3
$ node -v
v4.4.4
$ npm --version
2.15.1
$ mocha --version
2.4.5
Could it be due to previously npm install -g mocha
and npm install -g istanbul
? The failing call stack is referencing the %APPDATA% paths of mocha and istanbul so maybe that is what is messed up?
$ where mocha
C:\Users\scott\AppData\Roaming\npm\mocha
C:\Users\scott\AppData\Roaming\npm\mocha.cmd
$ ls /c/Users/scott/AppData/Roaming/npm/node_modules/mocha/bin/
_mocha* mocha* options.js
$ where istanbul
C:\Users\scott\AppData\Roaming\npm\istanbul
C:\Users\scott\AppData\Roaming\npm\istanbul.cmd
$ where _mocha
C:\Users\scott\AppData\Roaming\npm\_mocha
C:\Users\scott\AppData\Roaming\npm\_mocha.cmd
$ ls ./node_modules/mocha/
bin/ images/ lib/ mocha.css node_modules/
CHANGELOG.md index.js LICENSE mocha.js package.json
$ ls ./node_modules/istanbul/
CHANGELOG.md index.js lib/ LICENSE node_modules/ package.json README.md
$ istanbul cover -v _mocha -- --recursive
Using configuration
-------------------
verbose: true
instrumentation:
root: .
extensions:
- .js
default-excludes: true
excludes: []
embed-source: false
variable: __coverage__
compact: true
preserve-comments: false
complete-copy: false
save-baseline: false
baseline-file: ./coverage/coverage-baseline.json
include-all-sources: false
include-pid: false
es-modules: false
preload-sources: false
reporting:
print: summary
reports:
- lcov
dir: ./coverage
watermarks:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
report-config:
clover: {file: clover.xml}
cobertura: {file: cobertura-coverage.xml}
json: {file: coverage-final.json}
json-summary: {file: coverage-summary.json}
lcovonly: {file: lcov.info}
teamcity: {file: null, blockName: Code Coverage Summary}
text: {file: null, maxCols: 0}
text-lcov: {file: lcov.info}
text-summary: {file: null}
hooks:
hook-run-in-context: false
post-require-hook: null
handle-sigint: false
check:
global:
statements: 0
lines: 0
branches: 0
functions: 0
excludes: []
each:
statements: 0
lines: 0
branches: 0
functions: 0
excludes: []
-------------------
Running: node C:\Users\scott\AppData\Roaming\npm\_mocha.CMD --recursive
No coverage information was collected, exit without writing coverage information
C:\Users\scott\AppData\Roaming\npm\_mocha.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\scott\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\scott\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
at C:\Users\scott\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
at C:\Users\scott\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
$ cat /c/Users/scott/AppData/Roaming/npm/_mocha.cmd
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\node_modules\mocha\bin\_mocha" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\node_modules\mocha\bin\_mocha" %*
)
$ cat /c/Users/scott/AppData/Roaming/npm/_mocha
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/node_modules/mocha/bin/_mocha" "$@"
ret=$?
else
node "$basedir/node_modules/mocha/bin/_mocha" "$@"
ret=$?
fi
exit $ret
$ uname
MINGW64_NT-10.0
Let me know if gathering any additional command output or file contents would be helpful.
[1] https://git-scm.com/download/win
from istanbul.
same as @scott-plutovr I alse see this error under git-bash
from istanbul.
and alternatives
I did not say that nvm can be used on Windows (in general).
from istanbul.
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
from 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 ;)
from istanbul.
Could you run istanbul cover -v
and paste the output just in case there is any additional info to be had from verbose logging?
from istanbul.
The output of -v
is exactly the same as above.
from istanbul.
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.
from istanbul.
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)
.
from istanbul.
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.
from istanbul.
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.
from istanbul.
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).
from istanbul.
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.
from istanbul.
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
from istanbul.
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
from istanbul.
Can you install the latest node on Windows and check it against that first? 0.6.11
is quite old ;)
from istanbul.
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)
from istanbul.
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.
from istanbul.
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
from istanbul.
right - describe
is added as a global by mocha.
from istanbul.
@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).
from istanbul.
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?
from istanbul.
@gotwarlost Thanks for the response. I just skimmed through the thread - silly me. Sorry for the inconvenience!
from istanbul.
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
from istanbul.
@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));
}
from istanbul.
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 # has no method 'isIdentifierPart']
//
//
No coverage information was collected, exit without writing coverage information
from istanbul.
That seems to be an error in parsing your Javascript. Are you sure it is well-formed?
from istanbul.
Yes it is well formed. will be a reason for node.js?
from istanbul.
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 () {...
from istanbul.
I tested and can confirm that it persists in istanbul 0.4.1
from istanbul.
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
from istanbul.
node -v
v6.2.2
npm -v
3.9.5
use istanbul as devDependencies. used script:
istanbul cover -x *.test.js node_modules/mocha/bin/_mocha -- -R spec src/index.test.js
it works!
from istanbul.
Still relevant.
from istanbul.
I also have this issue with node 10.1.0 on a windows machine.
from istanbul.
I guess we should setup appveyor and try to find solutions.
from istanbul.
It seems like this is working for node versions 6 and 8, but it doesn't work for node version 10. I had to uninstall 10.15.3 and revert back to 8.15.1.
from istanbul.
It seems like this is working for node versions 6 and 8, but it doesn't work for node version 10. I had to uninstall 10.15.3 and revert back to 8.15.1.
You can use nvm and alternatives to switch versions.
from istanbul.
It seems like this is working for node versions 6 and 8, but it doesn't work for node version 10. I had to uninstall 10.15.3 and revert back to 8.15.1.
You can use nvm and alternatives to switch versions.
NVM doesn't work for me on an x64 Windows 10 system. I'm noticing there's no stdout when I'm running my coverage combined with _mocha.
node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --harmony -- -R spec
produces the coverage results without outputting the describe and it blocks during testing.
from istanbul.
you could use npx node@8
to use node version 8 even when you have a different version installed. source
something like:
npx node@8 node_modules/istanbul/lib/cli.js cover *.test.js node_modules/mocha/bin/_mocha
from istanbul.
On WSL and Git Bash much more solutions should work.
from istanbul.
WSL is not Windows either.
from 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
We can test with Travis CI.
I will open a PR for this.
from istanbul.
@DanielRuf I don't think this repo is maintained.
According to the readme:
Deprecation Notice: this version of istanbul is deprecated, we will not be
landing pull requests or releasing new versions. But don't worry, the Istanbul 2.0
API is now available and is being actively developed
in the new istanbuljs organization.
from istanbul.
But I think it is better to use another code coverage solution (v8 internally provides this already).
The last (tagged) release was in 2016 and last commit in 2017:
https://github.com/gotwarlost/istanbul/releases.
According to the readme:
Deprecation Notice: this version of istanbul is deprecated, we will not be
landing pull requests or releasing new versions. But don't worry, the Istanbul 2.0
API is now available and is being actively developed
in the new istanbuljs organization.
Right, time to migrate then I guess. Was not clear enough in the readme.
from istanbul.
https://github.com/istanbuljs/nyc it is then.
from istanbul.
If you're having this issue and you're on a Windows machine, all you need to do is to specify the full path of mocha to istanbul like so;
istanbul cover node_modules/mocha/bin/_mocha
from istanbul.
Related Issues (20)
- ignore lines of code by specifying the line numbers HOT 1
- Function to string without istanbul in runtime HOT 1
- Looking for Constantinople.js HOT 1
- is it possible to apply the effect from /* istanbul ignore next */ to all typescript private methods automagically?
- option to disable coverage on import lines
- Open Coverage File Automatically on Test Command? HOT 2
- Branches that don't exist get reported as missing
- how to use istanbul as a library
- Analyzing coverage of node server in Windows HOT 1
- exclude imported node modules from coverage reporting HOT 1
- Cannot get the backend coverage by running Cypress UI e2e test HOT 1
- Ignore implied "else"
- Coverage format documentation not explicitly stating 'end' meaning HOT 1
- Istanbul doesn't ignore nested if, when not executed
- Async package is vulnerable
- Coverage not being collected from file called "payload.ts"
- Fails when running `istanbul report` HOT 1
- Unit test branch for SignInPage showing the SignUpComponent
- Ignore docs could be clarified by adding a list of allowed keywords
- Code comments are being covered.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from istanbul.