Within a karma test beforeEach) block I would like to access (read) a file from the project directory. However, I do not know how to get access to that directory, since process.cwd() returns the directory the test is running in, which is a random private dir assigned by node or gulp.
How can I find what the project dir is within a running test?
describe.only('convertClaimTypes', function () {
var claimTypes;
before(function () {
var base = process.cwd();
claimTypes = fs.readFileSync(path.join(base, 'build/resources/claimTypes.json'));
claimTypes = JSON.parse(claimTypes);
});
...
Try using
__dirname
in place ofprocess.cwd()
as it gives you the directory of the current file rather than the directory of the executable.For example, if your tests are within a directory
/test
and/build
is a directory within the root of your application, access/build
from/test
like so: