Skip to content

Commit 6092a5b

Browse files
committed
Simplified testing.
1 parent fd2de52 commit 6092a5b

File tree

6 files changed

+24
-9279
lines changed

6 files changed

+24
-9279
lines changed

build.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var fs = require('fs');
1+
var fs = require("fs");
22

3-
const DashboardBuilder = require('./lib/DashboardBuilder');
4-
const { exit } = require('process');
3+
const DashboardBuilder = require("./lib/DashboardBuilder");
4+
const { exit } = require("process");
55
const builder = new DashboardBuilder()
66

77
const options = {
@@ -10,7 +10,7 @@ const options = {
1010
filterMap: {},
1111
}
1212

13-
const buildDir = './build';
13+
const buildDir = "./build";
1414

1515
try {
1616
if(fs.existsSync(buildDir)) {
@@ -27,13 +27,13 @@ if (!fs.existsSync(buildDir)){
2727
console.log("Created build folder.");
2828
}
2929

30-
const dashboardsDir = './build/dashboards';
30+
const dashboardsDir = "./build/dashboards";
3131
if (!fs.existsSync(dashboardsDir)){
3232
fs.mkdirSync(dashboardsDir);
3333
console.log("Created build/dashboards folder.");
3434
}
3535

36-
const datasourcesDir = './build/datasources';
36+
const datasourcesDir = "./build/datasources";
3737
if (!fs.existsSync(datasourcesDir)){
3838
fs.mkdirSync(datasourcesDir);
3939
console.log("Created build/datasources folder.");
@@ -55,7 +55,7 @@ try {
5555
exit(1);
5656
}
5757

58-
const dashboards = ['General', 'Metrics', 'Summary'];
58+
const dashboards = ["General", "Metrics", "Summary"];
5959

6060
var summaryList = [];
6161
for (const dashboard of dashboards) {

build.test.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
const fs = require('fs');
2-
const DashboardBuilder = require('./lib/DashboardBuilder');
1+
const fs = require("fs");
2+
const DashboardBuilder = require("./lib/DashboardBuilder");
33
const builder = new DashboardBuilder()
44

5-
function runTest(dashboard) {
5+
function getDashboard(dashboard) {
66
const options = {
77
table: "basicrum_friends_webperf_rum_events",
88
datasourceUid: "A0Wl5Mc4z",
99
filterMap: {
1010
"hosts":"testHosts",
1111
},
1212
}
13-
13+
1414
builder.build(dashboard, options);
1515

16-
const expected = JSON.parse(fs.readFileSync(`./testdata/dashboards/${dashboard}.json`, { encoding: 'utf8', flag: 'r' }));
17-
const actual = JSON.parse(fs.readFileSync(`./build/dashboards/${dashboard}.json`, { encoding: 'utf8', flag: 'r' }));
18-
expect(actual).toMatchObject(expected);
16+
return JSON.parse(fs.readFileSync(`./build/dashboards/${dashboard}.json`, { encoding: "utf8", flag: "r" }));
1917
}
2018

21-
test('build General dashboard should be as expected', () => {
22-
runTest('General')
19+
test("Test General dashboard should be as expected", () => {
20+
const generalDashboard = getDashboard("General");
21+
22+
expect(34).toBe(generalDashboard.panels.length);
2323
});
2424

25-
test('build Metrics dashboard should be as expected', () => {
26-
runTest('Metrics')
25+
test("Test Metrics dashboard should be as expected", () => {
26+
const metricsDashboard = getDashboard("Metrics");
27+
28+
expect(4).toBe(metricsDashboard.panels.length);
2729
});
2830

29-
test('build Summary dashboard should be as expected', () => {
30-
runTest('Summary')
31+
test("Test Summary dashboard should be as expected", () => {
32+
const summaryDashboard = getDashboard("Summary");
33+
34+
expect(14).toBe(summaryDashboard.panels.length);
3135
});

testdata/dashboards/.prettierrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)