Skip to content

Commit

Permalink
feat: add debug information for commit sha introduced (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal authored May 24, 2021
1 parent b06309b commit 89d84f6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
17 changes: 16 additions & 1 deletion __tests__/__snapshots__/app.test.js.snap
Original file line number Diff line number Diff line change
@@ -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...
Expand Down
16 changes: 14 additions & 2 deletions __tests__/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
2 changes: 1 addition & 1 deletion bin/snync.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ async function main() {
process.exit(-1)
}

await testProject(projectPath, console.log)
await testProject({ projectPath, log: console.log })
}
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 89d84f6

Please sign in to comment.