66 * @author  Dave Longley 
77 * @author  David I. Lehn 
88 * 
9-  * Copyright (c) 2011-2023  Digital Bazaar, Inc. All rights reserved. 
9+  * Copyright (c) 2011-2025  Digital Bazaar, Inc. All rights reserved. 
1010 */ 
11- /* global serverRequire */ 
1211// FIXME: hack to ensure delay is set first 
1312mocha . setup ( { delay : true ,  ui : 'bdd' } ) ; 
1413
1514const  assert  =  require ( 'chai' ) . assert ; 
1615const  benchmark  =  require ( 'benchmark' ) ; 
1716const  common  =  require ( './test.js' ) ; 
18- const  server  =  require ( 'karma-server-side' ) ; 
1917const  webidl  =  require ( './test-webidl' ) ; 
20- const  join  =  require ( 'join-path-js' ) ; 
2118
2219// special benchmark setup 
2320const  _  =  require ( 'lodash' ) ; 
@@ -26,70 +23,25 @@ window.Benchmark = Benchmark;
2623
2724const  entries  =  [ ] ; 
2825
26+ // setup test server url, add localhost if needed 
27+ let  testServerUrl  =  process . env . TEST_SERVER_URL ; 
28+ if ( ! testServerUrl . endsWith ( '/' ) )  { 
29+   testServerUrl  +=  '/' ; 
30+ } 
31+ if ( ! ( testServerUrl . startsWith ( 'http:' )  ||  testServerUrl . startsWith ( 'https:' ) ) )  { 
32+   const  pathname  =  testServerUrl ; 
33+   testServerUrl  =  new  URL ( window . location ) ; 
34+   testServerUrl . pathname  =  pathname ; 
35+ } 
36+ 
2937if ( process . env . TESTS )  { 
3038  entries . push ( ...process . env . TESTS . split ( ' ' ) ) ; 
3139}  else  { 
32-   const  _top  =  process . env . TEST_ROOT_DIR ; 
33-   // TODO: support just adding certain entries in EARL mode? 
34- 
35-   // json-ld-api main test suite 
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-   } ) ( ) ) ; 
49- 
50-   // json-ld-framing main test suite 
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-   } ) ( ) ) ; 
64- 
65-   /* 
66-   // TODO: use json-ld-framing once tests are moved 
67-   // json-ld.org framing test suite 
68-   // FIXME: add path detection 
69-   entries.push(join( 
70-     _top, 'test-suites/json-ld.org/test-suite/tests/frame-manifest.jsonld')); 
71-   entries.push(join( 
72-     _top, '../json-ld.org/test-suite/tests/frame-manifests.jsonld')); 
73-   */ 
40+   entries . push ( new  URL ( 'tests/default/' ,  testServerUrl ) ) ; 
7441
75-   // W3C RDF Dataset Canonicalization "rdf-canon" test suite 
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-   } ) ( ) ) ; 
42+   // TODO: support just adding certain entries in EARL mode? 
8943
90-   // other tests 
91-   entries . push ( join ( _top ,  'tests/misc.js' ) ) ; 
92-   entries . push ( join ( _top ,  'tests/graph-container.js' ) ) ; 
44+   // other tests (including js ones) added with options.addExtraTests 
9345
9446  // WebIDL tests 
9547  entries . push ( webidl ) ; 
@@ -126,33 +78,35 @@ const options = {
12678    throw  new  Error ( 'exit not implemented' ) ; 
12779  } , 
12880  earl : { 
81+     enabled : ! ! process . env . EARL , 
12982    filename : process . env . EARL 
13083  } , 
13184  entries, 
85+   addExtraTests : async  ( )  =>  { 
86+     // direct load for bundling 
87+     // called after handling other entry loading 
88+     require ( './misc.js' ) ; 
89+     require ( './graph-container.js' ) ; 
90+   } , 
13291  testEnvDefaults, 
133-   readFile : filename  =>  { 
134-     return  server . run ( filename ,  function ( filename )  { 
135-       const  fs  =  serverRequire ( 'fs-extra' ) ; 
136-       return  fs . readFile ( filename ,  'utf8' ) . then ( data  =>  { 
137-         return  data ; 
138-       } ) ; 
139-     } ) ; 
92+   get  testServerUrl ( )  { 
93+     return  testServerUrl ; 
14094  } , 
141-   writeFile : ( filename ,  data )  =>  { 
142-     return  server . run ( filename ,  data ,  function ( filename ,  data )  { 
143-       const  fs  =  serverRequire ( 'fs-extra' ) ; 
144-       return  fs . outputFile ( filename ,  data ) ; 
145-     } ) ; 
95+   get  authToken ( )  { 
96+     return  process . env . AUTH_TOKEN ; 
14697  } , 
147-   /* eslint-disable-next-line no-unused-vars */ 
14898  import : f  =>  { 
14999    console . error ( 'import not implemented for "'  +  f  +  '"' ) ; 
150-   } 
100+   } , 
101+   cleanup : async  ( )  =>  { } 
151102} ; 
152103
153- // wait for setup of all tests then run mocha 
154- common ( options ) . then ( ( )  =>  { 
104+ async  function  main ( )  { 
105+   // wait for setup of all tests then run mocha 
106+   await  common . setup ( options ) ; 
155107  run ( ) ; 
156- } ) . catch ( err  =>  { 
108+ } 
109+ 
110+ main ( ) . catch ( err  =>  { 
157111  console . error ( err ) ; 
158112} ) ; 
0 commit comments