Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #13

Open
davglass opened this issue Oct 19, 2012 · 49 comments
Open

Windows support #13

davglass opened this issue Oct 19, 2012 · 49 comments

Comments

@davglass
Copy link
Collaborator

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

> cpr@0.0.5 pretest c:\Users\YUI\Desktop\play\cpr
> jshint --config ./node_modules/yui-lint/jshint.json ./lib/


> cpr@0.0.5 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)
$
@gotwarlost
Copy link
Owner

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

@davglass
Copy link
Collaborator Author

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 ;)

@gotwarlost
Copy link
Owner

Could you run istanbul cover -v and paste the output just in case there is any additional info to be had from verbose logging?

@davglass
Copy link
Collaborator Author

The output of -v is exactly the same as above.

@davglass
Copy link
Collaborator Author

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.

@gotwarlost
Copy link
Owner

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).

@gotwarlost
Copy link
Owner

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.

@davglass
Copy link
Collaborator Author

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.

@davglass
Copy link
Collaborator Author

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).

@gotwarlost
Copy link
Owner

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.

@alessioalex
Copy link

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

@alessioalex
Copy link

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

@davglass
Copy link
Collaborator Author

Can you install the latest node on Windows and check it against that first? 0.6.11 is quite old ;)

@JogoShugh
Copy link

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)

@gotwarlost
Copy link
Owner

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.

@JogoShugh
Copy link

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

@gotwarlost
Copy link
Owner

right - describe is added as a global by mocha.

@paulbjensen
Copy link

@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).

@johanneslumpe
Copy link

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?

@gotwarlost
Copy link
Owner

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.

@johanneslumpe
Copy link

@gotwarlost Thanks for the response. I just skimmed through the thread - silly me. Sorry for the inconvenience!

@tbranyen
Copy link

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

@gamefreak
Copy link

@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));
}

@abhisekroy2002
Copy link

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

@gotwarlost
Copy link
Owner

That seems to be an error in parsing your Javascript. Are you sure it is well-formed?

@deltreey
Copy link

I tested and can confirm that it persists in istanbul 0.4.1

@ghost
Copy link

ghost commented May 23, 2016

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

@ghost
Copy link

ghost commented May 28, 2016

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

@UziTech
Copy link

UziTech commented Jun 29, 2016

Still an issue with

istanbul cover mocha

but

istanbul cover node_modules/mocha/bin/_mocha

works

@hausenism
Copy link

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!

@fruch
Copy link

fruch commented Oct 11, 2016

same as @scott-plutovr I alse see this error under git-bash

@DanielRuf
Copy link

Still relevant.

@ccoenen
Copy link

ccoenen commented May 15, 2018

I also have this issue with node 10.1.0 on a windows machine.

@DanielRuf
Copy link

I guess we should setup appveyor and try to find solutions.

generalov pushed a commit to generalov/gemini that referenced this issue Aug 28, 2018
@aspencerpsu
Copy link

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.

@DanielRuf
Copy link

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.

@aspencerpsu
Copy link

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.

@DanielRuf
Copy link

and alternatives

I did not say that nvm can be used on Windows (in general).

@UziTech
Copy link

UziTech commented Mar 21, 2019

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

@DanielRuf
Copy link

On WSL and Git Bash much more solutions should work.

@ccoenen
Copy link

ccoenen commented Mar 21, 2019

WSL is not Windows either.

@DanielRuf
Copy link

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.

@UziTech
Copy link

UziTech commented Mar 21, 2019

@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.

@DanielRuf
Copy link

#910

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.

@DanielRuf
Copy link

https://github.com/istanbuljs/nyc it is then.

@SirPhemmiey
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests