Node object karma fs empty

I am trying to run multiple tests on node using karma. I am using both phantom and real browsers.

Whichever way I run, I get an error in fs read file functions.

 'undefined' is not an object (evaluating 'fs.existsSync')

      

This is even if I have a very simple file like:

var fs = require('fs');
console.error(fs);
var text = fs.readFile('data.txt', 'utf8');

      

The first console writes out Object {}. The second is giving me the above error. I am assuming the object is empty.

I am using the latest karma and dependencies.

Can someone point me in the right direction as to why the fs object is empty / not working.

+3


source to share


1 answer


Karma is a client side test run where you cannot use the node filesystem. To test js server side, I suggest using another test runner like Mocha. If you are using Mocha for the js server specifically nodejs, you will be able to use the node.



There is another way to read the file from the client using XMLHttpRequest()

. Please refer to this question Javascript - read local text file

0


source







All Articles