Skip to content

Commit 2b5aa2d

Browse files
committed
Align test and benchmark code with rdf-canonize.
- Align test and benchmark code with rdf-canonize. - **NOTE**: This changes various testing and benchmark runner features and options. - Update env var usage. - Use more common code between Node.js and karma tests. - Conditionally load test suites. - Fix various minor bugs. - Add multiple jobs benchmarking support.
1 parent 80701d8 commit 2b5aa2d

File tree

6 files changed

+345
-314
lines changed

6 files changed

+345
-314
lines changed

Diff for: CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# jsonld ChangeLog
22

3-
## 8.1.2 - 2023-03-xx
3+
## 8.2.0 - 2023-03-xx
44

55
### Changed
66
- Update for latest [rdf-canon][] changes: test suite location, README, links,
77
and identifiers.
88
- Skip test with 'U' escapes. Will enable when [rdf-canonize][] dependency is
99
updated.
1010
- Test on Node.js 20.x.
11+
- Align test and benchmark code with [rdf-canonize][].
12+
- **NOTE**: This changes various testing and benchmark runner features and
13+
options.
14+
- Update env var usage.
15+
- Use more common code between Node.js and karma tests.
16+
- Conditionally load test suites.
17+
- Fix various minor bugs.
18+
- Add multiple jobs benchmarking support.
1119

1220
### Fixed
1321
- Improve safe mode for `@graph` use cases.

Diff for: README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@ Node.js tests can be run with a simple command:
389389
npm test
390390

391391
If you installed the test suites elsewhere, or wish to run other tests, use
392-
the `JSONLD_TESTS` environment var:
392+
the `TESTS` environment var:
393393

394-
JSONLD_TESTS="/tmp/org/test-suites /tmp/norm/tests" npm test
394+
TESTS="/tmp/org/test-suites /tmp/norm/tests" npm test
395395

396396
This feature can be used to run the older json-ld.org test suite:
397397

398-
JSONLD_TESTS=/tmp/json-ld.org/test-suite npm test
398+
TESTS=/tmp/json-ld.org/test-suite npm test
399399

400400
Browser testing can be done with Karma:
401401

@@ -419,7 +419,7 @@ Remote context tests are also available:
419419
# run the context server in the background or another terminal
420420
node tests/remote-context-server.js
421421

422-
JSONLD_TESTS=`pwd`/tests npm test
422+
TESTS=`pwd`/tests npm test
423423

424424
To generate EARL reports:
425425

@@ -432,7 +432,7 @@ To generate EARL reports:
432432
To generate an EARL report with the `json-ld-api` and `json-ld-framing` tests
433433
as used on the official [JSON-LD Processor Conformance][] page
434434

435-
JSONLD_TESTS="`pwd`/../json-ld-api/tests `pwd`/../json-ld-framing/tests" EARL="jsonld-js-earl.jsonld" npm test
435+
TESTS="`pwd`/../json-ld-api/tests `pwd`/../json-ld-framing/tests" EARL="jsonld-js-earl.jsonld" npm test
436436

437437
The EARL `.jsonld` output can be converted to `.ttl` using the [rdf][] tool:
438438

@@ -449,14 +449,14 @@ Benchmarks
449449
Benchmarks can be created from any manifest that the test system supports.
450450
Use a command line with a test suite and a benchmark flag:
451451

452-
JSONLD_TESTS=/tmp/benchmark-manifest.jsonld JSONLD_BENCHMARK=1 npm test
452+
TESTS=/tmp/benchmark-manifest.jsonld BENCHMARK=1 npm test
453453

454454
EARL reports with benchmark data can be generated with an optional environment
455455
details:
456456

457-
JSONLD_TESTS=`pwd`/../json-ld.org/benchmarks/b001-manifiest.jsonld JSONLD_BENCHMARK=1 EARL=earl-test.jsonld TEST_ENV=1 npm test
457+
TESTS=`pwd`/../json-ld.org/benchmarks/b001-manifiest.jsonld BENCHMARK=1 EARL=earl-test.jsonld TEST_ENV=1 npm test
458458

459-
See `tests/test.js` for more `TEST_ENV` control and options.
459+
See `tests/test.js` for more `TEST_ENV` and `BENCHMARK` control and options.
460460

