Saturday, 3 June 2017

mocha help needed, intelligent requires without full reference?

I didn't really know how to title this post, but I was hoping there would be a more efficient way to do things than what I am using currently.I have a project and the file structure for my code and then my tests is, starting from the root. bot/MYCODE and then tests/MYCODE I have designed it so that the tests are arranged as a mirror to the arrangement of files in the bot folder. So the test file for bot/utilities.js is located at tests/utilities.js This is preferably how I would like to do things, as I am building my bot file with docker and having tests in the bot folder adds unnecessary bloat. This has caused an issue for me, in the file tests/utilities.js, I don't want to have to reference the other file like this.require(../bot/utilities.js) Although this seems painless at the top level of the tests directory, once I work my way down to a file, for example tests/handlers/somefolder/somefile.js I will end up having to write code that looks like this.require('../../../../bot/handlers/somefolder/somefile.js') which is obviously less than ideal. So is there a way I can configure node to detect this file structure, therefore letting my write something just like.require('somefile.js') or evenrequire('somefile') Thanks in advance, any help would be appreciated.

Submitted June 04, 2017 at 04:18AM by AmITheRealI

No comments:

Post a Comment