Open badeball opened 1 month ago
@badeball
On Ubuntu 24.04.1
LTS with Node.js v18.20.4
(npm 10.7.0
) the command npm init -y
fails with
npm error Invalid name: "foo-&-bar"
when trying to initialize an npm-based project in a directory foo & bar
It's probably best to steer clear of project root directory names with an ampersand or spaces in them.
In your https://github.com/badeball/reproducible-issues/blob/master/cypress/unusual-characters-path/foo%20%26%20bar/package-lock.json you have an illegal name foo & bar
(see https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name for legal names):
{
"name": "foo & bar",
"lockfileVersion": 3,
however since the package.json
and package-lock.json
in this directory are out of sync, I couldn't test with npm ci
.
You might want to provide debug logs from your installation, however I don't suspect this is primarily a Cypress issue that you are seeing, although it's possible that it is an edge case.
On Windows, npx cypress
will not work at all in a directory foo & bar
. It tries to run cypress
from bar\node_modules\.bin\
and fails. You can work around this by not using npx
and calling ./node_modules/.bin/cypress
directly, however it should be expected that other calls which normally work would fail under this problematic directory name.
The name property of package-lock.json
is afaik, in the absence of a similar property in package.json
, inferred from the directory name. I'm literally outlining way of reproducing this involving directory name change, so of cource it's going to get out of sync. You can disable use of a locking file altogether if it makes things easier.
[..] although it's possible that it is an edge case.
It is.
I'm merely passing this on (from https://github.com/badeball/cypress-cucumber-preprocessor/issues/1232#issuecomment-2349311490). I don't actually have any vested interest in this myself.
@badeball
I'm merely passing this on (from badeball/cypress-cucumber-preprocessor#1232 (comment)). I don't actually have any vested interest in this myself.
Thanks for the reference to the original problem where the directory was P&D/frontend
and the package manager appears to be pnpm. Your example uses both spaces and an ampersand in the directory name, which causes additional npm problems on Windows.
I'm going to leave this now for the Cypress.io team to pick up if they think it should be prioritized.
FYI, I reproduced this using plain npm.
The original issue https://github.com/badeball/cypress-cucumber-preprocessor/issues/1232#issuecomment-2349311490 was running Cypress component testing with a parent directory containing an ampersand: P&D/frontend
which is one level higher than the Cypress project. The ampersand character was not in the directory immediately holding the Cypress project.
The repro https://github.com/badeball/reproducible-issues.git in cypress/unusual-characters-path/foo & bar
does demonstrate the issue, however it adds the challenge of having spaces and ampersand in the directory immediately holding the Cypress project. This can cause issues with package managers.
Renaming to cypress/unusual-characters&path/foo-and-bar
demonstrates the issue without causing package manager issues.
The test summary shows that the test spec is found, and not run (0ms and no test counts):
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ App.cy.js 0ms - - - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! 0ms - - - - -
In debug logs
cypress:server:reporter got mocha event 'start' with args: [ undefined ] +5ms
cypress:server:reporter got mocha event 'end' with args: [ undefined ] +0ms
is missing the following and other related reporter events, which are output if &
and spaces are removed from directory names:
cypress:server:reporter got mocha event 'suite' with args: [ p { title: '', ctx: {}, suites: [], tests: [ [u] ], pending: false, _beforeEach: [], _beforeAll: [], _afterEach: [], _afterAll: [], root: true, _timeout: 2000, _enableTimeouts: true, _slow: 250, _bail: false, _retries: -1, _onlyTests: [], _onlySuites: [], delayed: false, _events: [Object: null prototype] { newListener: [Function (anonymous)] }, _eventsCount: 1, file: 'cypress/component/App.cy.js', id: 'r1', type: 'suite' } ] +11ms
This issue, with an ampersand (&
) in a higher level parent directory, appears to affect only component testing, not E2E.
Using npx cypress open
shows that no tests were found even though the test spec was found and it does in fact contain tests. This happens when there is an ampersand character in a higher level directory containing the Cypress component test.
Current behavior
Component tests contained in a directory containing ampersand, fails to run ish, IE. no tests are picked up and Cypress exits with zero exit code. This can be seen using the repository mentioned below. Run it and see
0 passing
. Change the directory name (remove ampersand), run it again and see1 passing
.Desired behavior
No response
Test code to reproduce
https://github.com/badeball/reproducible-issues/tree/master/cypress/unusual-characters-path/foo%20%26%20bar
Cypress Version
13.14.2
Node version
v18.20.4
Operating System
Arch Linux
Debug Logs
No response
Other
No response