Skip to content

Commit

Permalink
Merge pull request #37 from snyk-tech-services/develop
Browse files Browse the repository at this point in the history
release debug mode change
  • Loading branch information
aarlaud authored Jun 2, 2020
2 parents 627b7ca + db4604e commit b2f1f94
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 6 additions & 2 deletions src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion test/lib/index-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2f1f94

Please sign in to comment.