From 3b17ba8e8bd1ec99e5166dcdb8e21ad5b98da8ff Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 27 Jun 2022 11:29:27 -0700 Subject: [PATCH] fix(logapi): Fixing issues with unit tests --- src/adapters/logapi.js | 4 +++- test/unit/adapters/logapi.adapter.unit.js | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/adapters/logapi.js b/src/adapters/logapi.js index dbb4ac5..8ec4c7a 100644 --- a/src/adapters/logapi.js +++ b/src/adapters/logapi.js @@ -135,8 +135,10 @@ class LogsApi { if (!filename || typeof filename !== 'string') { throw new Error('filename must be a string') } - // Throw an error if the file does not exist. + console.log('readLines() filename: ', filename) + + // Throw an error if the file does not exist. if (!_this.fs.existsSync(filename)) { throw new Error('file does not exist') } diff --git a/test/unit/adapters/logapi.adapter.unit.js b/test/unit/adapters/logapi.adapter.unit.js index bae3567..aab7d20 100644 --- a/test/unit/adapters/logapi.adapter.unit.js +++ b/test/unit/adapters/logapi.adapter.unit.js @@ -32,6 +32,9 @@ describe('#LogsApiLib', () => { }) it('should return log', async () => { + // Mock dependencies + sandbox.stub(uut, 'generateFileName').returns(`${__dirname.toString()}/../mocks/adapters/test.log`) + const pass = 'test' const result = await uut.getLogs(pass) // console.log('result', result) @@ -201,13 +204,15 @@ describe('#LogsApiLib', () => { // About yields sandbox.stub(uut.lineReader, 'eachLine').yieldsRight({}, true) - const fileName = context.fileName + const fileName = `${__dirname.toString()}/../mocks/adapters/test.log` + const result = await uut.readLines(fileName) assert.isArray(result) }) it('should return data', async () => { - const fileName = context.fileName + const fileName = `${__dirname.toString()}/../mocks/adapters/test.log` + const result = await uut.readLines(fileName) assert.isArray(result)