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

start-server-and-test is incompatible with husky #285

Open
mvasin opened this issue Oct 22, 2020 · 3 comments
Open

start-server-and-test is incompatible with husky #285

mvasin opened this issue Oct 22, 2020 · 3 comments

Comments

@mvasin
Copy link

mvasin commented Oct 22, 2020

Is this a bug report or a feature request?

If this is a bug report, please provide as much info as possible

  • version 1.11.5
  • platform macOS
  • expected behavior

I test a create-react-app-based app.

With this code in husky.config.js

module.exports = {
  hooks: {
    'pre-push': 'yarn start-server-and-test start http-get://localhost:3000 cy:run'
  }
}

I expect to run Cypress tests on git push.

  • actual behavior
Starting the development server...

Error: server closed unexpectedly
    at ChildProcess.onClose (/Users/foo/project/node_modules/start-server-and-test/src/index.js:69:14)
    at ChildProcess.emit (events.js:314:20)
    at maybeClose (internal/child_process.js:1047:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
error Command failed with exit code 1.

Fun fact: 'pre-push': 'sleep 10' does wait for 10 seconds before pushing to a git server. And time yarn start-server-and-test start http-get://localhost:3000 cy:run also confirms that the command works on its own and doesn't return to the terminal until the tests are done. But husky and start-server-and-test together somehow don't work. I also tried 'pre-push': 'bash -c "yarn start-server-and-test start http-get://localhost:3000 cy:run"' - that changed nothing.

@bcamarneiro
Copy link

Did you find any solution for this?

@mvasin
Copy link
Author

mvasin commented Dec 12, 2020

@bcamarneiro unfortunately not.

@marek-siemieniuk-morawski
Copy link

Hey, I had the same problem and I solved it. I'm not sure what's the root issue, but in my package.json there was:

"husky": {
    "hooks": {
      "pre-push": "yarn run test:cy -- --env configFile=local"
    }
},

and after removing -- --env configFile=local it started working.

Full package.json content:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {},
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "cy:run": "cypress run",
    "test:cy": "start-server-and-test start http://localhost:3000 cy:run"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ]
  },
  "husky": {
    "hooks": {
      "pre-push": "yarn run test:cy"
    }
  },
  "devDependencies": {
    "@types/fs-extra": "^9.0.6",
    "start-server-and-test": "^1.11.7"
  }
}

hopefully I helped

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

3 participants