1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-15 16:10:06 +00:00

fix(streamlog): use filepath if provided

This commit is contained in:
Krishna Acondy
2021-07-22 09:25:55 +01:00
parent c02eac196e
commit 0bb42c5e3c
4 changed files with 63 additions and 44 deletions

View File

@@ -1,4 +1,5 @@
import { Logger, LogLevel } from '@sasjs/utils'
import * as path from 'path'
import * as fileModule from '@sasjs/utils/file'
import { RequestClient } from '../../../request/RequestClient'
import { mockAuthConfig, mockJob } from './mockResponses'
@@ -85,6 +86,35 @@ describe('pollJobState', () => {
expect(saveLogModule.saveLog).toHaveBeenCalledTimes(2)
})
it('should use the given log path if it points to a file', async () => {
mockSimplePoll()
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
...defaultPollOptions,
streamLog: true,
logFolderPath: path.join(__dirname, 'test.log')
})
expect(fileModule.createWriteStream).toHaveBeenCalledWith(
path.join(__dirname, 'test.log')
)
})
it('should generate a log file path with a timestamp if it points to a folder', async () => {
mockSimplePoll()
await pollJobState(requestClient, mockJob, false, mockAuthConfig, {
...defaultPollOptions,
streamLog: true,
logFolderPath: path.join(__dirname)
})
expect(fileModule.createWriteStream).not.toHaveBeenCalledWith(__dirname)
expect(fileModule.createWriteStream).toHaveBeenCalledWith(
expect.stringContaining(__dirname + '/20')
)
})
it('should not attempt to fetch and save the log after each poll when streamLog is false', async () => {
mockSimplePoll()