Merge branch 'refactor-tests'
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
"require": true,
|
"require": true,
|
||||||
"Chromath": false,
|
"Chromath": false,
|
||||||
"setImmediate": true,
|
"setImmediate": true,
|
||||||
|
"jest": true,
|
||||||
"expect": true,
|
"expect": true,
|
||||||
"it": true,
|
"it": true,
|
||||||
"describe": true,
|
"describe": true,
|
||||||
|
|||||||
20
Gruntfile.js
20
Gruntfile.js
@@ -112,18 +112,6 @@ module.exports = function(grunt) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mochaTest: {
|
|
||||||
test: {
|
|
||||||
options: {
|
|
||||||
reporter: 'spec'
|
|
||||||
},
|
|
||||||
src: [
|
|
||||||
'dist/test/datasource-zabbix/specs/test-main.js',
|
|
||||||
'dist/test/datasource-zabbix/specs/*_specs.js'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
sass: {
|
sass: {
|
||||||
options: {
|
options: {
|
||||||
sourceMap: true
|
sourceMap: true
|
||||||
@@ -178,8 +166,7 @@ module.exports = function(grunt) {
|
|||||||
'copy',
|
'copy',
|
||||||
'jshint',
|
'jshint',
|
||||||
'jscs',
|
'jscs',
|
||||||
'babel',
|
'babel'
|
||||||
'mochaTest'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
grunt.registerTask('watchTask', [
|
grunt.registerTask('watchTask', [
|
||||||
@@ -193,12 +180,11 @@ module.exports = function(grunt) {
|
|||||||
'jscs'
|
'jscs'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
grunt.registerTask('test', [
|
grunt.registerTask('buildTest', [
|
||||||
'clean:test',
|
'clean:test',
|
||||||
'clean:tmp',
|
'clean:tmp',
|
||||||
'babel:distTestNoSystemJs',
|
'babel:distTestNoSystemJs',
|
||||||
'babel:distTestsSpecsNoSystemJs',
|
'babel:distTestsSpecsNoSystemJs'
|
||||||
'mochaTest'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
grunt.registerTask('bench', [
|
grunt.registerTask('bench', [
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ machine:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
override:
|
override:
|
||||||
- npm run build
|
- npm run ci-test
|
||||||
|
|||||||
11
codecov.yml
Normal file
11
codecov.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
coverage:
|
||||||
|
precision: 2
|
||||||
|
round: down
|
||||||
|
range: "50...100"
|
||||||
|
|
||||||
|
status:
|
||||||
|
project: yes
|
||||||
|
patch: yes
|
||||||
|
changes: no
|
||||||
|
|
||||||
|
comment: false
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import Q from "q";
|
||||||
import {Datasource} from "../module";
|
import {Datasource} from "../module";
|
||||||
import {zabbixTemplateFormat} from "../datasource";
|
import {zabbixTemplateFormat} from "../datasource";
|
||||||
import Q from "q";
|
|
||||||
import sinon from 'sinon';
|
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
describe('ZabbixDatasource', () => {
|
describe('ZabbixDatasource', () => {
|
||||||
let ctx = {};
|
let ctx = {};
|
||||||
let defined = sinon.match.defined;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.instanceSettings = {
|
ctx.instanceSettings = {
|
||||||
@@ -55,7 +53,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
range: {from: 'now-6h', to: 'now'}
|
range: {from: 'now-6h', to: 'now'}
|
||||||
};
|
};
|
||||||
ctx.ds.query(options).then(result => {
|
ctx.ds.query(options).then(result => {
|
||||||
expect(result.data).to.have.length(0);
|
expect(result.data.length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -65,12 +63,13 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
_.forEach(ranges, range => {
|
_.forEach(ranges, range => {
|
||||||
ctx.options.range.from = range;
|
ctx.options.range.from = range;
|
||||||
ctx.ds.queryNumericData = sinon.spy();
|
ctx.ds.queryNumericData = jest.fn();
|
||||||
ctx.ds.query(ctx.options);
|
ctx.ds.query(ctx.options);
|
||||||
|
|
||||||
// Check that useTrends options is true
|
// Check that useTrends options is true
|
||||||
expect(ctx.ds.queryNumericData)
|
let callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||||
.to.have.been.calledWith(defined, defined, true, sinon.match.any);
|
expect(callArgs[2]).toBe(true);
|
||||||
|
ctx.ds.queryNumericData.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
@@ -81,12 +80,13 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
_.forEach(ranges, range => {
|
_.forEach(ranges, range => {
|
||||||
ctx.options.range.from = range;
|
ctx.options.range.from = range;
|
||||||
ctx.ds.queryNumericData = sinon.spy();
|
ctx.ds.queryNumericData = jest.fn();
|
||||||
ctx.ds.query(ctx.options);
|
ctx.ds.query(ctx.options);
|
||||||
|
|
||||||
// Check that useTrends options is false
|
// Check that useTrends options is false
|
||||||
expect(ctx.ds.queryNumericData)
|
let callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||||
.to.have.been.calledWith(defined, defined, false, sinon.match.any);
|
expect(callArgs[2]).toBe(false);
|
||||||
|
ctx.ds.queryNumericData.mockClear();
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -101,7 +101,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = ctx.ds.replaceTemplateVars(target);
|
let result = ctx.ds.replaceTemplateVars(target);
|
||||||
expect(result).to.equal(expectedResult);
|
expect(result).toBe(expectedResult);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,10 +149,10 @@ describe('ZabbixDatasource', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.ds.replaceTemplateVars = (str) => str;
|
ctx.ds.replaceTemplateVars = (str) => str;
|
||||||
ctx.ds.zabbix = {
|
ctx.ds.zabbix = {
|
||||||
getGroups: () => Q.when([]),
|
getGroups: jest.fn().mockReturnValue(Q.when([])),
|
||||||
getHosts: () => Q.when([]),
|
getHosts: jest.fn().mockReturnValue(Q.when([])),
|
||||||
getApps: () => Q.when([]),
|
getApps: jest.fn().mockReturnValue(Q.when([])),
|
||||||
getItems: () => Q.when([])
|
getItems: jest.fn().mockReturnValue(Q.when([]))
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,66 +161,62 @@ describe('ZabbixDatasource', () => {
|
|||||||
{query: '*', expect: '/.*/'},
|
{query: '*', expect: '/.*/'},
|
||||||
{query: '', expect: ''},
|
{query: '', expect: ''},
|
||||||
{query: 'Backend', expect: 'Backend'},
|
{query: 'Backend', expect: 'Backend'},
|
||||||
{query: 'Back*', expect: 'Back*'}
|
{query: 'Back*', expect: 'Back*'},
|
||||||
];
|
];
|
||||||
|
|
||||||
let getGroups = sinon.spy(ctx.ds.zabbix, 'getGroups');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getGroups).to.have.been.calledWith(test.expect);
|
expect(ctx.ds.zabbix.getGroups).toBeCalledWith(test.expect);
|
||||||
getGroups.reset();
|
ctx.ds.zabbix.getGroups.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return hosts', (done) => {
|
it('should return hosts', (done) => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{query: '*.*', expect: '/.*/'},
|
{query: '*.*', expect: ['/.*/', '/.*/']},
|
||||||
{query: '.', expect: ''},
|
{query: '.', expect: ['', '']},
|
||||||
{query: 'Backend.*', expect: 'Backend'},
|
{query: 'Backend.*', expect: ['Backend', '/.*/']},
|
||||||
{query: 'Back*.', expect: 'Back*'}
|
{query: 'Back*.', expect: ['Back*', '']},
|
||||||
];
|
];
|
||||||
|
|
||||||
let getHosts = sinon.spy(ctx.ds.zabbix, 'getHosts');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getHosts).to.have.been.calledWith(test.expect);
|
expect(ctx.ds.zabbix.getHosts).toBeCalledWith(test.expect[0], test.expect[1]);
|
||||||
getHosts.reset();
|
ctx.ds.zabbix.getHosts.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return applications', (done) => {
|
it('should return applications', (done) => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{query: '*.*.*', expect: ['/.*/', '/.*/']},
|
{query: '*.*.*', expect: ['/.*/', '/.*/', '/.*/']},
|
||||||
{query: '.*.', expect: ['', '/.*/']},
|
{query: '.*.', expect: ['', '/.*/', '']},
|
||||||
{query: 'Backend.backend01.*', expect: ['Backend', 'backend01']},
|
{query: 'Backend.backend01.*', expect: ['Backend', 'backend01', '/.*/']},
|
||||||
{query: 'Back*.*.', expect: ['Back*', '/.*/']}
|
{query: 'Back*.*.', expect: ['Back*', '/.*/', '']}
|
||||||
];
|
];
|
||||||
|
|
||||||
let getApps = sinon.spy(ctx.ds.zabbix, 'getApps');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getApps).to.have.been.calledWith(test.expect[0], test.expect[1]);
|
expect(ctx.ds.zabbix.getApps).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2]);
|
||||||
getApps.reset();
|
ctx.ds.zabbix.getApps.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return items', (done) => {
|
it('should return items', (done) => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{query: '*.*.*.*', expect: ['/.*/', '/.*/', '']},
|
{query: '*.*.*.*', expect: ['/.*/', '/.*/', '', '/.*/']},
|
||||||
{query: '.*.*.*', expect: ['', '/.*/', '']},
|
{query: '.*.*.*', expect: ['', '/.*/', '', '/.*/']},
|
||||||
{query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '']},
|
{query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '', '/.*/']},
|
||||||
{query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu']}
|
{query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu', '/.*/']}
|
||||||
];
|
];
|
||||||
|
|
||||||
let getItems = sinon.spy(ctx.ds.zabbix, 'getItems');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getItems)
|
expect(ctx.ds.zabbix.getItems)
|
||||||
.to.have.been.calledWith(test.expect[0], test.expect[1], test.expect[2]);
|
.toBeCalledWith(test.expect[0], test.expect[1], test.expect[2], test.expect[3]);
|
||||||
getItems.reset();
|
ctx.ds.zabbix.getItems.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -228,9 +224,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
it('should invoke method with proper arguments', (done) => {
|
it('should invoke method with proper arguments', (done) => {
|
||||||
let query = '*.*';
|
let query = '*.*';
|
||||||
|
|
||||||
let getHosts = sinon.spy(ctx.ds.zabbix, 'getHosts');
|
|
||||||
ctx.ds.metricFindQuery(query);
|
ctx.ds.metricFindQuery(query);
|
||||||
expect(getHosts).to.have.been.calledWith('/.*/');
|
expect(ctx.ds.zabbix.getHosts).toBeCalledWith('/.*/', '/.*/');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -277,8 +272,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds).toHaveLength(1);
|
||||||
expect(resp.thresholds[0]).to.equal(100);
|
expect(resp.thresholds[0]).toBe(100);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -295,8 +290,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(100);
|
expect(resp.thresholds[0]).toBe(100);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -313,8 +308,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(30);
|
expect(resp.thresholds[0]).toBe(30);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -331,8 +326,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(50);
|
expect(resp.thresholds[0]).toBe(50);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
50
dist/datasource-zabbix/specs/test-main.js
vendored
50
dist/datasource-zabbix/specs/test-main.js
vendored
@@ -1,50 +0,0 @@
|
|||||||
// JSHint options
|
|
||||||
/* globals global: false */
|
|
||||||
|
|
||||||
import prunk from 'prunk';
|
|
||||||
import {JSDOM} from 'jsdom';
|
|
||||||
import chai from 'chai';
|
|
||||||
// import sinon from 'sinon';
|
|
||||||
import sinonChai from 'sinon-chai';
|
|
||||||
import * as dateMath from './modules/datemath';
|
|
||||||
|
|
||||||
// Mock angular module
|
|
||||||
var angularMocks = {
|
|
||||||
module: function() {
|
|
||||||
return {
|
|
||||||
directive: function() {},
|
|
||||||
service: function() {},
|
|
||||||
factory: function() {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var datemathMock = {
|
|
||||||
parse: dateMath.parse,
|
|
||||||
parseDateMath: dateMath.parseDateMath,
|
|
||||||
isValid: dateMath.isValid
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock Grafana modules that are not available outside of the core project
|
|
||||||
// Required for loading module.js
|
|
||||||
prunk.mock('./css/query-editor.css!', 'no css, dude.');
|
|
||||||
prunk.mock('app/plugins/sdk', {
|
|
||||||
QueryCtrl: null
|
|
||||||
});
|
|
||||||
prunk.mock('app/core/utils/datemath', datemathMock);
|
|
||||||
prunk.mock('app/core/table_model', {});
|
|
||||||
prunk.mock('angular', angularMocks);
|
|
||||||
prunk.mock('jquery', 'module not found');
|
|
||||||
|
|
||||||
// Required for loading angularjs
|
|
||||||
let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
|
||||||
// Setup jsdom
|
|
||||||
global.window = dom.window;
|
|
||||||
global.document = global.window.document;
|
|
||||||
global.Node = window.Node;
|
|
||||||
|
|
||||||
// Setup Chai
|
|
||||||
chai.should();
|
|
||||||
chai.use(sinonChai);
|
|
||||||
global.assert = chai.assert;
|
|
||||||
global.expect = chai.expect;
|
|
||||||
@@ -13,7 +13,7 @@ describe('timeseries processing functions', () => {
|
|||||||
let expected = [[2, 1], [4, 2], [5, 3]];
|
let expected = [[2, 1], [4, 2], [5, 3]];
|
||||||
|
|
||||||
let result = ts.sumSeries(series);
|
let result = ts.sumSeries(series);
|
||||||
expect(result).to.eql(expected);
|
expect(result).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ describe('timeseries processing functions', () => {
|
|||||||
let expected = [[1, 1], [4, 2], [5, 3]];
|
let expected = [[1, 1], [4, 2], [5, 3]];
|
||||||
|
|
||||||
let result = ts.sumSeries(series);
|
let result = ts.sumSeries(series);
|
||||||
expect(result).to.eql(expected);
|
expect(result).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -26,7 +26,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -57,7 +57,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -83,7 +83,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -106,7 +106,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||||
expect(splitQuery).to.eql(test_case.expected);
|
expect(splitQuery).toEqual(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -133,7 +133,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||||
expect(splitQuery).to.eql(test_case.expected);
|
expect(splitQuery).toEqual(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
1
dist/test-setup/cssStub.js
vendored
Normal file
1
dist/test-setup/cssStub.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {};
|
||||||
50
dist/test-setup/jest-setup.js
vendored
Normal file
50
dist/test-setup/jest-setup.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// JSHint options
|
||||||
|
/* globals global: false */
|
||||||
|
|
||||||
|
import {JSDOM} from 'jsdom';
|
||||||
|
|
||||||
|
// Mock Grafana modules that are not available outside of the core project
|
||||||
|
// Required for loading module.js
|
||||||
|
jest.mock('angular', () => {
|
||||||
|
return {
|
||||||
|
module: function() {
|
||||||
|
return {
|
||||||
|
directive: function() {},
|
||||||
|
service: function() {},
|
||||||
|
factory: function() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('app/plugins/sdk', () => {
|
||||||
|
return {
|
||||||
|
QueryCtrl: null
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('app/core/utils/datemath', () => {
|
||||||
|
const datemath = require('./modules/datemath');
|
||||||
|
return {
|
||||||
|
parse: datemath.parse,
|
||||||
|
parseDateMath: datemath.parseDateMath,
|
||||||
|
isValid: datemath.isValid
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('app/core/table_model', () => {
|
||||||
|
return {};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('./css/query-editor.css!', () => {
|
||||||
|
return "";
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('jquery', () => 'module not found', {virtual: true});
|
||||||
|
|
||||||
|
// Required for loading angularjs
|
||||||
|
let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
||||||
|
// Setup jsdom
|
||||||
|
global.window = dom.window;
|
||||||
|
global.document = global.window.document;
|
||||||
|
global.Node = window.Node;
|
||||||
@@ -1,26 +1,21 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _module = require("../module");
|
|
||||||
|
|
||||||
var _datasource = require("../datasource");
|
|
||||||
|
|
||||||
var _q = require("q");
|
|
||||||
|
|
||||||
var _q2 = _interopRequireDefault(_q);
|
|
||||||
|
|
||||||
var _sinon = require("sinon");
|
|
||||||
|
|
||||||
var _sinon2 = _interopRequireDefault(_sinon);
|
|
||||||
|
|
||||||
var _lodash = require("lodash");
|
var _lodash = require("lodash");
|
||||||
|
|
||||||
var _lodash2 = _interopRequireDefault(_lodash);
|
var _lodash2 = _interopRequireDefault(_lodash);
|
||||||
|
|
||||||
|
var _q = require("q");
|
||||||
|
|
||||||
|
var _q2 = _interopRequireDefault(_q);
|
||||||
|
|
||||||
|
var _module = require("../module");
|
||||||
|
|
||||||
|
var _datasource = require("../datasource");
|
||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
describe('ZabbixDatasource', function () {
|
describe('ZabbixDatasource', function () {
|
||||||
var ctx = {};
|
var ctx = {};
|
||||||
var defined = _sinon2.default.match.defined;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
ctx.instanceSettings = {
|
ctx.instanceSettings = {
|
||||||
@@ -71,7 +66,7 @@ describe('ZabbixDatasource', function () {
|
|||||||
range: { from: 'now-6h', to: 'now' }
|
range: { from: 'now-6h', to: 'now' }
|
||||||
};
|
};
|
||||||
ctx.ds.query(options).then(function (result) {
|
ctx.ds.query(options).then(function (result) {
|
||||||
expect(result.data).to.have.length(0);
|
expect(result.data.length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -81,11 +76,13 @@ describe('ZabbixDatasource', function () {
|
|||||||
|
|
||||||
_lodash2.default.forEach(ranges, function (range) {
|
_lodash2.default.forEach(ranges, function (range) {
|
||||||
ctx.options.range.from = range;
|
ctx.options.range.from = range;
|
||||||
ctx.ds.queryNumericData = _sinon2.default.spy();
|
ctx.ds.queryNumericData = jest.fn();
|
||||||
ctx.ds.query(ctx.options);
|
ctx.ds.query(ctx.options);
|
||||||
|
|
||||||
// Check that useTrends options is true
|
// Check that useTrends options is true
|
||||||
expect(ctx.ds.queryNumericData).to.have.been.calledWith(defined, defined, true, _sinon2.default.match.any);
|
var callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||||
|
expect(callArgs[2]).toBe(true);
|
||||||
|
ctx.ds.queryNumericData.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
@@ -96,11 +93,13 @@ describe('ZabbixDatasource', function () {
|
|||||||
|
|
||||||
_lodash2.default.forEach(ranges, function (range) {
|
_lodash2.default.forEach(ranges, function (range) {
|
||||||
ctx.options.range.from = range;
|
ctx.options.range.from = range;
|
||||||
ctx.ds.queryNumericData = _sinon2.default.spy();
|
ctx.ds.queryNumericData = jest.fn();
|
||||||
ctx.ds.query(ctx.options);
|
ctx.ds.query(ctx.options);
|
||||||
|
|
||||||
// Check that useTrends options is false
|
// Check that useTrends options is false
|
||||||
expect(ctx.ds.queryNumericData).to.have.been.calledWith(defined, defined, false, _sinon2.default.match.any);
|
var callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||||
|
expect(callArgs[2]).toBe(false);
|
||||||
|
ctx.ds.queryNumericData.mockClear();
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -114,7 +113,7 @@ describe('ZabbixDatasource', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var result = ctx.ds.replaceTemplateVars(target);
|
var result = ctx.ds.replaceTemplateVars(target);
|
||||||
expect(result).to.equal(expectedResult);
|
expect(result).toBe(expectedResult);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,25 +163,16 @@ describe('ZabbixDatasource', function () {
|
|||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
ctx.ds.zabbix = {
|
ctx.ds.zabbix = {
|
||||||
getGroups: function getGroups() {
|
getGroups: jest.fn().mockReturnValue(_q2.default.when([])),
|
||||||
return _q2.default.when([]);
|
getHosts: jest.fn().mockReturnValue(_q2.default.when([])),
|
||||||
},
|
getApps: jest.fn().mockReturnValue(_q2.default.when([])),
|
||||||
getHosts: function getHosts() {
|
getItems: jest.fn().mockReturnValue(_q2.default.when([]))
|
||||||
return _q2.default.when([]);
|
|
||||||
},
|
|
||||||
getApps: function getApps() {
|
|
||||||
return _q2.default.when([]);
|
|
||||||
},
|
|
||||||
getItems: function getItems() {
|
|
||||||
return _q2.default.when([]);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return groups', function (done) {
|
it('should return groups', function (done) {
|
||||||
var tests = [{ query: '*', expect: '/.*/' }, { query: '', expect: '' }, { query: 'Backend', expect: 'Backend' }, { query: 'Back*', expect: 'Back*' }];
|
var tests = [{ query: '*', expect: '/.*/' }, { query: '', expect: '' }, { query: 'Backend', expect: 'Backend' }, { query: 'Back*', expect: 'Back*' }];
|
||||||
|
|
||||||
var getGroups = _sinon2.default.spy(ctx.ds.zabbix, 'getGroups');
|
|
||||||
var _iteratorNormalCompletion = true;
|
var _iteratorNormalCompletion = true;
|
||||||
var _didIteratorError = false;
|
var _didIteratorError = false;
|
||||||
var _iteratorError = undefined;
|
var _iteratorError = undefined;
|
||||||
@@ -192,8 +182,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
var test = _step.value;
|
var test = _step.value;
|
||||||
|
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getGroups).to.have.been.calledWith(test.expect);
|
expect(ctx.ds.zabbix.getGroups).toBeCalledWith(test.expect);
|
||||||
getGroups.reset();
|
ctx.ds.zabbix.getGroups.mockClear();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError = true;
|
_didIteratorError = true;
|
||||||
@@ -214,9 +204,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return hosts', function (done) {
|
it('should return hosts', function (done) {
|
||||||
var tests = [{ query: '*.*', expect: '/.*/' }, { query: '.', expect: '' }, { query: 'Backend.*', expect: 'Backend' }, { query: 'Back*.', expect: 'Back*' }];
|
var tests = [{ query: '*.*', expect: ['/.*/', '/.*/'] }, { query: '.', expect: ['', ''] }, { query: 'Backend.*', expect: ['Backend', '/.*/'] }, { query: 'Back*.', expect: ['Back*', ''] }];
|
||||||
|
|
||||||
var getHosts = _sinon2.default.spy(ctx.ds.zabbix, 'getHosts');
|
|
||||||
var _iteratorNormalCompletion2 = true;
|
var _iteratorNormalCompletion2 = true;
|
||||||
var _didIteratorError2 = false;
|
var _didIteratorError2 = false;
|
||||||
var _iteratorError2 = undefined;
|
var _iteratorError2 = undefined;
|
||||||
@@ -226,8 +215,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
var test = _step2.value;
|
var test = _step2.value;
|
||||||
|
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getHosts).to.have.been.calledWith(test.expect);
|
expect(ctx.ds.zabbix.getHosts).toBeCalledWith(test.expect[0], test.expect[1]);
|
||||||
getHosts.reset();
|
ctx.ds.zabbix.getHosts.mockClear();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError2 = true;
|
_didIteratorError2 = true;
|
||||||
@@ -248,9 +237,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return applications', function (done) {
|
it('should return applications', function (done) {
|
||||||
var tests = [{ query: '*.*.*', expect: ['/.*/', '/.*/'] }, { query: '.*.', expect: ['', '/.*/'] }, { query: 'Backend.backend01.*', expect: ['Backend', 'backend01'] }, { query: 'Back*.*.', expect: ['Back*', '/.*/'] }];
|
var tests = [{ query: '*.*.*', expect: ['/.*/', '/.*/', '/.*/'] }, { query: '.*.', expect: ['', '/.*/', ''] }, { query: 'Backend.backend01.*', expect: ['Backend', 'backend01', '/.*/'] }, { query: 'Back*.*.', expect: ['Back*', '/.*/', ''] }];
|
||||||
|
|
||||||
var getApps = _sinon2.default.spy(ctx.ds.zabbix, 'getApps');
|
|
||||||
var _iteratorNormalCompletion3 = true;
|
var _iteratorNormalCompletion3 = true;
|
||||||
var _didIteratorError3 = false;
|
var _didIteratorError3 = false;
|
||||||
var _iteratorError3 = undefined;
|
var _iteratorError3 = undefined;
|
||||||
@@ -260,8 +248,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
var test = _step3.value;
|
var test = _step3.value;
|
||||||
|
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getApps).to.have.been.calledWith(test.expect[0], test.expect[1]);
|
expect(ctx.ds.zabbix.getApps).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2]);
|
||||||
getApps.reset();
|
ctx.ds.zabbix.getApps.mockClear();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError3 = true;
|
_didIteratorError3 = true;
|
||||||
@@ -282,9 +270,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return items', function (done) {
|
it('should return items', function (done) {
|
||||||
var tests = [{ query: '*.*.*.*', expect: ['/.*/', '/.*/', ''] }, { query: '.*.*.*', expect: ['', '/.*/', ''] }, { query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', ''] }, { query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu'] }];
|
var tests = [{ query: '*.*.*.*', expect: ['/.*/', '/.*/', '', '/.*/'] }, { query: '.*.*.*', expect: ['', '/.*/', '', '/.*/'] }, { query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '', '/.*/'] }, { query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu', '/.*/'] }];
|
||||||
|
|
||||||
var getItems = _sinon2.default.spy(ctx.ds.zabbix, 'getItems');
|
|
||||||
var _iteratorNormalCompletion4 = true;
|
var _iteratorNormalCompletion4 = true;
|
||||||
var _didIteratorError4 = false;
|
var _didIteratorError4 = false;
|
||||||
var _iteratorError4 = undefined;
|
var _iteratorError4 = undefined;
|
||||||
@@ -294,8 +281,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
var test = _step4.value;
|
var test = _step4.value;
|
||||||
|
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getItems).to.have.been.calledWith(test.expect[0], test.expect[1], test.expect[2]);
|
expect(ctx.ds.zabbix.getItems).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2], test.expect[3]);
|
||||||
getItems.reset();
|
ctx.ds.zabbix.getItems.mockClear();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_didIteratorError4 = true;
|
_didIteratorError4 = true;
|
||||||
@@ -318,9 +305,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
it('should invoke method with proper arguments', function (done) {
|
it('should invoke method with proper arguments', function (done) {
|
||||||
var query = '*.*';
|
var query = '*.*';
|
||||||
|
|
||||||
var getHosts = _sinon2.default.spy(ctx.ds.zabbix, 'getHosts');
|
|
||||||
ctx.ds.metricFindQuery(query);
|
ctx.ds.metricFindQuery(query);
|
||||||
expect(getHosts).to.have.been.calledWith('/.*/');
|
expect(ctx.ds.zabbix.getHosts).toBeCalledWith('/.*/', '/.*/');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -372,8 +358,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds).toHaveLength(1);
|
||||||
expect(resp.thresholds[0]).to.equal(100);
|
expect(resp.thresholds[0]).toBe(100);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -391,8 +377,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(100);
|
expect(resp.thresholds[0]).toBe(100);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -410,8 +396,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(30);
|
expect(resp.thresholds[0]).toBe(30);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -429,8 +415,8 @@ describe('ZabbixDatasource', function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return ctx.ds.alertQuery(options).then(function (resp) {
|
return ctx.ds.alertQuery(options).then(function (resp) {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(50);
|
expect(resp.thresholds[0]).toBe(50);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
67
dist/test/datasource-zabbix/specs/test-main.js
vendored
67
dist/test/datasource-zabbix/specs/test-main.js
vendored
@@ -1,67 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var _prunk = require('prunk');
|
|
||||||
|
|
||||||
var _prunk2 = _interopRequireDefault(_prunk);
|
|
||||||
|
|
||||||
var _jsdom = require('jsdom');
|
|
||||||
|
|
||||||
var _chai = require('chai');
|
|
||||||
|
|
||||||
var _chai2 = _interopRequireDefault(_chai);
|
|
||||||
|
|
||||||
var _sinonChai = require('sinon-chai');
|
|
||||||
|
|
||||||
var _sinonChai2 = _interopRequireDefault(_sinonChai);
|
|
||||||
|
|
||||||
var _datemath = require('./modules/datemath');
|
|
||||||
|
|
||||||
var dateMath = _interopRequireWildcard(_datemath);
|
|
||||||
|
|
||||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
||||||
|
|
||||||
// Mock angular module
|
|
||||||
|
|
||||||
// import sinon from 'sinon';
|
|
||||||
var angularMocks = {
|
|
||||||
module: function module() {
|
|
||||||
return {
|
|
||||||
directive: function directive() {},
|
|
||||||
service: function service() {},
|
|
||||||
factory: function factory() {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}; // JSHint options
|
|
||||||
/* globals global: false */
|
|
||||||
|
|
||||||
var datemathMock = {
|
|
||||||
parse: dateMath.parse,
|
|
||||||
parseDateMath: dateMath.parseDateMath,
|
|
||||||
isValid: dateMath.isValid
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock Grafana modules that are not available outside of the core project
|
|
||||||
// Required for loading module.js
|
|
||||||
_prunk2.default.mock('./css/query-editor.css!', 'no css, dude.');
|
|
||||||
_prunk2.default.mock('app/plugins/sdk', {
|
|
||||||
QueryCtrl: null
|
|
||||||
});
|
|
||||||
_prunk2.default.mock('app/core/utils/datemath', datemathMock);
|
|
||||||
_prunk2.default.mock('app/core/table_model', {});
|
|
||||||
_prunk2.default.mock('angular', angularMocks);
|
|
||||||
_prunk2.default.mock('jquery', 'module not found');
|
|
||||||
|
|
||||||
// Required for loading angularjs
|
|
||||||
var dom = new _jsdom.JSDOM('<html><head><script></script></head><body></body></html>');
|
|
||||||
// Setup jsdom
|
|
||||||
global.window = dom.window;
|
|
||||||
global.document = global.window.document;
|
|
||||||
global.Node = window.Node;
|
|
||||||
|
|
||||||
// Setup Chai
|
|
||||||
_chai2.default.should();
|
|
||||||
_chai2.default.use(_sinonChai2.default);
|
|
||||||
global.assert = _chai2.default.assert;
|
|
||||||
global.expect = _chai2.default.expect;
|
|
||||||
@@ -15,7 +15,7 @@ describe('timeseries processing functions', function () {
|
|||||||
var expected = [[2, 1], [4, 2], [5, 3]];
|
var expected = [[2, 1], [4, 2], [5, 3]];
|
||||||
|
|
||||||
var result = _timeseries2.default.sumSeries(series);
|
var result = _timeseries2.default.sumSeries(series);
|
||||||
expect(result).to.eql(expected);
|
expect(result).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ describe('timeseries processing functions', function () {
|
|||||||
var expected = [[1, 1], [4, 2], [5, 3]];
|
var expected = [[1, 1], [4, 2], [5, 3]];
|
||||||
|
|
||||||
var result = _timeseries2.default.sumSeries(series);
|
var result = _timeseries2.default.sumSeries(series);
|
||||||
expect(result).to.eql(expected);
|
expect(result).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -33,7 +33,7 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
_lodash2.default.each(test_cases, function (test_case) {
|
_lodash2.default.each(test_cases, function (test_case) {
|
||||||
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -59,7 +59,7 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
_lodash2.default.each(test_cases, function (test_case) {
|
_lodash2.default.each(test_cases, function (test_case) {
|
||||||
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -81,7 +81,7 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
_lodash2.default.each(test_cases, function (test_case) {
|
_lodash2.default.each(test_cases, function (test_case) {
|
||||||
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
var expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -101,7 +101,7 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
_lodash2.default.each(test_cases, function (test_case) {
|
_lodash2.default.each(test_cases, function (test_case) {
|
||||||
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||||
expect(splitQuery).to.eql(test_case.expected);
|
expect(splitQuery).toEqual(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -123,7 +123,7 @@ describe('Utils', function () {
|
|||||||
|
|
||||||
_lodash2.default.each(test_cases, function (test_case) {
|
_lodash2.default.each(test_cases, function (test_case) {
|
||||||
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||||
expect(splitQuery).to.eql(test_case.expected);
|
expect(splitQuery).toEqual(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
3
dist/test/test-setup/cssStub.js
vendored
Normal file
3
dist/test/test-setup/cssStub.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {};
|
||||||
52
dist/test/test-setup/jest-setup.js
vendored
Normal file
52
dist/test/test-setup/jest-setup.js
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var _jsdom = require('jsdom');
|
||||||
|
|
||||||
|
// Mock Grafana modules that are not available outside of the core project
|
||||||
|
// Required for loading module.js
|
||||||
|
jest.mock('angular', function () {
|
||||||
|
return {
|
||||||
|
module: function module() {
|
||||||
|
return {
|
||||||
|
directive: function directive() {},
|
||||||
|
service: function service() {},
|
||||||
|
factory: function factory() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, { virtual: true }); // JSHint options
|
||||||
|
/* globals global: false */
|
||||||
|
|
||||||
|
jest.mock('app/plugins/sdk', function () {
|
||||||
|
return {
|
||||||
|
QueryCtrl: null
|
||||||
|
};
|
||||||
|
}, { virtual: true });
|
||||||
|
|
||||||
|
jest.mock('app/core/utils/datemath', function () {
|
||||||
|
var datemath = require('./modules/datemath');
|
||||||
|
return {
|
||||||
|
parse: datemath.parse,
|
||||||
|
parseDateMath: datemath.parseDateMath,
|
||||||
|
isValid: datemath.isValid
|
||||||
|
};
|
||||||
|
}, { virtual: true });
|
||||||
|
|
||||||
|
jest.mock('app/core/table_model', function () {
|
||||||
|
return {};
|
||||||
|
}, { virtual: true });
|
||||||
|
|
||||||
|
jest.mock('./css/query-editor.css!', function () {
|
||||||
|
return "";
|
||||||
|
}, { virtual: true });
|
||||||
|
|
||||||
|
jest.mock('jquery', function () {
|
||||||
|
return 'module not found';
|
||||||
|
}, { virtual: true });
|
||||||
|
|
||||||
|
// Required for loading angularjs
|
||||||
|
var dom = new _jsdom.JSDOM('<html><head><script></script></head><body></body></html>');
|
||||||
|
// Setup jsdom
|
||||||
|
global.window = dom.window;
|
||||||
|
global.document = global.window.document;
|
||||||
|
global.Node = window.Node;
|
||||||
13
jest.config.js
Normal file
13
jest.config.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
"roots": [
|
||||||
|
"<rootDir>/dist/test"
|
||||||
|
],
|
||||||
|
"setupFiles": [
|
||||||
|
"<rootDir>/dist/test/test-setup/jest-setup.js"
|
||||||
|
],
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^[./a-zA-Z0-9$_-]+\.css\!?$": "<rootDir>/dist/test/test-setup/cssStub.js",
|
||||||
|
},
|
||||||
|
"coverageDirectory": "<rootDir>/tmp/coverage/",
|
||||||
|
"collectCoverage": false
|
||||||
|
};
|
||||||
22
package.json
22
package.json
@@ -4,9 +4,11 @@
|
|||||||
"version": "3.6.0",
|
"version": "3.6.0",
|
||||||
"description": "Zabbix plugin for Grafana",
|
"description": "Zabbix plugin for Grafana",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "./node_modules/.bin/grunt test",
|
"test": "./node_modules/.bin/grunt buildTest && jest",
|
||||||
"build": "./node_modules/.bin/grunt",
|
"build": "./node_modules/.bin/grunt && jest",
|
||||||
"watch": "./node_modules/.bin/grunt watch"
|
"watch": "./node_modules/.bin/grunt watch",
|
||||||
|
"codecov": "./node_modules/.bin/grunt && jest --coverage && codecov",
|
||||||
|
"ci-test": "./node_modules/.bin/grunt && jest --coverage && codecov"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -18,12 +20,13 @@
|
|||||||
"url": "https://github.com/alexanderzobnin/grafana-zabbix/issues"
|
"url": "https://github.com/alexanderzobnin/grafana-zabbix/issues"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel": "~6.5.1",
|
||||||
"babel-plugin-transform-es2015-for-of": "^6.6.0",
|
"babel-plugin-transform-es2015-for-of": "^6.6.0",
|
||||||
"babel-plugin-transform-es2015-modules-systemjs": "^6.5.0",
|
"babel-plugin-transform-es2015-modules-systemjs": "^6.5.0",
|
||||||
"babel-preset-es2015": "^6.5.0",
|
"babel-preset-es2015": "^6.5.0",
|
||||||
"babel": "~6.5.1",
|
"benchmark": "^2.1.4",
|
||||||
"benchmark":"^2.1.4",
|
"codecov": "^3.0.0",
|
||||||
"chai": "~3.5.0",
|
"grunt": "~0.4.5",
|
||||||
"grunt-babel": "~6.0.0",
|
"grunt-babel": "~6.0.0",
|
||||||
"grunt-benchmark": "^1.0.0",
|
"grunt-benchmark": "^1.0.0",
|
||||||
"grunt-cli": "~1.2.0",
|
"grunt-cli": "~1.2.0",
|
||||||
@@ -34,19 +37,14 @@
|
|||||||
"grunt-contrib-watch": "^0.6.1",
|
"grunt-contrib-watch": "^0.6.1",
|
||||||
"grunt-execute": "~0.2.2",
|
"grunt-execute": "~0.2.2",
|
||||||
"grunt-jscs": "^2.8.0",
|
"grunt-jscs": "^2.8.0",
|
||||||
"grunt-mocha-test": "~0.12.7",
|
|
||||||
"grunt-sass": "^1.1.0",
|
"grunt-sass": "^1.1.0",
|
||||||
"grunt-systemjs-builder": "^0.2.5",
|
"grunt-systemjs-builder": "^0.2.5",
|
||||||
"grunt": "~0.4.5",
|
"jest": "^21.2.1",
|
||||||
"jsdom": "~11.3.0",
|
"jsdom": "~11.3.0",
|
||||||
"jshint-stylish": "^2.1.0",
|
"jshint-stylish": "^2.1.0",
|
||||||
"load-grunt-tasks": "~3.2.0",
|
"load-grunt-tasks": "~3.2.0",
|
||||||
"mocha": "^2.4.5",
|
|
||||||
"moment": "~2.14.1",
|
"moment": "~2.14.1",
|
||||||
"prunk": "~1.2.1",
|
|
||||||
"q": "~1.4.1",
|
"q": "~1.4.1",
|
||||||
"sinon-chai": "~2.13.0",
|
|
||||||
"sinon":"^3.2.1",
|
|
||||||
"tether-drop": "^1.4.2"
|
"tether-drop": "^1.4.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import Q from "q";
|
||||||
import {Datasource} from "../module";
|
import {Datasource} from "../module";
|
||||||
import {zabbixTemplateFormat} from "../datasource";
|
import {zabbixTemplateFormat} from "../datasource";
|
||||||
import Q from "q";
|
|
||||||
import sinon from 'sinon';
|
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
describe('ZabbixDatasource', () => {
|
describe('ZabbixDatasource', () => {
|
||||||
let ctx = {};
|
let ctx = {};
|
||||||
let defined = sinon.match.defined;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.instanceSettings = {
|
ctx.instanceSettings = {
|
||||||
@@ -55,7 +53,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
range: {from: 'now-6h', to: 'now'}
|
range: {from: 'now-6h', to: 'now'}
|
||||||
};
|
};
|
||||||
ctx.ds.query(options).then(result => {
|
ctx.ds.query(options).then(result => {
|
||||||
expect(result.data).to.have.length(0);
|
expect(result.data.length).toBe(0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -65,12 +63,13 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
_.forEach(ranges, range => {
|
_.forEach(ranges, range => {
|
||||||
ctx.options.range.from = range;
|
ctx.options.range.from = range;
|
||||||
ctx.ds.queryNumericData = sinon.spy();
|
ctx.ds.queryNumericData = jest.fn();
|
||||||
ctx.ds.query(ctx.options);
|
ctx.ds.query(ctx.options);
|
||||||
|
|
||||||
// Check that useTrends options is true
|
// Check that useTrends options is true
|
||||||
expect(ctx.ds.queryNumericData)
|
let callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||||
.to.have.been.calledWith(defined, defined, true, sinon.match.any);
|
expect(callArgs[2]).toBe(true);
|
||||||
|
ctx.ds.queryNumericData.mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
done();
|
done();
|
||||||
@@ -81,12 +80,13 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
_.forEach(ranges, range => {
|
_.forEach(ranges, range => {
|
||||||
ctx.options.range.from = range;
|
ctx.options.range.from = range;
|
||||||
ctx.ds.queryNumericData = sinon.spy();
|
ctx.ds.queryNumericData = jest.fn();
|
||||||
ctx.ds.query(ctx.options);
|
ctx.ds.query(ctx.options);
|
||||||
|
|
||||||
// Check that useTrends options is false
|
// Check that useTrends options is false
|
||||||
expect(ctx.ds.queryNumericData)
|
let callArgs = ctx.ds.queryNumericData.mock.calls[0];
|
||||||
.to.have.been.calledWith(defined, defined, false, sinon.match.any);
|
expect(callArgs[2]).toBe(false);
|
||||||
|
ctx.ds.queryNumericData.mockClear();
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -101,7 +101,7 @@ describe('ZabbixDatasource', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = ctx.ds.replaceTemplateVars(target);
|
let result = ctx.ds.replaceTemplateVars(target);
|
||||||
expect(result).to.equal(expectedResult);
|
expect(result).toBe(expectedResult);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,10 +149,10 @@ describe('ZabbixDatasource', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.ds.replaceTemplateVars = (str) => str;
|
ctx.ds.replaceTemplateVars = (str) => str;
|
||||||
ctx.ds.zabbix = {
|
ctx.ds.zabbix = {
|
||||||
getGroups: () => Q.when([]),
|
getGroups: jest.fn().mockReturnValue(Q.when([])),
|
||||||
getHosts: () => Q.when([]),
|
getHosts: jest.fn().mockReturnValue(Q.when([])),
|
||||||
getApps: () => Q.when([]),
|
getApps: jest.fn().mockReturnValue(Q.when([])),
|
||||||
getItems: () => Q.when([])
|
getItems: jest.fn().mockReturnValue(Q.when([]))
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,66 +161,62 @@ describe('ZabbixDatasource', () => {
|
|||||||
{query: '*', expect: '/.*/'},
|
{query: '*', expect: '/.*/'},
|
||||||
{query: '', expect: ''},
|
{query: '', expect: ''},
|
||||||
{query: 'Backend', expect: 'Backend'},
|
{query: 'Backend', expect: 'Backend'},
|
||||||
{query: 'Back*', expect: 'Back*'}
|
{query: 'Back*', expect: 'Back*'},
|
||||||
];
|
];
|
||||||
|
|
||||||
let getGroups = sinon.spy(ctx.ds.zabbix, 'getGroups');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getGroups).to.have.been.calledWith(test.expect);
|
expect(ctx.ds.zabbix.getGroups).toBeCalledWith(test.expect);
|
||||||
getGroups.reset();
|
ctx.ds.zabbix.getGroups.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return hosts', (done) => {
|
it('should return hosts', (done) => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{query: '*.*', expect: '/.*/'},
|
{query: '*.*', expect: ['/.*/', '/.*/']},
|
||||||
{query: '.', expect: ''},
|
{query: '.', expect: ['', '']},
|
||||||
{query: 'Backend.*', expect: 'Backend'},
|
{query: 'Backend.*', expect: ['Backend', '/.*/']},
|
||||||
{query: 'Back*.', expect: 'Back*'}
|
{query: 'Back*.', expect: ['Back*', '']},
|
||||||
];
|
];
|
||||||
|
|
||||||
let getHosts = sinon.spy(ctx.ds.zabbix, 'getHosts');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getHosts).to.have.been.calledWith(test.expect);
|
expect(ctx.ds.zabbix.getHosts).toBeCalledWith(test.expect[0], test.expect[1]);
|
||||||
getHosts.reset();
|
ctx.ds.zabbix.getHosts.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return applications', (done) => {
|
it('should return applications', (done) => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{query: '*.*.*', expect: ['/.*/', '/.*/']},
|
{query: '*.*.*', expect: ['/.*/', '/.*/', '/.*/']},
|
||||||
{query: '.*.', expect: ['', '/.*/']},
|
{query: '.*.', expect: ['', '/.*/', '']},
|
||||||
{query: 'Backend.backend01.*', expect: ['Backend', 'backend01']},
|
{query: 'Backend.backend01.*', expect: ['Backend', 'backend01', '/.*/']},
|
||||||
{query: 'Back*.*.', expect: ['Back*', '/.*/']}
|
{query: 'Back*.*.', expect: ['Back*', '/.*/', '']}
|
||||||
];
|
];
|
||||||
|
|
||||||
let getApps = sinon.spy(ctx.ds.zabbix, 'getApps');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getApps).to.have.been.calledWith(test.expect[0], test.expect[1]);
|
expect(ctx.ds.zabbix.getApps).toBeCalledWith(test.expect[0], test.expect[1], test.expect[2]);
|
||||||
getApps.reset();
|
ctx.ds.zabbix.getApps.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return items', (done) => {
|
it('should return items', (done) => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{query: '*.*.*.*', expect: ['/.*/', '/.*/', '']},
|
{query: '*.*.*.*', expect: ['/.*/', '/.*/', '', '/.*/']},
|
||||||
{query: '.*.*.*', expect: ['', '/.*/', '']},
|
{query: '.*.*.*', expect: ['', '/.*/', '', '/.*/']},
|
||||||
{query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '']},
|
{query: 'Backend.backend01.*.*', expect: ['Backend', 'backend01', '', '/.*/']},
|
||||||
{query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu']}
|
{query: 'Back*.*.cpu.*', expect: ['Back*', '/.*/', 'cpu', '/.*/']}
|
||||||
];
|
];
|
||||||
|
|
||||||
let getItems = sinon.spy(ctx.ds.zabbix, 'getItems');
|
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
ctx.ds.metricFindQuery(test.query);
|
ctx.ds.metricFindQuery(test.query);
|
||||||
expect(getItems)
|
expect(ctx.ds.zabbix.getItems)
|
||||||
.to.have.been.calledWith(test.expect[0], test.expect[1], test.expect[2]);
|
.toBeCalledWith(test.expect[0], test.expect[1], test.expect[2], test.expect[3]);
|
||||||
getItems.reset();
|
ctx.ds.zabbix.getItems.mockClear();
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -228,9 +224,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
it('should invoke method with proper arguments', (done) => {
|
it('should invoke method with proper arguments', (done) => {
|
||||||
let query = '*.*';
|
let query = '*.*';
|
||||||
|
|
||||||
let getHosts = sinon.spy(ctx.ds.zabbix, 'getHosts');
|
|
||||||
ctx.ds.metricFindQuery(query);
|
ctx.ds.metricFindQuery(query);
|
||||||
expect(getHosts).to.have.been.calledWith('/.*/');
|
expect(ctx.ds.zabbix.getHosts).toBeCalledWith('/.*/', '/.*/');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -277,8 +272,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds).toHaveLength(1);
|
||||||
expect(resp.thresholds[0]).to.equal(100);
|
expect(resp.thresholds[0]).toBe(100);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -295,8 +290,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(100);
|
expect(resp.thresholds[0]).toBe(100);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -313,8 +308,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(30);
|
expect(resp.thresholds[0]).toBe(30);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -331,8 +326,8 @@ describe('ZabbixDatasource', () => {
|
|||||||
|
|
||||||
return ctx.ds.alertQuery(options)
|
return ctx.ds.alertQuery(options)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
expect(resp.thresholds.length).to.equal(1);
|
expect(resp.thresholds.length).toBe(1);
|
||||||
expect(resp.thresholds[0]).to.equal(50);
|
expect(resp.thresholds[0]).toBe(50);
|
||||||
return resp;
|
return resp;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// JSHint options
|
|
||||||
/* globals global: false */
|
|
||||||
|
|
||||||
import prunk from 'prunk';
|
|
||||||
import {JSDOM} from 'jsdom';
|
|
||||||
import chai from 'chai';
|
|
||||||
// import sinon from 'sinon';
|
|
||||||
import sinonChai from 'sinon-chai';
|
|
||||||
import * as dateMath from './modules/datemath';
|
|
||||||
|
|
||||||
// Mock angular module
|
|
||||||
var angularMocks = {
|
|
||||||
module: function() {
|
|
||||||
return {
|
|
||||||
directive: function() {},
|
|
||||||
service: function() {},
|
|
||||||
factory: function() {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var datemathMock = {
|
|
||||||
parse: dateMath.parse,
|
|
||||||
parseDateMath: dateMath.parseDateMath,
|
|
||||||
isValid: dateMath.isValid
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock Grafana modules that are not available outside of the core project
|
|
||||||
// Required for loading module.js
|
|
||||||
prunk.mock('./css/query-editor.css!', 'no css, dude.');
|
|
||||||
prunk.mock('app/plugins/sdk', {
|
|
||||||
QueryCtrl: null
|
|
||||||
});
|
|
||||||
prunk.mock('app/core/utils/datemath', datemathMock);
|
|
||||||
prunk.mock('app/core/table_model', {});
|
|
||||||
prunk.mock('angular', angularMocks);
|
|
||||||
prunk.mock('jquery', 'module not found');
|
|
||||||
|
|
||||||
// Required for loading angularjs
|
|
||||||
let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
|
||||||
// Setup jsdom
|
|
||||||
global.window = dom.window;
|
|
||||||
global.document = global.window.document;
|
|
||||||
global.Node = window.Node;
|
|
||||||
|
|
||||||
// Setup Chai
|
|
||||||
chai.should();
|
|
||||||
chai.use(sinonChai);
|
|
||||||
global.assert = chai.assert;
|
|
||||||
global.expect = chai.expect;
|
|
||||||
@@ -13,7 +13,7 @@ describe('timeseries processing functions', () => {
|
|||||||
let expected = [[2, 1], [4, 2], [5, 3]];
|
let expected = [[2, 1], [4, 2], [5, 3]];
|
||||||
|
|
||||||
let result = ts.sumSeries(series);
|
let result = ts.sumSeries(series);
|
||||||
expect(result).to.eql(expected);
|
expect(result).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ describe('timeseries processing functions', () => {
|
|||||||
let expected = [[1, 1], [4, 2], [5, 3]];
|
let expected = [[1, 1], [4, 2], [5, 3]];
|
||||||
|
|
||||||
let result = ts.sumSeries(series);
|
let result = ts.sumSeries(series);
|
||||||
expect(result).to.eql(expected);
|
expect(result).toEqual(expected);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -26,7 +26,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -57,7 +57,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -83,7 +83,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
let expandedName = utils.expandItemName(test_case.name, test_case.key);
|
||||||
expect(expandedName).to.equal(test_case.expected);
|
expect(expandedName).toBe(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -106,7 +106,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||||
expect(splitQuery).to.eql(test_case.expected);
|
expect(splitQuery).toEqual(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -133,7 +133,7 @@ describe('Utils', () => {
|
|||||||
|
|
||||||
_.each(test_cases, test_case => {
|
_.each(test_cases, test_case => {
|
||||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||||
expect(splitQuery).to.eql(test_case.expected);
|
expect(splitQuery).toEqual(test_case.expected);
|
||||||
});
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
1
src/test-setup/cssStub.js
Normal file
1
src/test-setup/cssStub.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {};
|
||||||
50
src/test-setup/jest-setup.js
Normal file
50
src/test-setup/jest-setup.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// JSHint options
|
||||||
|
/* globals global: false */
|
||||||
|
|
||||||
|
import {JSDOM} from 'jsdom';
|
||||||
|
|
||||||
|
// Mock Grafana modules that are not available outside of the core project
|
||||||
|
// Required for loading module.js
|
||||||
|
jest.mock('angular', () => {
|
||||||
|
return {
|
||||||
|
module: function() {
|
||||||
|
return {
|
||||||
|
directive: function() {},
|
||||||
|
service: function() {},
|
||||||
|
factory: function() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('app/plugins/sdk', () => {
|
||||||
|
return {
|
||||||
|
QueryCtrl: null
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('app/core/utils/datemath', () => {
|
||||||
|
const datemath = require('./modules/datemath');
|
||||||
|
return {
|
||||||
|
parse: datemath.parse,
|
||||||
|
parseDateMath: datemath.parseDateMath,
|
||||||
|
isValid: datemath.isValid
|
||||||
|
};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('app/core/table_model', () => {
|
||||||
|
return {};
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('./css/query-editor.css!', () => {
|
||||||
|
return "";
|
||||||
|
}, {virtual: true});
|
||||||
|
|
||||||
|
jest.mock('jquery', () => 'module not found', {virtual: true});
|
||||||
|
|
||||||
|
// Required for loading angularjs
|
||||||
|
let dom = new JSDOM('<html><head><script></script></head><body></body></html>');
|
||||||
|
// Setup jsdom
|
||||||
|
global.window = dom.window;
|
||||||
|
global.document = global.window.document;
|
||||||
|
global.Node = window.Node;
|
||||||
Reference in New Issue
Block a user