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
4613mocha . setup ( { delay : true , ui : 'bdd' } ) ;
4714
4815const assert = require ( 'chai' ) . assert ;
49- const common = require ( './test ' ) ;
50- const jsonld = require ( '.. ' ) ;
16+ const benchmark = require ( 'benchmark ' ) ;
17+ const common = require ( './test.js ' ) ;
5118const server = require ( 'karma-server-side' ) ;
5219const webidl = require ( './test-webidl' ) ;
5320const join = require ( 'join-path-js' ) ;
5421
5522// special benchmark setup
5623const _ = require ( 'lodash' ) ;
57- //const _process = require('process');
58- const benchmark = require ( 'benchmark' ) ;
59- //const Benchmark = benchmark.runInContext({_, _process});
6024const Benchmark = benchmark . runInContext ( { _} ) ;
6125window . Benchmark = Benchmark ;
6226
6327const 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
173119const 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