# How to unit test rules as part of CI/CD pipeline

**URL:** <https://community.auth0.com/t/how-to-unit-test-rules-as-part-of-ci-cd-pipeline/22424>\
**Category:** Get Help\
**Tags:** rules, auth0\
**Created:** [March 11, 2019, 2:15pm UTC](https://community.auth0.com/t/how-to-unit-test-rules-as-part-of-ci-cd-pipeline/22424 "2019-03-11T14:15:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumana.malkapuram](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sumana.malkapuram/32/33115_2.png) [@sumana.malkapuram](https://community.auth0.com/u/sumana.malkapuram)\
**Post date:** [March 11, 2019, 2:15pm UTC](https://community.auth0.com/t/how-to-unit-test-rules-as-part-of-ci-cd-pipeline/22424/1 "2019-03-11T14:15:31Z")

</div>

Do we have any method to unit test just rules, as we have deprecated webtasks.

The docs used to point to this module [https://www.npmjs.com/package/auth0-rules-testharness](https://www.npmjs.com/package/auth0-rules-testharness) with this sample ([GitHub - tawawa/auth0-rules-testharness-sample: Seed project for auth0-rules-testharness to help users get started immediately · GitHub](https://github.com/tawawa/auth0-rules-testharness-sample)), but both rely on a webtask token.

> _This question comes from a Professional Services customer_

---

<div class="post-metadata">

**Author:** ![sumana.malkapuram](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sumana.malkapuram/32/33115_2.png) [@sumana.malkapuram](https://community.auth0.com/u/sumana.malkapuram)\
**Post date:** [March 11, 2019, 2:27pm UTC](https://community.auth0.com/t/how-to-unit-test-rules-as-part-of-ci-cd-pipeline/22424/2 "2019-03-11T14:27:49Z")

</div>

There are two ways:

1. The NPM package ( [auth0-rules-testharness - npm](https://www.npmjs.com/package/auth0-rules-testharness)) is quite simple and can be modified to run a rule locally and not in the webtask sandbox.  
The [auth0-rules-local-testharness](https://github.com/auth0/auth0-rules-local-testharness) library provides an easy way to deploy, execute, and test the output of Auth0 Rules using a local sandbox environment without modifying the actual rule.

2. You can wrap the rule in a simple anonymous function which immediately executes. This function will return the rule as CommonJS module if the code is invoked from module system.  
This enables you to load the rule in your tests using standard **require(‘debug\_rule’)** statement and you can use packages like [nock](https://www.npmjs.com/package/nock) to mock http requests etc. However, this requires you to modify the rule.

**`debug_rule.js`**

```auto
(()=>{
  function rule(user, context, callback) {
    request.post({
      url: 'https://requestbin.com/zumtg7zu',
      json: {
        user: user,
        context: context,
      },
      timeout: 15000
    }, function(err, response, body){
      if (err) return callback(new Error(err));
      return callback(null, user, context);
    });
  }
   
  if (module) {
    module.exports = rule;
  }
   
  return rule;
   
})()

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 11, 2019, 3:21pm UTC](https://community.auth0.com/t/how-to-unit-test-rules-as-part-of-ci-cd-pipeline/22424/3 "2019-03-11T15:21:46Z")

</div>

Thanks a lot @sumana.malkapuram for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![sumana.malkapuram](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sumana.malkapuram/32/33115_2.png) [@sumana.malkapuram](https://community.auth0.com/u/sumana.malkapuram)\
**Post date:** [March 26, 2019, 3:21pm UTC](https://community.auth0.com/t/how-to-unit-test-rules-as-part-of-ci-cd-pipeline/22424/4 "2019-03-26T15:21:47Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
