updated test cases and instructions on how to install jasmine-node with the newest jasmine
BrainDoctor committed
Jul 18, 2017 at 14:58 UTC
64f6191801edbdd2cf3d15178a8fdef879cd574c
3 files changed
+13
-13
package.json
-1
@@ -2,7 +2,6 @@
2
"devDependencies": {
3
"jasmine": "^2.6.0",
4
"jasmine-core": "^2.6.4",
5
- "jasmine-node": "^1.14.5",
5
"karma": "^1.7.0",
6
"karma-chrome-launcher": "^2.2.0",
7
"karma-coverage": "^1.1.1",
tests/README.md
+2
-1
@@ -12,8 +12,9 @@ Make sure you are the user who is developer (permissions, except sudo ofc)
12
sudo apt-get install nodejs npm chromium-browser
13
14
cd /path/to/your/netdata
15
-
15
npm install
16
+cd node_modules
17
+git clone https://github.com/BrainDoctor/jasmine-node.git
18
```
19
20
That should install the necessary node modules.
tests/node.d/fronius.spec.js
+11
-11
@@ -6,8 +6,9 @@ var fronius = require("../../node.d/fronius.node");
6
7
describe("fronius chart creation", function () {
8
9
- beforeEach(function () {
10
- netdata.options.DEBUG = true;
9
+ beforeAll(function () {
10
+ // change this to enable debug log
11
+ netdata.options.DEBUG = false;
12
});
13
14
it("should return a basic chart definition", function () {
@@ -23,7 +24,7 @@ describe("fronius chart creation", function () {
24
it("will fail", function () {
25
netdata.debug("test");
26
26
- throw new Error("expected failure to test unit test runner");
27
+ throw new Error("demonstrate failure of unit test runner");
28
});
29
30
});
@@ -35,7 +36,11 @@ describe("fronius data parsing", function () {
36
module: this
37
});
38
38
- beforeEach(function () {
39
+ // this is a faked JSON response from the server.
40
+ // Used with freeformatter.com/json-escape.html to escape the json and turn it into a string.
41
+ var fakeResponse = "{\r\n\t\"Head\" : {\r\n\t\t\"RequestArguments\" : {},\r\n\t\t\"Status\" : {\r\n\t\t\t\"Code\" : 0,\r\n\t\t\t\"Reason\" : \"\",\r\n\t\t\t\"UserMessage\" : \"\"\r\n\t\t},\r\n\t\t\"Timestamp\" : \"2017-07-17T16:01:04+02:00\"\r\n\t},\r\n\t\"Body\" : {\r\n\t\t\"Data\" : {\r\n\t\t\t\"Site\" : {\r\n\t\t\t\t\"Mode\" : \"meter\",\r\n\t\t\t\t\"P_Grid\" : -3430.729923,\r\n\t\t\t\t\"P_Load\" : -910.270077,\r\n\t\t\t\t\"P_Akku\" : null,\r\n\t\t\t\t\"P_PV\" : 4341,\r\n\t\t\t\t\"rel_SelfConsumption\" : 20.969133,\r\n\t\t\t\t\"rel_Autonomy\" : 100,\r\n\t\t\t\t\"E_Day\" : 57230,\r\n\t\t\t\t\"E_Year\" : 6425915.5,\r\n\t\t\t\t\"E_Total\" : 15388710,\r\n\t\t\t\t\"Meter_Location\" : \"grid\"\r\n\t\t\t},\r\n\t\t\t\"Inverters\" : {\r\n\t\t\t\t\"1\" : {\r\n\t\t\t\t\t\"DT\" : 123,\r\n\t\t\t\t\t\"P\" : 4341,\r\n\t\t\t\t\t\"E_Day\" : 57230,\r\n\t\t\t\t\t\"E_Year\" : 6425915.5,\r\n\t\t\t\t\t\"E_Total\" : 15388710\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"
42
+
43
+ beforeAll(function () {
44
// change this to enable debug log
45
netdata.options.DEBUG = false;
46
});
@@ -44,15 +49,10 @@ describe("fronius data parsing", function () {
49
// arrange
50
netdata.send = jasmine.createSpy("send");
51
// act
47
- fronius.processResponse(service, createFakeResponse());
48
- var result = netdata.send.calls[0].args[0];
52
+ fronius.processResponse(service, fakeResponse);
53
+ var result = netdata.send.calls.argsFor(0)[0];
54
// assert
55
expect(result).toContain("SET p_grid = -3431");
56
});
57
53
- function createFakeResponse() {
54
- // this is a faked JSON response from the server.
55
- // Used with freeformatter.com/json-escape.html to escape the json and turn it into a string.
56
- return "{\r\n\t\"Head\" : {\r\n\t\t\"RequestArguments\" : {},\r\n\t\t\"Status\" : {\r\n\t\t\t\"Code\" : 0,\r\n\t\t\t\"Reason\" : \"\",\r\n\t\t\t\"UserMessage\" : \"\"\r\n\t\t},\r\n\t\t\"Timestamp\" : \"2017-07-17T16:01:04+02:00\"\r\n\t},\r\n\t\"Body\" : {\r\n\t\t\"Data\" : {\r\n\t\t\t\"Site\" : {\r\n\t\t\t\t\"Mode\" : \"meter\",\r\n\t\t\t\t\"P_Grid\" : -3430.729923,\r\n\t\t\t\t\"P_Load\" : -910.270077,\r\n\t\t\t\t\"P_Akku\" : null,\r\n\t\t\t\t\"P_PV\" : 4341,\r\n\t\t\t\t\"rel_SelfConsumption\" : 20.969133,\r\n\t\t\t\t\"rel_Autonomy\" : 100,\r\n\t\t\t\t\"E_Day\" : 57230,\r\n\t\t\t\t\"E_Year\" : 6425915.5,\r\n\t\t\t\t\"E_Total\" : 15388710,\r\n\t\t\t\t\"Meter_Location\" : \"grid\"\r\n\t\t\t},\r\n\t\t\t\"Inverters\" : {\r\n\t\t\t\t\"1\" : {\r\n\t\t\t\t\t\"DT\" : 123,\r\n\t\t\t\t\t\"P\" : 4341,\r\n\t\t\t\t\t\"E_Day\" : 57230,\r\n\t\t\t\t\t\"E_Year\" : 6425915.5,\r\n\t\t\t\t\t\"E_Total\" : 15388710\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}"
57
- }
58
});