461461
These reports can be compared with the `benchmarks/compare/` tool and at the
462462
[JSON-LD Benchmarks][] site.

Diff for: karma.conf.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/**
2-
* Karam configuration for jsonld.js.
2+
* Karma configuration for jsonld.js.
33
*
4-
* Set dirs, manifests, or js to run:
5-
* JSONLD_TESTS="f1 f2 ..."
6-
* Output an EARL report:
7-
* EARL=filename
8-
* Bail with tests fail:
9-
* BAIL=true
4+
* See ./test/test.js for env options.
105
*
116
* @author Dave Longley
127
* @author David I. Lehn
138
*
14-
* Copyright (c) 2011-2017 Digital Bazaar, Inc. All rights reserved.
9+
* Copyright (c) 2011-2023 Digital Bazaar, Inc. All rights reserved.
1510
*/
1611
const os = require('os');
1712
const webpack = require('webpack');
@@ -67,11 +62,10 @@ module.exports = function(config) {
6762
plugins: [
6863
new webpack.DefinePlugin({
6964
'process.env.BAIL': JSON.stringify(process.env.BAIL),
65+
'process.env.BENCHMARK': JSON.stringify(process.env.BENCHMARK),
7066
'process.env.EARL': JSON.stringify(process.env.EARL),
67+
'process.env.TESTS': JSON.stringify(process.env.TESTS),
7168
'process.env.TEST_ENV': JSON.stringify(process.env.TEST_ENV),
72-
'process.env.JSONLD_BENCHMARK':
73-
JSON.stringify(process.env.JSONLD_BENCHMARK),
74-
'process.env.JSONLD_TESTS': JSON.stringify(process.env.JSONLD_TESTS),
7569
'process.env.TEST_ROOT_DIR': JSON.stringify(__dirname),
7670
'process.env.VERBOSE_SKIP': JSON.stringify(process.env.VERBOSE_SKIP),
7771
// for 'auto' test env
@@ -149,10 +143,10 @@ module.exports = function(config) {
149143
[
150144
'envify', {
151145
BAIL: process.env.BAIL,
146+
BENCHMARK: process.env.BENCHMARK,
152147
EARL: process.env.EARL,
148+
TESTS: process.env.TESTS,
153149
TEST_ENV: process.env.TEST_ENV,
154-
JSONLD_BENCHMARK: process.env.JSONLD_BENCHMARK,
155-
JSONLD_TESTS: process.env.JSONLD_TESTS,
156150
TEST_ROOT_DIR: __dirname,
157151
VERBOSE_SKIP: process.env.VERBOSE_SKIP,
158152
// for 'auto' test env

Diff for: tests/test-karma.js

+65-122
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,66 @@
11
/**
22
* Karma test runner for jsonld.js.
33
*
4-
* Use environment vars to control, set via karma.conf.js/webpack:
5-
*
6-
* Set dirs, manifests, or js to run:
7-
* JSONLD_TESTS="r1 r2 ..."
8-
* Output an EARL report:
9-
* EARL=filename
10-
* Test environment details for EARL report:
11-
* This is useful for benchmark comparison.
12-
* By default no details are added for privacy reasons.
13-
* Automatic details can be added for all fields with '1', 'true', or 'auto':
14-
* TEST_ENV=1
15-
* To include only certain fields, set them, or use 'auto':
16-
* TEST_ENV=cpu='Intel i7-4790K @ 4.00GHz',runtime='Node.js',...
17-
* TEST_ENV=cpu=auto # only cpu
18-
* TEST_ENV=cpu,runtime # only cpu and runtime
19-
* TEST_ENV=auto,comment='special test' # all auto with override
20-
* Available fields:
21-
* - arch - ex: 'x64'
22-
* - cpu - ex: 'Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz'
23-
* - cpuCount - ex: 8
24-
* - platform - ex: 'linux'
25-
* - runtime - ex: 'Node.js'
26-
* - runtimeVersion - ex: 'v14.19.0'
27-
* - comment: any text
28-
* - version: jsonld.js version
29-
* Bail with tests fail:
30-
* BAIL=true
31-
* Verbose skip reasons:
32-
* VERBOSE_SKIP=true
33-
* Benchmark mode:
34-
* Basic:
35-
* JSONLD_BENCHMARK=1
36-
* With options:
37-
* JSONLD_BENCHMARK=key1=value1,key2=value2,...
4+
* See ./test.js for environment vars options.
385
*
396
* @author Dave Longley
407
* @author David I. Lehn
418
*
42-
* Copyright (c) 2011-2022 Digital Bazaar, Inc. All rights reserved.
9+
* Copyright (c) 2011-2023 Digital Bazaar, Inc. All rights reserved.
4310
*/
4411
/* global serverRequire */
4512
// FIXME: hack to ensure delay is set first
4613
mocha.setup({delay: true, ui: 'bdd'});
4714

4815
const assert = require('chai').assert;
49-
const common = require('./test');
50-
const jsonld = require('..');
16+
const benchmark = require('benchmark');
17+
const common = require('./test.js');
5118
const server = require('karma-server-side');
5219
const webidl = require('./test-webidl');
5320
const join = require('join-path-js');
5421

5522
// special benchmark setup
5623
const _ = require('lodash');
57-
//const _process = require('process');
58-
const benchmark = require('benchmark');
59-
//const Benchmark = benchmark.runInContext({_, _process});
6024
const Benchmark = benchmark.runInContext({_});
6125
window.Benchmark = Benchmark;
6226

6327
const entries = [];
6428

65-
if(process.env.JSONLD_TESTS) {
66-
entries.push(...process.env.JSONLD_TESTS.split(' '));
29+
if(process.env.TESTS) {
30+
entries.push(...process.env.TESTS.split(' '));
6731
} else {
6832
const _top = process.env.TEST_ROOT_DIR;
6933
// TODO: support just adding certain entries in EARL mode?
7034

7135
// json-ld-api main test suite
72-
// FIXME: add path detection
73-
entries.push(join(_top, 'test-suites/json-ld-api/tests'));
74-
entries.push(join(_top, '../json-ld-api/tests'));
36+
entries.push((async () => {
37+
const testPath = join(_top, 'test-suites/json-ld-api/tests');
38+
const siblingPath = join(_top, '../json-ld-api/tests');
39+
return server.run(testPath, siblingPath, function(testPath, siblingPath) {
40+
const fs = serverRequire('fs-extra');
41+
// use local tests if setup
42+
if(fs.existsSync(testPath)) {
43+
return testPath;
44+
}
45+
// default to sibling dir
46+
return siblingPath;
47+
});
48+
})());
7549

7650
// json-ld-framing main test suite
77-
// FIXME: add path detection
78-
entries.push(join(_top, 'test-suites/json-ld-framing/tests'));
79-
entries.push(join(_top, '../json-ld-framing/tests'));
51+
entries.push((async () => {
52+
const testPath = join(_top, 'test-suites/json-ld-framing/tests');
53+
const siblingPath = join(_top, '../json-ld-framing/tests');
54+
return server.run(testPath, siblingPath, function(testPath, siblingPath) {
55+
const fs = serverRequire('fs-extra');
56+
// use local tests if setup
57+
if(fs.existsSync(testPath)) {
58+
return testPath;
59+
}
60+
// default to sibling dir
61+
return siblingPath;
62+
});
63+
})());
8064

8165
/*
8266
// TODO: use json-ld-framing once tests are moved
@@ -89,9 +73,19 @@ if(process.env.JSONLD_TESTS) {
8973
*/
9074

9175
// W3C RDF Dataset Canonicalization "rdf-canon" test suite
92-
// FIXME: add path detection
93-
entries.push(join(_top, 'test-suites/rdf-canon/tests'));
94-
entries.push(join(_top, '../rdf-canon/tests'));
76+
entries.push((async () => {
77+
const testPath = join(_top, 'test-suites/rdf-canon/tests');
78+
const siblingPath = join(_top, '../rdf-canon/tests');
79+
return server.run(testPath, siblingPath, function(testPath, siblingPath) {
80+
const fs = serverRequire('fs-extra');
81+
// use local tests if setup
82+
if(fs.existsSync(testPath)) {
83+
return testPath;
84+
}
85+
// default to sibling dir
86+
return siblingPath;
87+
});
88+
})());
9589

9690
// other tests
9791
entries.push(join(_top, 'tests/misc.js'));
@@ -102,79 +96,31 @@ if(process.env.JSONLD_TESTS) {
10296
entries.push(webidl);
10397
}
10498

105-
// test environment
106-
let testEnv = null;
107-
if(process.env.TEST_ENV) {
108-
let _test_env = process.env.TEST_ENV;
109-
if(!(['0', 'false'].includes(_test_env))) {
110-
testEnv = {};
111-
if(['1', 'true', 'auto'].includes(_test_env)) {
112-
_test_env = 'auto';
113-
}
114-
_test_env.split(',').forEach(pair => {
115-
if(pair === 'auto') {
116-
testEnv.arch = 'auto';
117-
testEnv.cpu = 'auto';
118-
testEnv.cpuCount = 'auto';
119-
testEnv.platform = 'auto';
120-
testEnv.runtime = 'auto';
121-
testEnv.runtimeVersion = 'auto';
122-
testEnv.comment = 'auto';
123-
testEnv.version = 'auto';
124-
} else {
125-
const kv = pair.split('=');
126-
if(kv.length === 1) {
127-
testEnv[kv[0]] = 'auto';
128-
} else {
129-
testEnv[kv[0]] = kv.slice(1).join('=');
130-
}
131-
}
132-
});
133-
if(testEnv.arch === 'auto') {
134-
testEnv.arch = process.env._TEST_ENV_ARCH;
135-
}
136-
if(testEnv.cpu === 'auto') {
137-
testEnv.cpu = process.env._TEST_ENV_CPU;
138-
}
139-
if(testEnv.cpuCount === 'auto') {
140-
testEnv.cpuCount = process.env._TEST_ENV_CPU_COUNT;
141-
}
142-
if(testEnv.platform === 'auto') {
143-
testEnv.platform = process.env._TEST_ENV_PLATFORM;
144-
}
145-
if(testEnv.runtime === 'auto') {
146-
testEnv.runtime = 'browser';
147-
}
148-
if(testEnv.runtimeVersion === 'auto') {
149-
testEnv.runtimeVersion = '(unknown)';
150-
}
151-
if(testEnv.comment === 'auto') {
152-
testEnv.comment = '';
153-
}
154-
if(testEnv.version === 'auto') {
155-
testEnv.version = require('../package.json').version;
156-
}
157-
}
158-
}
99+
// test environment defaults
100+
const testEnvDefaults = {
101+
label: '',
102+
arch: process.env._TEST_ENV_ARCH,
103+
cpu: process.env._TEST_ENV_CPU,
104+
cpuCount: process.env._TEST_ENV_CPU_COUNT,
105+
platform: process.env._TEST_ENV_PLATFORM,
106+
runtime: 'browser',
107+
runtimeVersion: '(unknown)',
108+
comment: '',
109+
version: require('../package.json').version
110+
};
159111

160-
let benchmarkOptions = null;
161-
if(process.env.JSONLD_BENCHMARK) {
162-
if(!(['0', 'false'].includes(process.env.JSONLD_BENCHMARK))) {
163-
benchmarkOptions = {};
164-
if(!(['1', 'true'].includes(process.env.JSONLD_BENCHMARK))) {
165-
process.env.JSONLD_BENCHMARK.split(',').forEach(pair => {
166-
const kv = pair.split('=');
167-
benchmarkOptions[kv[0]] = kv[1];
168-
});
169-
}
170-
}
171-
}
112+
const env = {
113+
BAIL: process.env.BAIL,
114+
BENCHMARK: process.env.BENCHMARK,
115+
TEST_ENV: process.env.TEST_ENV,
116+
VERBOSE_SKIP: process.env.VERBOSE_SKIP
117+
};
172118

173119
const options = {
120+
env,
174121
nodejs: false,
175122
assert,
176123
benchmark,
177-
jsonld,
178124
/* eslint-disable-next-line no-unused-vars */
179125
exit: code => {
180126
console.error('exit not implemented');
@@ -183,11 +129,8 @@ const options = {
183129
earl: {
184130
filename: process.env.EARL
185131
},
186-
verboseSkip: process.env.VERBOSE_SKIP === 'true',
187-
bailOnError: process.env.BAIL === 'true',
188132
entries,
189-
testEnv,
190-
benchmarkOptions,
133+
testEnvDefaults,
191134
readFile: filename => {
192135
return server.run(filename, function(filename) {
193136
const fs = serverRequire('fs-extra');

0 commit comments

Comments
 (0)