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

Preprocessor opens another Cypress instance when bundling #8634

Closed
bahmutov opened this issue Sep 21, 2020 · 12 comments · Fixed by #8826
Closed

Preprocessor opens another Cypress instance when bundling #8634

bahmutov opened this issue Sep 21, 2020 · 12 comments · Fixed by #8826
Assignees

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Sep 21, 2020

This issue happens in Cypress v5.0.0 and does not occur in v4.12.1

If you try to run Cypress tests in https://github.com/eggheadio/egghead-next then a curious thing happens: it pops a new Cypress instance while trying to bundle.

Recording: https://jumpshare.com/v/v5mfJi5QlSbsd7IpBFAb

@ctorresMural
Copy link

I have the same problem in cypress v5.0.2. It always opens multiple windows but never it run the tests.

@bahmutov
Copy link
Contributor Author

bahmutov commented Sep 23, 2020

Narrowed it down to these dependencies

  "dependencies": {
    "next": "^9.5.3"
  },
  "devDependencies": {
    "cypress": "5.2.0",
    "jest": "^26.4.2"
  }

and .babelrc file

{
  "presets": ["next/babel"],
  "plugins": ["istanbul"]
}
$ npm ls babel-plugin-istanbul
egghead-io-nextjs@0.1.0 /Users/gleb/git/egghead-next
└─┬ jest@26.4.2
  └─┬ @jest/core@26.4.2
    ├─┬ @jest/transform@26.3.0
    │ └── babel-plugin-istanbul@6.0.0 
    └─┬ jest-config@26.4.2
      └─┬ babel-jest@26.3.0
        └── babel-plugin-istanbul@6.0.0  deduped

Top level dependencies

$ npm ls --depth 0
egghead-io-nextjs@0.1.0 /Users/gleb/git/egghead-next
├── cypress@5.2.0
├── jest@26.4.2
├── next@9.5.3
├── UNMET PEER DEPENDENCY react@^16.6.0
└── UNMET PEER DEPENDENCY react-dom@^16.6.0

Behavior: when you click on the spec.js it opens second global instance of Cypress

Screen Shot 2020-09-23 at 2 21 44 PM

@bahmutov
Copy link
Contributor Author

Reproducible example in https://github.com/cypress-io/cypress-test-tiny/tree/open-global

  • clone repo
  • npm install
  • npx cypress open
  • click on the spec

See the second instance of Cypress open!

Relevant portion of the debug log

 cypress:server:cypress starting cypress with argv [ '/Users/gleb/Library/Caches/Cypress/5.2.0/Cypress.app/Contents/MacOS/Cypress', '/Users/gleb/git/cypress-test-tiny/node_modules/babel-plugin-istanbul/lib/load-nyc-config-sync.js', '/Users/gleb/git/cypress-test-tiny' ] +0ms
  cypress:server:args argv array: [ '/Users/gleb/Library/Caches/Cypress/5.2.0/Cypress.app/Contents/MacOS/Cypress', '/Users/gleb/git/cypress-test-tiny/node_modules/babel-plugin-istanbul/lib/load-nyc-config-sync.js', '/Users/gleb/git/cypress-test-tiny' ] +0ms
  cypress:server:args argv parsed: { _: [ '/Users/gleb/Library/Caches/Cypress/5.2.0/Cypress.app/Contents/MacOS/Cypress', '/Users/gleb/git/cypress-test-tiny/node_modules/babel-plugin-istanbul/lib/load-nyc-config-sync.js', '/Users/gleb/git/cypress-test-tiny' ], invokedFromCli: false, cwd: '/Users/gleb/Library/Caches/Cypress/5.2.0/Cypress.app/Contents/Resources/app/packages/server' }

@bahmutov bahmutov added the stage: needs investigating Someone from Cypress needs to look at this label Sep 23, 2020
@bahmutov
Copy link
Contributor Author

Traced it inside babel-plugin-istanbul to the function that loads the config like this

function loadNycConfig(cwd, opts) {
  ...
  const result = JSON.parse((0, _child_process.execFileSync)(process.execPath, args));
  ...
  return config;
}

Which in our case starts Cypress pointing at the args! For example if we print the args

console.log('about to execute')
console.log(process.execPath, args.join(' '))

we get

about to execute
/Users/gleb/Library/Caches/Cypress/5.2.0/Cypress.app/Contents/MacOS/Cypress 
  /Users/gleb/git/cypress-test-tiny/node_modules/babel-plugin-istanbul/lib/load-nyc-config-sync.js 
  /Users/gleb/git/cypress-test-tiny

Because it thinks it is executing inside Node, thus uses exec process to load other scripts as child processes. Should we separate every bundler better into a child process to solve this - because this one executes a child process inside a require.

@bahmutov bahmutov added stage: ready for work The issue is reproducible and in scope and removed stage: needs investigating Someone from Cypress needs to look at this labels Sep 23, 2020
@bahmutov
Copy link
Contributor Author

Note: using system Node is NOT a workaround. The setting below still opens Cypress while loading babel options

{
  "nodeVersion": "system"
}

@johnlindquist
Copy link

Is there any movement on this? Kinda waiting on it so we can switch back to v5...

@chrisbreiding
Copy link
Contributor

@johnlindquist I'm planning to look into this sometime in the next few days. Sorry for the inconvenience!

@nhynes
Copy link

nhynes commented Oct 11, 2020

@chrisbreiding thanks for looking into this. I'm getting the same issue using TS and Parcel without any explicit babel-plugin-istanbul. I'm also using route2, so I can't go back to 4.x.

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress labels Oct 13, 2020
@chrisbreiding
Copy link
Contributor

@bahmutov: Should we separate every bundler better into a child process to solve this - because this one executes a child process inside a require.

That's exactly what we need to do. We do this for user-registered preprocessors, but when the user has not registered a preprocessor, we register our own default preprocessor in the main Cypress process. I'm fixing this in #8826 by now registering the default preprocessor in the plugins child process as well.

@bahmutov
Copy link
Contributor Author

bahmutov commented Oct 13, 2020 via email

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

The code for this is done in cypress-io/cypress#8826, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Oct 14, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 14, 2020

Released in 5.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.4.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants