Closed
Description
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Should be able to run test files directly. It turns out that we can not do this for all files.
If the current behavior is a bug, please provide the steps to reproduce.
$ npx mocha --exit test/utils.test.js
/home/stieg/Devel/airfordable/mongoose/lib/types/buffer.js:7
const Binary = require('../driver').get().Binary;
^
TypeError: Cannot read property 'Binary' of null
at Object.<anonymous> (/home/stieg/Devel/airfordable/mongoose/lib/types/buffer.js:7:42)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at Object.<anonymous> (/home/stieg/Devel/airfordable/mongoose/test/utils.test.js:8:24)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Module.require (internal/modules/cjs/loader.js:830:19)
at require (internal/modules/cjs/helpers.js:68:18)
at /home/stieg/Devel/airfordable/mongoose/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/home/stieg/Devel/airfordable/mongoose/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/home/stieg/Devel/airfordable/mongoose/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (/home/stieg/Devel/airfordable/mongoose/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (internal/modules/cjs/loader.js:936:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
at Module.load (internal/modules/cjs/loader.js:790:32)
at Function.Module._load (internal/modules/cjs/loader.js:703:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
at internal/main/run_main_module.js:17:11
What is the expected behavior?*
This should work so we can expedite testing.
Issue is that the driver is not set when run directly, but is set when when you run the npm test
target. Based on the value of the target nothing special is being set so this is likely a run order bug.