-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjasmine-ieee829-decorator.js
118 lines (109 loc) · 4.14 KB
/
jasmine-ieee829-decorator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Holder for all of our test spec definitions.
var testSpecRoot = [];
var reporterPresent = false;
var reporter;
jasmine.getEnv().addReporter({
jasmineStarted: function () {
testSpecRoot = [];
},
specStarted: function (result) {
testSpecRoot[testSpecRoot.length] = {
specId: result.id,
specName: result.fullName,
testElement: "not defined",
validResponse: "not defined",
invalidResponse: "not defined",
dataItems: [],
desc: null,
lastRunDT: "incomplete",
lastRunStatus: "unknown"
};
},
specDone: function (result) {
testSpecRoot[testSpecRoot.length - 1].lastRunDT = new Date().toString();
testSpecRoot[testSpecRoot.length - 1].lastRunStatus = result.status;
},
jasmineDone: function () {
printTestSpecDefinitionToReporter();
}
});
function defineDescription(description) {
if(description !== "undefined") {
testSpecRoot[testSpecRoot.length - 1].desc = description;
}
};
function defineValidResponse(response) {
if(response !== "undefined") {
testSpecRoot[testSpecRoot.length - 1].validResponse = response;
}
};
function defineInvalidResponse(response) {
if(response !== "undefined") {
testSpecRoot[testSpecRoot.length - 1].invalidResponse = response;
}
};
function defineTestElement(testElement) {
if(testElement !== "undefined") {
testSpecRoot[testSpecRoot.length - 1].testElement = testElement;
}
};
function defineData(dataItemName, dataItemType, desc) {
if(dataItemName !== "undefined" && dataItemType !== "undefined" && desc !== "undefined") {
var currentTestSpec = testSpecRoot[testSpecRoot.length - 1];
currentTestSpec.dataItems[currentTestSpec.dataItems.length] = {
dataItemName: dataItemName,
dataItemType: dataItemType,
dataItemDesc: desc
}
}
};
function printTestSpecDefinitionToReporter() {
// Determine if the jasmine reporter has done its thing and we have output in the DOM.
reporter = document.getElementsByClassName("jasmine_html-reporter")[0];
if (typeof(reporter) != 'undefined' && reporter != null) {
reporterPresent = true;
appendToReporter("");
appendToReporter("IEEE 829 Test Specification");
appendToReporter("---------------------------");
appendToReporter("");
} else {
// no reporter to append to.
return;
}
for(var specIndex = 0; specIndex < testSpecRoot.length; specIndex++) {
var currentSpec = testSpecRoot[specIndex];
// print spec id
appendToReporter("Unique Test ID : " + currentSpec.specId);
// print test name
appendToReporter("Test Name : " + currentSpec.specName);
// print test element
appendToReporter("Test Element : " + currentSpec.testElement);
// print valid and invalid response
appendToReporter("Valid Response : " + currentSpec.validResponse);
appendToReporter("Invalid Response : " + currentSpec.invalidResponse);
// print extended description (if there is one)
if(currentSpec.desc != null) {
appendToReporter("Description cont.: " + currentSpec.desc);
}
appendToReporter("Last Run DT : " + currentSpec.lastRunDT);
appendToReporter("Last Run Result : " + currentSpec.lastRunStatus);
// print data items (if any were defined)
if(currentSpec.dataItems.length > 0) {
appendToReporter("Data Items : ");
for(var itemIndex = 0; itemIndex < currentSpec.dataItems.length; itemIndex++) {
var currentDataItem = currentSpec.dataItems[itemIndex];
appendToReporter(" Item Name : " + currentDataItem.dataItemName);
appendToReporter(" Item Type : " + currentDataItem.dataItemType);
appendToReporter(" Item Description : " + currentDataItem.dataItemDesc);
appendToReporter("");
}
}
// We want a gap between test desriptions.
appendToReporter("");
}
};
function appendToReporter(value) {
if(reporterPresent) {
reporter.innerHTML = reporter.innerHTML + value + "<br>";
}
}