From 89d84f62725efdb79d450087bce73456f994a18a Mon Sep 17 00:00:00 2001 From: Liran Tal Date: Mon, 24 May 2021 08:13:21 +0300 Subject: [PATCH] feat: add debug information for commit sha introduced (#6) --- __tests__/__snapshots__/app.test.js.snap | 17 ++++++++++++++++- __tests__/app.test.js | 16 ++++++++++++++-- bin/snync.js | 2 +- src/index.js | 8 +++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/__tests__/__snapshots__/app.test.js.snap b/__tests__/__snapshots__/app.test.js.snap index 5b437c4..3e2cd55 100644 --- a/__tests__/__snapshots__/app.test.js.snap +++ b/__tests__/__snapshots__/app.test.js.snap @@ -1,6 +1,21 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`integration test 1`] = ` +exports[`Debug information prints commit SHA 1`] = ` +" +Reviewing your dependencies... + +Checking dependency: asunc + -> ❌ suspicious + -> introduced via commit sha: b335c1d5b4089833d63c95e846fb1916e6425447 +Checking dependency: a-package-in-private-registry-0 + -> ⚠️ vulnerable + -> introduced via commit sha: 07b2f1c6a5bde9d73e056d67d51ea9bbc7be6ee7 +Checking dependency: lodash + -> introduced via commit sha: 74f0d1666052fd03fc1220351ee087545dba2ec0 +" +`; + +exports[`Sanity test 1`] = ` " Reviewing your dependencies... diff --git a/__tests__/app.test.js b/__tests__/app.test.js index 85ceb30..d8c285d 100644 --- a/__tests__/app.test.js +++ b/__tests__/app.test.js @@ -24,10 +24,22 @@ beforeAll(async () => { } }) -test('integration test', async () => { +test('Sanity test', async () => { const projectPath = path.resolve(path.join(destinationFixtures, 'simple-project')) let out = '' - await testProject(projectPath, (...args) => (out += `${args.join(' ')}\n`)) + await testProject({ projectPath, log: (...args) => (out += `${args.join(' ')}\n`) }) + expect(out).toMatchSnapshot() +}) + +test('Debug information prints commit SHA', async () => { + const projectPath = path.resolve(path.join(destinationFixtures, 'simple-project')) + + let out = '' + await testProject({ + projectPath, + log: (...args) => (out += `${args.join(' ')}\n`), + debugMode: true + }) expect(out).toMatchSnapshot() }) diff --git a/bin/snync.js b/bin/snync.js index baa6bd9..2402c13 100644 --- a/bin/snync.js +++ b/bin/snync.js @@ -20,5 +20,5 @@ async function main() { process.exit(-1) } - await testProject(projectPath, console.log) + await testProject({ projectPath, log: console.log }) } diff --git a/src/index.js b/src/index.js index ca3e2ee..bd640dc 100644 --- a/src/index.js +++ b/src/index.js @@ -4,9 +4,10 @@ const RepoManager = require('../src/RepoManager') const Parser = require('../src/Parser') const RegistryClient = require('../src/RegistryClient') -async function testProject(projectPath, log) { +async function testProject({ projectPath, log, debugMode }) { const registryClient = new RegistryClient() const repoManager = new RepoManager({ directoryPath: projectPath }) + const parser = new Parser({ directoryPath: projectPath, manifestType: 'npm' @@ -53,9 +54,14 @@ async function testProject(projectPath, log) { timestampOfPackageInSource, timestampOfPackageInRegistry }) + if (status) { log(' -> ', status) } + + if (debugMode) { + log(' -> introduced via commit sha: ', earliestSnapshotPerDependency[dependency].hash) + } } }