1
1
/**
2
2
* Karma test runner for jsonld.js.
3
3
*
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.
38
5
*
39
6
* @author Dave Longley
40
7
* @author David I. Lehn
41
8
*
42
- * Copyright (c) 2011-2022 Digital Bazaar, Inc. All rights reserved.
9
+ * Copyright (c) 2011-2023 Digital Bazaar, Inc. All rights reserved.
43
10
*/
44
11
/* global serverRequire */
45
12
// FIXME: hack to ensure delay is set first
46
13
mocha . setup ( { delay : true , ui : 'bdd' } ) ;
47
14
48
15
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 ' ) ;
51
18
const server = require ( 'karma-server-side' ) ;
52
19
const webidl = require ( './test-webidl' ) ;
53
20
const join = require ( 'join-path-js' ) ;
54
21
55
22
// special benchmark setup
56
23
const _ = require ( 'lodash' ) ;
57
- //const _process = require('process');
58
- const benchmark = require ( 'benchmark' ) ;
59
- //const Benchmark = benchmark.runInContext({_, _process});
60
24
const Benchmark = benchmark . runInContext ( { _} ) ;
61
25
window . Benchmark = Benchmark ;
62
26
63
27
const entries = [ ] ;
64
28
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 ( ' ' ) ) ;
67
31
} else {
68
32
const _top = process . env . TEST_ROOT_DIR ;
69
33
// TODO: support just adding certain entries in EARL mode?
70
34
71
35
// 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
+ } ) ( ) ) ;
75
49
76
50
// 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
+ } ) ( ) ) ;
80
64
81
65
/*
82
66
// TODO: use json-ld-framing once tests are moved
@@ -89,9 +73,19 @@ if(process.env.JSONLD_TESTS) {
89
73
*/
90
74
91
75
// 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
+ } ) ( ) ) ;
95
89
96
90
// other tests
97
91
entries . push ( join ( _top , 'tests/misc.js' ) ) ;
@@ -102,79 +96,31 @@ if(process.env.JSONLD_TESTS) {
102
96
entries . push ( webidl ) ;
103
97
}
104
98
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
+ } ;
159
111
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
+ } ;
172
118
173
119
const options = {
120
+ env,
174
121
nodejs : false ,
175
122
assert,
176
123
benchmark,
177
- jsonld,
178
124
/* eslint-disable-next-line no-unused-vars */
179
125
exit : code => {
180
126
console . error ( 'exit not implemented' ) ;
@@ -183,11 +129,8 @@ const options = {
183
129
earl : {
184
130
filename : process . env . EARL
185
131
} ,
186
- verboseSkip : process . env . VERBOSE_SKIP === 'true' ,
187
- bailOnError : process . env . BAIL === 'true' ,
188
132
entries,
189
- testEnv,
190
- benchmarkOptions,
133
+ testEnvDefaults,
191
134
readFile : filename => {
192
135
return server . run ( filename , function ( filename ) {
193
136
const fs = serverRequire ( 'fs-extra' ) ;
0 commit comments