Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/debug commit sha #6

Merged
merged 2 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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