JonathanPrince / loopback-component-fixtures

handle fixtures for testing clients against
MIT License
12 stars 13 forks source link

Project root path incorrectly calculated #20

Closed richard-fairthorne closed 7 years ago

richard-fairthorne commented 7 years ago

"fixturesPath" is calculated relative to the root of the project according to https://www.npmjs.com/package/loopback-component-fixtures

The project root is incorrectly calculated.

How to Duplicate:

var appRoot = require('app-root-path'); var models = require(appRoot + '/server/server.js').models;

- cd to another directory in the project, and execute it again.

Expected result:
- It will fail when you attempt to run it from another directory.
- Here is a real life example:

✔ ~/code/iptv master > bin/configure-server.js OK ✔ ~/code/iptv master > cd server ✔ ~/code/iptv/server master* > ../bin/configure-server.js fs.js:856 return binding.readdir(pathModule._makeLong(path)); ^

Error: ENOENT: no such file or directory, scandir '/home/richard/code/iptv/server/server/test-fixtures/' at Error (native) at Object.fs.readdirSync (fs.js:856:18) at loadFixtures (/home/richard/code/iptv/node_modules/loopback-component-fixtures/index.js:40:36) at setupTestFixtures (/home/richard/code/iptv/node_modules/loopback-component-fixtures/index.js:73:5) at /home/richard/code/iptv/node_modules/loopback-boot/lib/executor.js:437:5 at Array.forEach (native) at setupComponents (/home/richard/code/iptv/node_modules/loopback-boot/lib/executor.js:430:27) at execute (/home/richard/code/iptv/node_modules/loopback-boot/lib/executor.js:41:3) at bootLoopBackApp (/home/richard/code/iptv/node_modules/loopback-boot/index.js:154:3) at Object. (/home/richard/code/iptv/server/server.js:23:1) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:20:19)



Suggested fix: Use the app-root-path module or similar, as per the example.
JonathanPrince commented 7 years ago

Hi @richard-fairthorne thank you for pointing this out, will get this resolved in the next few days.

JonathanPrince commented 7 years ago

Hi @richard-fairthorne finally got around to fixing this up using the method you suggested, will be published soon with a few other little changes that i'm planning to make. Thanks again for you input.