Skip to content

Commit

Permalink
Merge pull request #1363 from sasjs/verbose-fix
Browse files Browse the repository at this point in the history
fix(config): fixed verbose mode in getSASjs utility
  • Loading branch information
allanbowe authored Aug 4, 2023
2 parents 831d03a + 7ba8f15 commit 90e1bc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,8 @@ export const getTestTearDown = async (target: Target) => {
* @returns - instance of @sasjs/adapter.
*/
export function getSASjs(target: Target) {
const verbose = process.env.VERBOSE

return new SASjs({
serverUrl: target.serverUrl,
appLoc: target.appLoc,
Expand All @@ -966,7 +968,7 @@ export function getSASjs(target: Target) {
httpsAgentOptions: target.httpsAgentOptions,
debug: true,
useComputeApi: target.serverType === ServerType.SasViya, // compute api is used only on Viya server
verbose: !!process.env.VERBOSE // any not empty string should be considered as true
verbose: typeof verbose === 'string' ? /on/i.test(verbose) : false // only string equal to 'on'(case insensitive) will enable verbose mode
})
}

Expand Down
26 changes: 22 additions & 4 deletions src/utils/spec/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,20 @@ describe('getSASjs', () => {
expect(useComputeApi).toEqual(false)
})

it('should enable verbose mode if VERBOSE env is present', () => {
it(`should enable verbose mode if VERBOSE env is present and is equal to 'on'(case insensitive)`, () => {
process.env.VERBOSE = 'on'

const sasjs = getSASjs({} as Target)
const sasjsConfig = sasjs.getSasjsConfig()
const { verbose } = sasjsConfig
let sasjs = getSASjs({} as Target)
let sasjsConfig = sasjs.getSasjsConfig()
let { verbose } = sasjsConfig

expect(verbose).toEqual(true)

process.env.VERBOSE = 'ON'

sasjs = getSASjs({} as Target)
sasjsConfig = sasjs.getSasjsConfig()
verbose = sasjsConfig.verbose

expect(verbose).toEqual(true)
})
Expand All @@ -575,4 +583,14 @@ describe('getSASjs', () => {

expect(verbose).toEqual(false)
})

it(`should disable verbose mode if VERBOSE env is present and is not equal to 'on'(case insensitive)`, () => {
process.env.VERBOSE = 'start'

const sasjs = getSASjs({} as Target)
const sasjsConfig = sasjs.getSasjsConfig()
const { verbose } = sasjsConfig

expect(verbose).toEqual(false)
})
})

0 comments on commit 90e1bc4

Please sign in to comment.