Skip to content

Commit 9d5b66c

Browse files
committed
Output benchmark Hz in EARL report.
- Output Hz in EARL report. - Add extra env data in EARL fields.
1 parent a6b5e4f commit 9d5b66c

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

tests/earl-report.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* @param options {Object} reporter options
1313
* id: {String} report id
14+
* env: {String} environment description
1415
*/
1516
function EarlReport(options) {
1617
let today = new Date();
@@ -22,6 +23,7 @@ function EarlReport(options) {
2223
this.now = new Date();
2324
this.now.setMilliseconds(0);
2425
this.id = options.id;
26+
this.env = options.env;
2527
/* eslint-disable quote-props */
2628
this._report = {
2729
'@context': {
@@ -30,6 +32,7 @@ function EarlReport(options) {
3032
'dc': 'http://purl.org/dc/terms/',
3133
'earl': 'http://www.w3.org/ns/earl#',
3234
'xsd': 'http://www.w3.org/2001/XMLSchema#',
35+
'jsonld': 'http://www.w3.org/ns/json-ld#',
3336
'doap:homepage': {'@type': '@id'},
3437
'doap:license': {'@type': '@id'},
3538
'dc:creator': {'@type': '@id'},
@@ -73,17 +76,16 @@ function EarlReport(options) {
7376
'subjectOf': []
7477
};
7578
/* eslint-enable quote-props */
76-
const version = require('../package.json').version;
77-
// FIXME: Improve "Node.js" vs "browser" id reporting
78-
// this._report['@id'] += '#' + this.id;
79-
// this._report['doap:name'] += ' ' + this.id;
80-
// this._report['dc:title'] += ' ' + this.id;
81-
this._report['doap:release']['doap:name'] =
82-
this._report['doap:name'] + ' ' + version;
83-
this._report['doap:release']['doap:revision'] = version;
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 : '');
8485
}
8586

86-
EarlReport.prototype.addAssertion = function(test, pass) {
87+
EarlReport.prototype.addAssertion = function(test, pass, options) {
88+
options = options || {};
8789
this._report.subjectOf.push({
8890
'@type': 'earl:Assertion',
8991
'earl:assertedBy': this._report['doap:developer']['@id'],
@@ -93,6 +95,7 @@ EarlReport.prototype.addAssertion = function(test, pass) {
9395
'@type': 'earl:TestResult',
9496
'dc:date': this.now.toISOString(),
9597
'earl:outcome': pass ? 'earl:passed' : 'earl:failed'
98+
...options.extra
9699
}
97100
});
98101
return this;

tests/test-common.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ const SKIP_TESTS = [];
264264

265265
// create earl report
266266
if(options.earl && options.earl.filename) {
267-
options.earl.report = new EarlReport({id: options.earl.id});
267+
options.earl.report = new EarlReport({
268+
id: options.earl.id,
269+
env: options.earl.env
270+
});
268271
}
269272

270273
return new Promise(resolve => {
@@ -570,9 +573,9 @@ function addTest(manifest, test, tests) {
570573
throw Error('Unknown test type: ' + test.type);
571574
}
572575

573-
let benchResults = null;
576+
let benchResult = null
574577
if(options.benchmark) {
575-
benchResults = await runBenchmark({
578+
const result = await runBenchmark({
576579
test,
577580
fn,
578581
params: testInfo.params.map(param => param(test, {
@@ -581,11 +584,17 @@ function addTest(manifest, test, tests) {
581584
})),
582585
mochaTest: self
583586
});
587+
benchResult = {
588+
'jsonld:benchmarkHz': result.target.hz
589+
};
584590
}
585591

586592
if(options.earl.report) {
587-
// TODO: add benchmark info
588-
options.earl.report.addAssertion(test, true);
593+
options.earl.report.addAssertion(test, true, {
594+
extra: {
595+
...benchResult
596+
}
597+
});
589598
}
590599
} catch(err) {
591600
if(options.bailOnError) {
@@ -630,7 +639,7 @@ async function runBenchmark({test, fn, params, mochaTest}) {
630639
reject(new Error(err));
631640
})
632641
.on('complete', e => {
633-
resolve();
642+
resolve(e);
634643
})
635644
.run({async: true});
636645
});

tests/test-karma.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* JSONLD_TESTS="r1 r2 ..."
88
* Output an EARL report:
99
* EARL=filename
10+
* Output EARL environment description (any appropraite string):
11+
* EARL_ENV='CPU=Intel-i7-4790K@4.00GHz,Node.js=v10.16.3,jsonld.js=v1.7.0'
1012
* Bail with tests fail:
1113
* BAIL=true
1214
* Verbose skip reasons:
@@ -95,6 +97,7 @@ const options = {
9597
},
9698
earl: {
9799
id: 'browser',
100+
env: process.env.EARL_ENV,
98101
filename: process.env.EARL
99102
},
100103
verboseSkip: process.env.VERBOSE_SKIP === 'true',

tests/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* JSONLD_TESTS="r1 r2 ..."
88
* Output an EARL report:
99
* EARL=filename
10+
* Output EARL environment description (any appropraite string):
11+
* EARL_ENV='CPU=Intel-i7-4790K@4.00GHz,Node.js=v10.16.3,jsonld.js=v1.7.0'
1012
* Bail with tests fail:
1113
* BAIL=true
1214
* Verbose skip reasons:
@@ -102,6 +104,7 @@ const options = {
102104
exit: code => process.exit(code),
103105
earl: {
104106
id: 'Node.js',
107+
env: process.env.EARL_ENV,
105108
filename: process.env.EARL
106109
},
107110
verboseSkip: process.env.VERBOSE_SKIP === 'true',

0 commit comments

Comments
 (0)