diff --git a/src/lib/index.ts b/src/lib/index.ts index a1fff8f..a0c007b 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -17,8 +17,8 @@ Snyk Tech Prevent Tool ` -const getDelta = async(snykTestOutput: string = '') => { - const argv = utils.init() +const getDelta = async(snykTestOutput: string = '', debugMode = false) => { + const argv = utils.init(debugMode) const debug = utils.getDebugModule() const mode = argv.currentProject || argv.currentOrg ? "standalone" : "inline" diff --git a/src/lib/utils/utils.ts b/src/lib/utils/utils.ts index c69621f..c65b6d5 100644 --- a/src/lib/utils/utils.ts +++ b/src/lib/utils/utils.ts @@ -16,7 +16,11 @@ const getDebugModule = () => { return debug } -const init = () => { +export interface ModuleOptions { + debug: boolean +} + +const init = (debugMode = false) => { const pkgJSONPath = fs.existsSync(__dirname+'/../../../package.json')? __dirname+'/../../../package.json' : path.dirname(path.dirname(__dirname))+'/package.json' const pkgJSON = JSON.parse(fs.readFileSync(pkgJSONPath).toString()) @@ -46,7 +50,7 @@ const init = () => { .version(pkgJSON.version) .argv; - if (argv.debug || argv.d) { + if (argv.debug || argv.d || debugMode) { let enable = DEBUG_DEFAULT_NAMESPACES.join(','); if (process.env.DEBUG) { enable += ',' + process.env.DEBUG; diff --git a/test/lib/index-module.test.ts b/test/lib/index-module.test.ts index 116b6b9..f4eda62 100644 --- a/test/lib/index-module.test.ts +++ b/test/lib/index-module.test.ts @@ -2,9 +2,10 @@ import * as nock from 'nock'; import * as path from 'path'; import * as fs from 'fs'; //process.argv.push('-d'); +import * as debug from 'debug'; import { getDelta } from '../../src/lib/index'; - +import { ModuleOptions } from '../../src/lib/utils/utils'; const fixturesFolderPath = path.resolve(__dirname, '..') + '/fixtures/'; const originalLog = console.log; @@ -70,6 +71,18 @@ describe('Test End 2 End - Module', () => { expect(result).toEqual(0); }); + it('Test module debug mode - no new issue', async () => { + const result = await getDelta( + fs + .readFileSync(fixturesFolderPath + 'snykTestsOutputs/test-goof.json') + .toString(), + true, + ); + expect(debug('snyk')).toBeTruthy(); + expect(consoleOutput).toContain('No new issues found !'); + expect(result).toEqual(0); + }); + it('Test module mode - 1 new issue', async () => { const result = await getDelta( fs