From 64f6191801edbdd2cf3d15178a8fdef879cd574c Mon Sep 17 00:00:00 2001 From: BrainDoctor Date: Tue, 18 Jul 2017 14:58:58 +0200 Subject: updated test cases and instructions on how to install jasmine-node with the newest jasmine --- tests/README.md | 3 ++- tests/node.d/fronius.spec.js | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/README.md b/tests/README.md index fd753254e1..415622e098 100644 --- a/tests/README.md +++ b/tests/README.md @@ -12,8 +12,9 @@ Make sure you are the user who is developer (permissions, except sudo ofc) sudo apt-get install nodejs npm chromium-browser cd /path/to/your/netdata - npm install +cd node_modules +git clone https://github.com/BrainDoctor/jasmine-node.git ``` That should install the necessary node modules. diff --git a/tests/node.d/fronius.spec.js b/tests/node.d/fronius.spec.js index 204f7f6fe4..11581552a0 100644 --- a/tests/node.d/fronius.spec.js +++ b/tests/node.d/fronius.spec.js @@ -6,8 +6,9 @@ var fronius = require("../../node.d/fronius.node"); describe("fronius chart creation", function () { - beforeEach(function () { - netdata.options.DEBUG = true; + beforeAll(function () { + // change this to enable debug log + netdata.options.DEBUG = false; }); it("should return a basic chart definition", function () { @@ -23,7 +24,7 @@ describe("fronius chart creation", function () { it("will fail", function () { netdata.debug("test"); - throw new Error("expected failure to test unit test runner"); + throw new Error("demonstrate failure of unit test runner"); }); }); @@ -35,7 +36,11 @@ describe("fronius data parsing", function () { module: this }); - beforeEach(function () { + // this is a faked JSON response from the server. + // Used with freeformatter.com/json-escape.html to escape the json and turn it into a string. + 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}" + + beforeAll(function () { // change this to enable debug log netdata.options.DEBUG = false; }); @@ -44,15 +49,10 @@ describe("fronius data parsing", function () { // arrange netdata.send = jasmine.createSpy("send"); // act - fronius.processResponse(service, createFakeResponse()); - var result = netdata.send.calls[0].args[0]; + fronius.processResponse(service, fakeResponse); + var result = netdata.send.calls.argsFor(0)[0]; // assert expect(result).toContain("SET p_grid = -3431"); }); - function createFakeResponse() { - // this is a faked JSON response from the server. - // Used with freeformatter.com/json-escape.html to escape the json and turn it into a string. - 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}" - } }); -- cgit v1.2.3