3.2.0 • Published 1 year ago

mocha-elk-reporter v3.2.0

Weekly downloads
28
License
MIT
Repository
-
Last release
1 year ago

Build Status

mocha-elk-reporter

A simple custom mocha reporter that sends Mocha Test results to Elastic search.

Purpose

  • Sending test results to Elastic Search helps collect test results over a period of time/multiple runs.
  • With Kibana you can create different visualizations to better understand the trends for test results.
  • This helps get better visibility, helps better measure reliability, understand cause of failures, measure speed etc. of the tests.

To learn more about ELK (Elastic Search, LogStash, Kibana). Click Here https://www.elastic.co/products/kibana

Usage

To use mocha-elk-reporter, add it as a 'devDependency' in your project

npm install --save-dev mocha-elk-reporter

Add a elk-reporter.js file to your project for your Elastic search instance

module.exports = {
  applicationName: "application name to be sent in the content of the tests",
  elasticSearchHost: "host name with port for your elastic search instance e.g. my-elasticsearch.com:9200, 10.10.1.100:9200",
  elasticSearchIndex: "indexName"
}

Mocha by default supports different kind of reporters like spec, json, etc. You can use this reporter similar to any other reporter by passing in additional command line arguments when running the tests using mocha. i.e.

--reporter mocha-elk-reporter

After you execute a test with additional parameters, you should now see data coming into your instance of ELK.

If there are issues with your configuration you should see appropriate logs associated with that

Advance Usage

Until this issue is resolved and PR merged in. If you want to use multiple reporters for your reporting needs e.g. spec, json, mocha-allure-reporter in conjunction with this reporter, you can do so with the help 'mocha multi' module.

To add that as a devDependency to your project

npm install --save-dev mocha-multi

Now you can run multiple reporters while running mocha tests uding this command

'multi="spec=- mocha-elk-reporter=-" mocha --reporter mocha-multi'

addContext Usage

If you are using mocha-multi-reporters with mochawesome and mochawesome's addContext functionality, any key-value pairs in 'value' will automatically get sent. For example here you would have myKey sent to ELK

addContext(this, { title: 'some text here', value: { myKey: "myValue" }});

You can also use addContext standalone without mochawesome using an exposed version. you call it like this:

const addContextMER = require('mocha-elk-reporter/addContext');

Then in your actual test use it with this format:

    it('it-test1', function() {
      assert.equal([1,2,3].indexOf(4), -1);
      addContextMER(this, { title: 'some text here', value: { myKey: "myValue" }});
    });
3.2.0

1 year ago

3.0.0-beta1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.6.1

3 years ago

2.6.0

3 years ago

2.6.0-beta1

3 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.3.0

4 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.2-beta13

5 years ago

2.0.2-beta3

5 years ago

2.0.2-beta2

5 years ago

2.0.2-beta1

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago