11
11
*
12
12
* @param options {Object} reporter options
13
13
* id: {String} report id
14
- * env: {String } environment description
14
+ * env: {Object } environment description
15
15
*/
16
16
function EarlReport ( options ) {
17
17
let today = new Date ( ) ;
@@ -24,6 +24,8 @@ function EarlReport(options) {
24
24
this . now . setMilliseconds ( 0 ) ;
25
25
this . id = options . id ;
26
26
this . env = options . env ;
27
+ // test environment
28
+ this . _environment = null ;
27
29
/* eslint-disable quote-props */
28
30
this . _report = {
29
31
'@context' : {
@@ -69,35 +71,40 @@ function EarlReport(options) {
69
71
'foaf:homepage' : 'https://digitalbazaar.com/'
70
72
} ,
71
73
'doap:release' : {
72
- 'doap:name' : '' ,
73
74
'doap:revision' : '' ,
74
75
'doap:created' : today
75
76
} ,
76
77
'subjectOf' : [ ]
77
78
} ;
78
79
/* eslint-enable quote-props */
79
- this . _report [ '@id' ] +=
80
- '#' + this . id ;
81
- this . _report [ 'doap:name' ] +=
82
- ' ' + this . id + ( this . env ? ' ' + this . env : '' ) ;
83
- this . _report [ 'dc:title' ] +=
84
- ' ' + this . id + ( this . env ? ' ' + this . env : '' ) ;
80
+ if ( this . env && this . env . version ) {
81
+ this . _report [ 'doap:release' ] [ 'doap:name' ] = this . env . version ;
82
+ }
85
83
}
86
84
87
85
EarlReport . prototype . addAssertion = function ( test , pass , options ) {
88
86
options = options || { } ;
89
- this . _report . subjectOf . push ( {
87
+ const assertion = {
90
88
'@type' : 'earl:Assertion' ,
91
89
'earl:assertedBy' : this . _report [ 'doap:developer' ] [ '@id' ] ,
92
90
'earl:mode' : 'earl:automatic' ,
93
91
'earl:test' : test [ '@id' ] ,
94
92
'earl:result' : {
95
93
'@type' : 'earl:TestResult' ,
96
94
'dc:date' : this . now . toISOString ( ) ,
97
- 'earl:outcome' : pass ? 'earl:passed' : 'earl:failed' ,
98
- ...options . extra
95
+ 'earl:outcome' : pass ? 'earl:passed' : 'earl:failed'
99
96
}
100
- } ) ;
97
+ } ;
98
+ if ( options . benchmarkResult ) {
99
+ const result = {
100
+ ...options . benchmarkResult
101
+ } ;
102
+ if ( this . _environment ) {
103
+ result [ 'jldb:environment' ] = this . _environment [ '@id' ] ;
104
+ }
105
+ assertion [ 'jldb:result' ] = result ;
106
+ }
107
+ this . _report . subjectOf . push ( assertion ) ;
101
108
return this ;
102
109
} ;
103
110
@@ -109,4 +116,81 @@ EarlReport.prototype.reportJson = function() {
109
116
return JSON . stringify ( this . _report , null , 2 ) ;
110
117
} ;
111
118
119
+ /* eslint-disable quote-props */
120
+ const _benchmarkContext = {
121
+ 'jldb' : 'http://json-ld.org/benchmarks/vocab#' ,
122
+ 'rdfs' : 'http://www.w3.org/2000/01/rdf-schema#' ,
123
+ 'xsd' : 'http://www.w3.org/2001/XMLSchema#' ,
124
+
125
+ // environment description
126
+ 'jldb:Environment' : { '@type' : '@id' } ,
127
+
128
+ // per environment
129
+ // architecture type
130
+ // ex: x86
131
+ 'jldb:arch' : { '@type' : 'xsd:string' } ,
132
+ // cpu model description (may show multiple cpus)
133
+ // ex: 'Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz'
134
+ 'jldb:cpu' : { '@type' : 'xsd:string' } ,
135
+ // count of cpus, may not be uniform, just informative
136
+ 'jldb:cpuCount' : { '@type' : 'xsd:integer' } ,
137
+ // platform name
138
+ // ex: linux
139
+ 'jldb:platform' : { '@type' : 'xsd:string' } ,
140
+ // runtime name
141
+ // ex: Node.js, Chromium, Ruby
142
+ 'jldb:runtime' : { '@type' : 'xsd:string' } ,
143
+ // runtime version
144
+ // ex: v14.19.0
145
+ 'jldb:runtimeVersion' : { '@type' : 'xsd:string' } ,
146
+ // arbitrary comment
147
+ 'jldb:comment' : 'rdfs:comment' ,
148
+
149
+ // benchmark result
150
+ 'jldb:BenchmarkResult' : { '@type' : '@id' } ,
151
+
152
+ // use in earl:Assertion, type jldb:BenchmarkResult
153
+ 'jldb:result' : { '@type' : '@id' } ,
154
+
155
+ // per BenchmarkResult
156
+ 'jldb:environment' : { '@type' : '@id' } ,
157
+ 'jldb:hz' : { '@type' : 'xsd:float' } ,
158
+ 'jldb:rme' : { '@type' : 'xsd:float' }
159
+ } ;
160
+ /* eslint-enable quote-props */
161
+
162
+ // setup @context and environment to handle benchmark data
163
+ EarlReport . prototype . setupForBenchmarks = function ( options ) {
164
+ // add context if needed
165
+ if ( ! Array . isArray ( this . _report [ '@context' ] ) ) {
166
+ this . _report [ '@context' ] = [ this . _report [ '@context' ] ] ;
167
+ }
168
+ if ( ! this . _report [ '@context' ] . some ( c => c === _benchmarkContext ) ) {
169
+ this . _report [ '@context' ] . push ( _benchmarkContext ) ;
170
+ }
171
+ if ( options . testEnv ) {
172
+ // add report environment
173
+ const fields = [
174
+ [ 'arch' , 'jldb:arch' ] ,
175
+ [ 'cpu' , 'jldb:cpu' ] ,
176
+ [ 'cpuCount' , 'jldb:cpuCount' ] ,
177
+ [ 'platform' , 'jldb:platform' ] ,
178
+ [ 'runtime' , 'jldb:runtime' ] ,
179
+ [ 'runtimeVersion' , 'jldb:runtimeVersion' ] ,
180
+ [ 'comment' , 'jldb:comment' ]
181
+ ] ;
182
+ const _env = {
183
+ '@id' : '_:environment:0'
184
+ } ;
185
+ for ( const [ field , property ] of fields ) {
186
+ if ( options . testEnv [ field ] ) {
187
+ _env [ property ] = options . testEnv [ field ] ;
188
+ }
189
+ }
190
+ this . _environment = _env ;
191
+ this . _report [ '@included' ] = this . _report [ '@included' ] || [ ] ;
192
+ this . _report [ '@included' ] . push ( _env ) ;
193
+ }
194
+ } ;
195
+
112
196
module . exports = EarlReport ;
0 commit comments