question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot run component testing in pre-commit hook

See original GitHub issue

Current behavior

If I add “npx cypress run-ct” in .git/pre-commit and use default vs code git GUI to make a commit I get an error:

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -

> template@1.0.0 pre-commit
> npm run test-ci


> template@1.0.0 test-ci
> cross-env NODE_ENV=development cypress run-ct

We found an invalid configuration value:

Found an error while validating the `browsers` list. Expected `version` to be a non-empty string. Instead the value was: `{"name":"electron","channel":"stable","family":"chromium","displayName":"Electron","version":"","path":"","info":"Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses."}`
husky - pre-commit hook exited with code 1 (error)

Desired behavior

The hook runs with no errors

Test code to reproduce

I added husky to make it easier to run hooks (the problem can be reproduced without it)

How to reproduce:

  1. Clone Repo
  2. npm i
  3. npm set-script new “cypress run-ct” # make changes to repo
  4. use vs code (version 1.59, all extensions disabled) to commit changes and click “Show command output” image

Cypress Version

8.2.0

Other

If I change cypress version to 7.7.0 the error changes to something like this: “Cannot import module “–run-project”” If I run another command e.g. open-ct it succeeds If I commit without using VS Code git GUI then the hook with run-ct succeeds

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
a-zichcommented, Nov 5, 2021

I run into the same problem in VSCode. As @jennifer-shehane asked about the environment variables, I added an ‘export’ command before the test run. And yes, besided a lot of other stuff, it shows

export ELECTRON_RUN_AS_NODE=“1”

So VSCode sets this automatically.

I change my pre_commit file and it commited fine.

echo "***Running unit tests***"
unset ELECTRON_RUN_AS_NODE
npm test -- --config video=false screenshotOnRunFailure=false
0reactions
Omarov3000commented, Oct 15, 2021

I experience the same problem on MacOS. I have the similar log as @JessicaSachs has.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Precommit hook not triggering even after failures
If i dont add cross-env CI=true , the jest test cases wont break. I am trying to perform for both linting and unit...
Read more >
Supported hooks - pre-commit
php-unit - Run the full php unit test. Checks which PHPUnit executable is available first and then runs it. Preference order is vendor/bin,...
Read more >
How to lint and test your code using git pre-commit hooks
How to use Git hooks, husky and lint-staged to run scripts that run linting and testing tools before we make a commit or...
Read more >
Run tests | IntelliJ IDEA Documentation - JetBrains
When you want to check that your changes wouldn't break the code before committing them, you can do that by running tests as...
Read more >
How to run ESLint using a pre-commit hook - Level Up Coding
ESLint Git pre-commit hook · If you haven't initialized git for your repo then do so by running the command: git init ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found