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

Failure to run coverage with ava when the path has a space #784

Closed
brogdonm opened this issue Feb 23, 2018 · 12 comments · Fixed by istanbuljs/spawn-wrap#98
Closed

Failure to run coverage with ava when the path has a space #784

brogdonm opened this issue Feb 23, 2018 · 12 comments · Fixed by istanbuljs/spawn-wrap#98

Comments

@brogdonm
Copy link

brogdonm commented Feb 23, 2018

Expected Behavior

When running (npm run test:cov) on a windows box with a home path of C:\Users\First Last\repo-name would expect the same type of behavior when the path does not have a space in it.

Observed Behavior

Currently, when I try to run I get an error on windows 'C:\Users\First' is not recognized as an internal or external command, indicating the spaces are not escaped correctly.

Bonus Points! Code (or Repository) that Reproduces Issue

The following is an excerpt from our package.json file:

"scripts": {
      "test": "cross-env BABEL_ENV=test ava",
      "test:cov": "nyc npm run test && nyc report --reporter=lcov"
},
  "ava": {
    "require": "babel-register",
    "babel": "inherit"
  },
  "nyc": {
    "sourceMap": false,
    "instrument": false
  },

Forensic Information

Windows 10 x64 machine
CWD = C:\Users\Michael Brogdon\repository-name

Version info:

node - v8.9.4
npm - 5.6.0
nyc - 11.4.0
ava - 0.24.0

@devMYC
Copy link

devMYC commented Mar 9, 2018

Also having a problem with include: [ "__tests__/**/*.js" ] in .nycrc result in empty coverage report. And it works fine without the underscores in the file path.

@nicolaspfernandes
Copy link

Have you found a solution for this issue? I'm getting it today.

@brogdonm
Copy link
Author

@nicolaspfernandes I haven't found a solution yet. Right now I have just worked around it by checking out in a path that does not have spaces.

@JeKachan
Copy link

The similar issue with path, but with testing child processes via require('child_process').spawn

@dagerikhl
Copy link

dagerikhl commented May 22, 2018

Facing the same issue when using a user with a space in the name, getting 'C:\Users\Dag' is not recognized as an internal or external command, operable program or batch file. when running nyc npm test --color.

The project itself is not placed on the path with a space, it's placed on another drive. But for some reason nyc accesses the C:\ path for something.

Same error found with CMD and PowerShell as well.

Windows 7 v. 6.1.7601 SP1 Build 7601
Git Bash for Windows v. GNU bash, version 4.3.42(5)-release (x86_64-pc-msys)
node v. 8.9.4
npm v. 5.6.0
nyc v. 11.4.1

No issue on my other computer running Windows 10, but that one doesn't have any spaces in the username.

@ShuratCode
Copy link

I have the same problem. The logs are:

12 info lifecycle [email protected]~coverage: Failed to exec coverage script
13 verbose stack Error: [email protected] coverage: cross-env NODE_ENV=coverage nyc --reporter=json-summary npm run test
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (C:\Users\Shaked Eyal\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:304:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess. (C:\Users\Shaked Eyal\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:962:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\genius8901-sqe-workshop-2018-exercise-1
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\Shaked Eyal\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "run" "coverage"
18 verbose node v10.13.0
19 verbose npm v6.1.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] coverage: cross-env NODE_ENV=coverage nyc --reporter=json-summary npm run test
22 error Exit status 1
23 error Failed at the [email protected] coverage script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

@ShuratCode
Copy link

I am looking into it

nrkn added a commit to entity-schema/json-schema-traverse that referenced this issue Dec 13, 2018
Can't call `nyc npm run test-spec` on a windows machine where the user folder contains a space due to nyc bug:

istanbuljs/nyc#784

package.json `script` was modified slightly to work around this without changing behaviour

Had to remove pre-commit hook due to windows issues
@stale stale bot added the stale label Feb 7, 2019
@pushkin-
Copy link

"Further activity" so this issue stays open

@stale stale bot removed the stale label Feb 13, 2019
@istanbuljs istanbuljs deleted a comment from stale bot Feb 13, 2019
@MarcusPope
Copy link

The issue is caused by node's os.homedir() function. The particular line to fix is here:

https://github.com/istanbuljs/nyc/blob/master/bin/nyc.js#L47

I would recommend using os.tmpdir() instead which automatically uses the 8.3 short name format (https://en.wikipedia.org/wiki/8.3_filename)

For those who need to get past this issue before a fix, you can assign the env var SPAWN_WRAP_SHIM_ROOT to some path without spaces, or use the tilde short name for a directory with spaces eg: C:\Program~1

Hope that helps!

@coreyfarrell
Copy link
Member

This seems to be a non-issue on Linux platforms? I just did the following:

mkdir 'this is a test'
cd 'this is a test'
npm init
npm i -D nyc
SPAWN_WRAP_SHIM_ROOT=$PWD npx nyc ls -lha

This correctly showed a .node-spawn-wrap-* folder. I also created a basic mytest.js:

#!/usr/bin/env node
console.log('hello');

Then ran:

chmod +x mytest.js
SPAWN_WRAP_SHIM_ROOT=$PWD npx nyc ./mytest.js

And this worked. So if this is a Windows specific issue maybe it could be fixed within spawn-wrap? If we need to switch from os.homedir() to os.tmpdir() I'd rather do it for affected platforms only. I'm concerned that on some Linux systems os.tmpdir() might be on a noexec mount or maybe SELinux might interfere.

@MarcusPope
Copy link

MarcusPope commented Jun 20, 2019

I agree with @coreyfarrell 's concerns and after doing a bit more research on the issue it appears that even tmpdir() wouldn't fix the problem because it is merely a pass-thru for whatever env var is already set (and tmpdir just happened to be in 8.3 format on my machine) (ref: Node Issue 17586)

I think the best course is to update the readme with notes about resolving this error with an env override for the user's home directory when it has either spaces or special characters in the username segment. I'll drop a PR in a bit.

Turns out the bug was fixable, PR to spawn-wrap is up - istanbuljs/spawn-wrap#98

MarcusPope added a commit to MarcusPope/spawn-wrap that referenced this issue Jun 28, 2019
demurgos added a commit to demurgos/spawn-wrap that referenced this issue Jul 8, 2019
coreyfarrell pushed a commit to istanbuljs/spawn-wrap that referenced this issue Jul 9, 2019
@brogdonm
Copy link
Author

brogdonm commented Jul 9, 2019

Thanks ya'll!!

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

Successfully merging a pull request may close this issue.

10 participants