# Git Pre-Commit with Newman Testing

**URL:** <https://community.postman.com/t/git-pre-commit-with-newman-testing/6076>\
**Category:** Help Hub\
**Created:** [June 24, 2019, 6:19pm UTC](https://community.postman.com/t/git-pre-commit-with-newman-testing/6076 "2019-06-24T18:19:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hoang\_Nguyen459](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Hoang\_Nguyen459](https://community.postman.com/u/Hoang_Nguyen459)\
**Post date:** [June 24, 2019, 6:19pm UTC](https://community.postman.com/t/git-pre-commit-with-newman-testing/6076/1 "2019-06-24T18:19:41Z")

</div>

Is there a way that I can trigger Newman to run prior git commit thus if collection runner test failed, git will not commit? Thank you very much.

---

<div class="post-metadata">

**Author:** ![Hoang\_Nguyen459](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Hoang\_Nguyen459](https://community.postman.com/u/Hoang_Nguyen459)\
**Post date:** [June 25, 2019, 2:44pm UTC](https://community.postman.com/t/git-pre-commit-with-newman-testing/6076/2 "2019-06-25T14:44:40Z")

</div>

Would some one help me please? Thank you very much.

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 25, 2019, 2:50pm UTC](https://community.postman.com/t/git-pre-commit-with-newman-testing/6076/3 "2019-06-25T14:50:51Z")

</div>

I know this thing exists?

> **[pre-commit](https://www.npmjs.com/package/pre-commit)**
>
> Automatically install pre-commit hooks for your npm modules.. Latest version: 1.2.2, last published: 7 years ago. Start using pre-commit in your project by running \`npm i pre-commit\`. There are 299 other projects in the npm registry using pre-commit.

I remember a dev talking about an NPM module that ran his unit tests before every commit and if the tests failed, the commit wouldn’t merge.

I assume this is the NPM module he was talking about.  
Again, I assume you can just give it another command to run prior to your commit. So you could effectively run your API tests via Newman prior to a commit.

---

<div class="post-metadata">

**Author:** ![Hoang\_Nguyen459](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Hoang\_Nguyen459](https://community.postman.com/u/Hoang_Nguyen459)\
**Post date:** [June 25, 2019, 4:13pm UTC](https://community.postman.com/t/git-pre-commit-with-newman-testing/6076/4 "2019-06-25T16:13:25Z")

</div>

Thank you sir very much for your help. With pre-commit, when I run git commit, it does run newman test as I expected. However in my newman I have 8 failed but git commit does not know about the newman test failures and complete git commit. Below is my nodejs code for newman test:

nemanTest.js

/\* eslint-disable func-names \*/  
‘use strict’;

const newman = require(‘newman’);

newman.run(  
{  
collection: require(’…/postman/1.0.1/req\_collection.json’),  
environment: require(’…/postman/1.0.1/dev\_environment.json’),  
globals: require(’…/postman/1.0.1/global-variables.json’),  
reporters: ‘cli’  
},  
function (err) {  
if (err) {  
console.log(‘Postman Collection Run Error’, err);  
}

```
console.log('Postman collection test complete!');

```

}  
);
