mercredi 2 septembre 2015

Mocha unit testing - not able to get stdin or stdout

I'm very new to asynch and mocha as a testing frame work. I am testing my programme and the first test I want to check is if the console.logs are the same, I can't seem to get any value from stdout.

This is the test I am running at the moment

    describe('Test', function () {
before(helpers.setup)

describe('From file', function (done) {

  it('read contents of the file', function (done) {
    exec('cat ' + __dirname + '/../script/mycsv.csv  | NODE_ENV=development ' + __dirname + '../scripts/fileimtesting --branch branch --organisation org, function (err, stdout, stderr) {
      var lines = stdout.split('\n')

      console.log(stdin)        
      should(lines[0]).equal("READING FILE FROM LOCAL SYSTEM")
      should(lines[1]).equal("PARSING DOCUMENT")


      done()


    })
  })
})
})

Where the section of code i'm reading the file in from is

 fs.readFile("/dev/stdin", "utf8", function(error, contents) {
        console.log("READING FILE FROM LOCAL SYSTEM")
        readCSV(contents.toString())
    });

My understanding is lacking severely, any idea how to go about what I am trying to achieve. I am logging the expected lines in the script I wrote, is there a similar thing such as "stream.on" I have to use when testing things that use fs.readFile.

Hopefully this made sense...

Aucun commentaire:

Enregistrer un commentaire