Initial unit tests (using Mocha and Chai asserts).
This commit is contained in:
@@ -34,6 +34,13 @@
|
||||
"define": true,
|
||||
"require": true,
|
||||
"Chromath": false,
|
||||
"setImmediate": true
|
||||
"setImmediate": true,
|
||||
"expect": true,
|
||||
"it": true,
|
||||
"describe": true,
|
||||
"sinon": true,
|
||||
"module": true,
|
||||
"beforeEach": true,
|
||||
"inject": true
|
||||
}
|
||||
}
|
||||
|
||||
39
Gruntfile.js
39
Gruntfile.js
@@ -40,11 +40,13 @@ module.exports = function(grunt) {
|
||||
|
||||
babel: {
|
||||
options: {
|
||||
sourceMap: true,
|
||||
presets: ["es2015"],
|
||||
plugins: ['transform-es2015-modules-systemjs', "transform-es2015-for-of"],
|
||||
presets: ["es2015"]
|
||||
},
|
||||
dist: {
|
||||
options: {
|
||||
sourceMap: true,
|
||||
plugins: ['transform-es2015-modules-systemjs', "transform-es2015-for-of"]
|
||||
},
|
||||
files: [{
|
||||
cwd: 'src',
|
||||
expand: true,
|
||||
@@ -57,6 +59,34 @@ module.exports = function(grunt) {
|
||||
dest: 'dist/'
|
||||
}]
|
||||
},
|
||||
distTestNoSystemJs: {
|
||||
files: [{
|
||||
cwd: 'src',
|
||||
expand: true,
|
||||
src: ['**/*.js'],
|
||||
dest: 'dist/test'
|
||||
}]
|
||||
},
|
||||
distTestsSpecsNoSystemJs: {
|
||||
files: [{
|
||||
expand: true,
|
||||
cwd: 'specs',
|
||||
src: ['**/*.js'],
|
||||
dest: 'dist/test/specs'
|
||||
}]
|
||||
}
|
||||
},
|
||||
|
||||
mochaTest: {
|
||||
test: {
|
||||
options: {
|
||||
reporter: 'spec'
|
||||
},
|
||||
src: [
|
||||
'dist/test/datasource-zabbix/specs/test-main.js',
|
||||
'dist/test/datasource-zabbix/specs/*_specs.js'
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
sass: {
|
||||
@@ -77,6 +107,7 @@ module.exports = function(grunt) {
|
||||
'copy:src_to_dist',
|
||||
'copy:pluginDef',
|
||||
'babel',
|
||||
'sass'
|
||||
'sass',
|
||||
'mochaTest'
|
||||
]);
|
||||
};
|
||||
|
||||
13
package.json
13
package.json
@@ -23,16 +23,23 @@
|
||||
"grunt-contrib-copy": "~0.8.2",
|
||||
"grunt-contrib-watch": "^0.6.1",
|
||||
"grunt-contrib-uglify": "~0.11.0",
|
||||
"grunt-mocha-test": "~0.12.7",
|
||||
"grunt-systemjs-builder": "^0.2.5",
|
||||
"load-grunt-tasks": "~3.2.0",
|
||||
"grunt-execute": "~0.2.2",
|
||||
"grunt-contrib-clean": "~0.6.0"
|
||||
"grunt-contrib-clean": "~0.6.0",
|
||||
"prunk": "~1.2.1",
|
||||
"jsdom": "~3.1.2",
|
||||
"q": "~1.4.1",
|
||||
"chai": "~3.5.0",
|
||||
"moment": "~2.14.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-plugin-transform-es2015-modules-systemjs": "^6.5.0",
|
||||
"babel-plugin-transform-es2015-for-of": "^6.5.0",
|
||||
"babel-plugin-transform-es2015-for-of": "^6.6.0",
|
||||
"babel-preset-es2015": "^6.5.0",
|
||||
"lodash": "~4.0.0"
|
||||
"lodash": "~4.0.0",
|
||||
"mocha": "^2.4.5"
|
||||
},
|
||||
"homepage": "http://grafana-zabbix.org"
|
||||
}
|
||||
|
||||
40
src/datasource-zabbix/specs/datasource_specs.js
Normal file
40
src/datasource-zabbix/specs/datasource_specs.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import {Datasource} from "../module";
|
||||
import Q from "q";
|
||||
|
||||
describe('ZabbixDatasource', function() {
|
||||
var ctx = {};
|
||||
|
||||
beforeEach(function() {
|
||||
ctx.instanceSettings = {
|
||||
jsonData: {
|
||||
username: 'zabbix',
|
||||
password: 'zabbix',
|
||||
trends: false
|
||||
}
|
||||
};
|
||||
ctx.$q = Q;
|
||||
ctx.templateSrv = {};
|
||||
ctx.alertSrv = {};
|
||||
ctx.zabbixAPIService = function() {};
|
||||
ctx.ZabbixCachingProxy = function() {};
|
||||
ctx.QueryProcessor = function() {};
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.$q, ctx.templateSrv, ctx.alertSrv,
|
||||
ctx.zabbixAPIService, ctx.ZabbixCachingProxy, ctx.QueryProcessor);
|
||||
});
|
||||
|
||||
describe('When querying data', function() {
|
||||
|
||||
it('should return an empty array when no targets are set', function(done) {
|
||||
var options = {
|
||||
targets: [],
|
||||
range: {from: null, to: null}
|
||||
};
|
||||
ctx.ds.query(options).then(function(result) {
|
||||
expect(result.data).to.have.length(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
43
src/datasource-zabbix/specs/test-main.js
Normal file
43
src/datasource-zabbix/specs/test-main.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// JSHint options
|
||||
/* globals global: false */
|
||||
|
||||
import prunk from 'prunk';
|
||||
import {jsdom} from 'jsdom';
|
||||
import chai from 'chai';
|
||||
|
||||
// Mock angular module
|
||||
var angularMocks = {
|
||||
module: function() {
|
||||
return {
|
||||
directive: function() {},
|
||||
service: function() {},
|
||||
factory: function() {}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var datemathMock = {
|
||||
parse: function() {}
|
||||
};
|
||||
|
||||
// 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('angular', angularMocks);
|
||||
prunk.mock('jquery', 'module not found');
|
||||
|
||||
// Setup jsdom
|
||||
// Required for loading angularjs
|
||||
global.document = jsdom('<html><head><script></script></head><body></body></html>');
|
||||
global.window = global.document.parentWindow;
|
||||
global.navigator = window.navigator = {};
|
||||
global.Node = window.Node;
|
||||
|
||||
// Setup Chai
|
||||
chai.should();
|
||||
global.assert = chai.assert;
|
||||
global.expect = chai.expect;
|
||||
Reference in New Issue
Block a user