score:-1
to do locally you can just write a script which first runs the tests and pipes the exit code and decides whether to really push or not based on the exit code.
by default npm test
runs in interactive mode
to exit after running the tests use ci=true
i.e. ci=true npm test
score:-1
this worked for me:
npm install --save-dev pre-commit
https://www.npmjs.com/package/pre-commit
then, in package.json
:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "ci=true react-scripts test", //<-- update
"eject": "react-scripts eject",
}
adding ci=true
runs all tests without making it interactive
finally,
"devdependencies": {
"pre-commit": "test"
}
score:0
maybe you can utilise some npm packages for this.
so, this is not a direct solution but you can include as many things you want instead of using git commands, shells and yml files
install package pre-commit and install git-cz from npm. using these you can make use of pre-commit and commit in package.json and desired things to them.
now you can make use of these packages in your packages.json like below
{
"start": "node index.js",
"pre-commit": "lint-staged",
"commit": "git-cz",
"lint": "eslint . --ext .js,.jsx",
}
for example you want to run test cases then pre-commit: npm run test && lint-staged
because in our project we needed to update documents, checking style-lint, eslint and test cases, so we were using these combination.
but you should not commit directly using git commit -m "message" but with npm run commit.
hope, this helps.
score:9
you need to use husky package. here is basic configuration (put it in package.json
). it adds pre-commit
hook to your git configuration.
"husky": {
"hooks": {
"pre-commit": "ci=true npm run test",
}
}
you can also consider using lint-staged to lint files which you commit. you can see full configuration here.
Source: stackoverflow.com
Related Query
- How to run tests before commit in create react app?
- How to run eslint in create react app
- How get window values in Tests with Enzyme, Jest + Create React App
- React SSR(Server Side Rendering) for SEO before login and after login Create React App (CRA). How to do this in one project folder?
- how do you deal with localstorage with tests in create react app withour ejecting?
- How to create a React app directly in the current folder
- How to create multiple page app using react
- How to not show warnings in Create React App
- Missing Script when I run npm start to create React app
- How to include custom JS files in to React create app
- How to run production react app in local with local back-end
- How to inject port and host using ENV variable in Create React App Proxy settings?
- How to fix TypeError _interopRequireDefault is not a function in Create React App
- How to use yarn to create a React app project?
- How to change PublicPath for Create React App in Dev Environment
- Create React App cannot find tests
- create react app : configure Jest : Run all test files
- How to run and debug a react app directly from VSCode?
- How to analyze create react app build size and reduce it?
- How to read console.log from a mounted component with Enzyme and Jest in Create React App
- How to import a file into a react app that uses create react app as raw text?
- create react app - npm run build issues
- how to use .env.qa or .env.staging with create react app
- How to make React Create App Production Error Boundary map to source code
- How to create a React App without Create-react-app
- Create react app - how to copy pdf.worker.js file from pdfjs-dist/build to your project's output folder?
- How to create react app without git (skipping git)?
- How to avoid very long paths and use absolute paths within a Create React App project?
- How to run ES6 React app in IE9 without errors
- how to config create react app with worker-loader
More Query from same tag
- How to tell different component when add to same listener in React
- Next js multiple dynamic pages
- How do I update an array using the useContext hook?
- create-react-app proxy request fails with 404 when backend is hosted on Azure
- Pulling out data from a nested Schema
- How to use react's reader in laravel
- How to resolve Typescript error -- mapbox-gl & React hooks
- Why ReactJs says "warning 'counter:' is defined but never used" but variable is used?
- Getting 'Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag' even when I use React.Fragment
- Progress Bar tied to a form
- Set React array state after promise all is completed
- Serving a static html page from a single page react app with react router
- Reading a topic of kafka with react
- How to show Error Message When someone leave Empty Fields
- react router and redux dispatch() is running from all routes once instead of only current route
- Why isn't my ReactJs App not updating correctly
- Using redux with Nextjs I don't understand why it requires more setup different than react app
- In useState is rendering but when i push to the same useState it doesnt
- How to rerender function component when id changed in url
- How to customise DialogTitle in material-ui
- SocketIo: Unable to emit event from react frontend to node backend
- Formik form not updating fields upon edit
- Refactoring how react/node handles response
- Redux-form 6.0.0 access error outside Field component
- How to render a video component in reactjs
- Showing data by React
- Using MockedProvider results in error "No more mocked reponses for the query" in jest-react
- Extracting styles in React + material-ui
- Create React App for multiple apps?
- React: how to open a new page without render SideBar component