0

I have a following structure

root/Test/runtests.js
root/Test/package.json               # npm
root/packages/local/foo/package.json # not npm
root/packages/local/foo/spec/        # root for tests

runtests.js:

var Jasmine = require('jasmine');
var jasmine = new Jasmine();
var spec_files = process.argv[2] + '/**/*Spec.js';
jasmine.loadConfig({
    spec_dir: '../',
    helpers: [],
    spec_files: [
        spec_files
    ],
    stopSpecOnExpectationFailure: false,
    random: true
});
jasmine.execute();

And I run it from inside root/Test with node runtests.js packages/local/foo/spec. Whatever I try, it keeps failing by trying to parse packages/local/foo/package.json. It's not surprising it fails, because that json file isn't actually valid json and uses /* syntax for block comments, but that's beside the point -- why is it being parsed to begin with? How can it be excluded? I tried using ! syntax in spec_files definition, to no avail. Here is what stacktrace look like

(node:48272) UnhandledPromiseRejectionWarning: SyntaxError: Error parsing root\packages\local\foo\package.json: Unexpected token / in JSON at position 7                                          
  at JSON.parse (<anonymous>)                                                                                                                                                                                                                  
  at readPackage (internal/modules/cjs/loader.js:239:25)                                                                                                                                                                                       
  at readPackageScope (internal/modules/cjs/loader.js:263:19)                                                                                                                                                                                  
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:970:17)                                                                                                                                                                     
  at Module.load (internal/modules/cjs/loader.js:815:32)                                                                                                                                                                                       
  at Function.Module._load (internal/modules/cjs/loader.js:727:14)                                                                                                                                                                             
  at Module.require (internal/modules/cjs/loader.js:852:19)                                                                                                                                                                                    
  at require (internal/modules/cjs/helpers.js:74:18)                                                                                                                                                                                           
  at Loader.requireShim [as require_] (root\Test\node_modules\jasmine\lib\loader.js:35:3)                                                                                                               
  at root\Test\node_modules\jasmine\lib\loader.js:28:12

I'm using jasmine ^3.9.0

Coderino Javarino
  • 2,819
  • 4
  • 21
  • 43
  • You are asking for trouble by having a file named `package.json`. NPM does some traversal through paths looking for files of this name and there are things that may try to interpret those files whether you want them to or not. You can debate with the NPM team whether they picked a good or bad name but I suspect that by renaming your non-package.json-package.json file to something else will resolve this. – Joe Sep 15 '21 at 16:00
  • @Joe I didn't choose to name it package.json, just like I didn't choose to name npm's file package.json. If I rename it, then it will stop working in the context it is needed – Coderino Javarino Sep 15 '21 at 16:25
  • Then you might need to move it out of the source tree to a different path off the root, something outside of the context of where code might be. – Joe Sep 15 '21 at 16:32
  • I'm not saying NPM is right in what they're doing, but your file is likely confusing NPM. – Joe Sep 15 '21 at 16:33

0 Answers0