Skip to content

Commit

Permalink
Fixed elastic indexing problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ocinbat committed Nov 7, 2017
1 parent 06fe701 commit 7addb8e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
19 changes: 13 additions & 6 deletions lib/mochalastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,38 @@ module.exports = mochalastic;
function mochalastic(runner, options) {
mocha.reporters.Base.call(this, runner);
var reporterOptions = options.reporterOptions;
var currentDate = new Date().toISOString();

validate(reporterOptions, 'host');
validate(reporterOptions, 'port');
validate(reporterOptions, 'protocol');
validate(reporterOptions, 'username');
validate(reporterOptions, 'password');
validate(reporterOptions, 'project');
validate(reporterOptions, 'suite');

var self = this;
var tests = [];
var client = new elasticsearch.Client({

var elasticConfig = {
host: [{
host: reporterOptions.host,
auth: reporterOptions.username + ':' + reporterOptions.password,
protocol: reporterOptions.protocol,
port: reporterOptions.port
}],
log: 'error'
});
};

if (reporterOptions.username && reporterOptions.password) {
elasticConfig.host[0].auth = reporterOptions.username + ':' + reporterOptions.password;
}

var client = new elasticsearch.Client(elasticConfig);

var log = function log(testData) {
client.create({
index: 'test-data-index', // Get from config
type: 'mocha-test',
type: 'mocha-test-result',
id: testData.id,
timestamp: testData.time,
body: testData
}, function (error, response) {
console.log(error);
Expand Down Expand Up @@ -82,6 +88,7 @@ function mochalastic(runner, options) {
currentRetry: test.currentRetry(),
project: reporterOptions.project,
suite: reporterOptions.suite,
time: currentDate,
err: errorJSON(test.err || {})
};
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "mochalastic",
"version": "1.1.0",
"version": "1.1.1",
"engines": {
"node": ">=6.9.1"
},
"description": "mocha elasticsearch reporter.",
"main": "./lib/mochalastic.js",
"scripts": {
"build": "babel src -d lib",
"test": "npm run build && mocha --reporter spec",
"test": "npm run build && mocha --reporter spec --no-exit",
"cover": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec test/*"
},
"repository": {
Expand Down
21 changes: 14 additions & 7 deletions src/mochalastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@ function mochalastic(runner, options) {
validate(reporterOptions, 'host');
validate(reporterOptions, 'port');
validate(reporterOptions, 'protocol');
validate(reporterOptions, 'username');
validate(reporterOptions, 'password');
validate(reporterOptions, 'project');
validate(reporterOptions, 'suite');

var self = this;
var tests = [];
var client = new elasticsearch.Client({

var elasticConfig = {
host: [
{
host: reporterOptions.host,
auth: reporterOptions.username + ':' + reporterOptions.password,
protocol: reporterOptions.protocol,
port: reporterOptions.port
}
],
log: 'error'
});
};

if (reporterOptions.username && reporterOptions.password) {
elasticConfig.host[0].auth = reporterOptions.username + ':' + reporterOptions.password;
}

var client = new elasticsearch.Client(elasticConfig);

var log = function (testData) {
client.create({
index: 'test-data-index', // Get from config
type: 'mocha-test',
type: 'mocha-test-result',
id: testData.id,
timestamp: testData.time,
body: testData
}, function (error, response) {
console.log(error);
if (error) {
console.log(error);
}
});
};

Expand Down

0 comments on commit 7addb8e

Please sign in to comment.