-
Notifications
You must be signed in to change notification settings - Fork 555
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:exit code 3 when no projects detected #1386
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,9 @@ function executeTest(root, options) { | |
return results; | ||
}); | ||
} catch (error) { | ||
return Promise.reject(chalk.red.bold(error)); | ||
return Promise.reject( | ||
chalk.red.bold(error.message ? error.message : error), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix to drop |
||
); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,28 @@ Describe "Snyk test command" | |
snyk test | ||
} | ||
|
||
run_test_in_empty_subfolder() { | ||
cd ../fixtures/empty || return | ||
snyk test | ||
} | ||
|
||
It "throws error when file does not exist" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
When run snyk test --file=non-existent/package.json | ||
The status should equal 2 | ||
The output should include "Could not find the specified file" | ||
The stderr should equal "" | ||
End | ||
|
||
It "throws error when no suppored manifests detected" | ||
When run run_test_in_empty_subfolder | ||
The status should equal 3 | ||
The output should include "Could not detect supported target files in" | ||
The stderr should equal "" | ||
End | ||
|
||
It "finds vulns in a project in the same folder" | ||
When run run_test_in_subfolder | ||
The status should be failure # issues found | ||
The status should equal 1 | ||
The output should include "https://snyk.io/vuln/npm:minimatch:20160620" | ||
The stderr should equal "" | ||
End | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { test } from 'tap'; | ||
import { exec } from 'child_process'; | ||
import { sep, join } from 'path'; | ||
import { readFileSync, unlinkSync, rmdirSync, mkdirSync, existsSync } from 'fs'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
const osName = require('os-name'); | ||
|
||
const main = './dist/cli/index.js'.replace(/\//g, sep); | ||
const iswindows = | ||
osName() | ||
.toLowerCase() | ||
.indexOf('windows') === 0; | ||
|
||
test('`test --json-file-output can save JSON output to file while sending human readable output to stdout`', (t) => { | ||
t.plan(2); | ||
|
||
exec( | ||
`node ${main} test --json-file-output=snyk-direct-json-test-output.json`, | ||
(err, stdout) => { | ||
if (err) { | ||
throw err; | ||
} | ||
t.match(stdout, 'Organization:', 'contains human readable output'); | ||
const outputFileContents = readFileSync( | ||
'snyk-direct-json-test-output.json', | ||
'utf-8', | ||
); | ||
unlinkSync('./snyk-direct-json-test-output.json'); | ||
const jsonObj = JSON.parse(outputFileContents); | ||
const okValue = jsonObj.ok as boolean; | ||
t.ok(okValue, 'JSON output ok'); | ||
}, | ||
); | ||
}); | ||
|
||
test('`test --json-file-output produces same JSON output as normal JSON output to stdout`', (t) => { | ||
t.plan(1); | ||
|
||
exec( | ||
`node ${main} test --json --json-file-output=snyk-direct-json-test-output.json`, | ||
(err, stdout) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const stdoutJson = stdout; | ||
const outputFileContents = readFileSync( | ||
'snyk-direct-json-test-output.json', | ||
'utf-8', | ||
); | ||
unlinkSync('./snyk-direct-json-test-output.json'); | ||
t.equals(stdoutJson, outputFileContents); | ||
}, | ||
); | ||
}); | ||
|
||
test('`test --json-file-output can handle a relative path`', (t) => { | ||
t.plan(1); | ||
|
||
// if 'test-output' doesn't exist, created it | ||
if (!existsSync('test-output')) { | ||
mkdirSync('test-output'); | ||
} | ||
|
||
const tempFolder = uuidv4(); | ||
const outputPath = `test-output/${tempFolder}/snyk-direct-json-test-output.json`; | ||
|
||
exec( | ||
`node ${main} test --json --json-file-output=${outputPath}`, | ||
(err, stdout) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const stdoutJson = stdout; | ||
const outputFileContents = readFileSync(outputPath, 'utf-8'); | ||
unlinkSync(outputPath); | ||
rmdirSync(`test-output/${tempFolder}`); | ||
t.equals(stdoutJson, outputFileContents); | ||
}, | ||
); | ||
}); | ||
|
||
test( | ||
'`test --json-file-output can handle an absolute path`', | ||
{ skip: iswindows }, | ||
(t) => { | ||
t.plan(1); | ||
|
||
// if 'test-output' doesn't exist, created it | ||
if (!existsSync('test-output')) { | ||
mkdirSync('test-output'); | ||
} | ||
|
||
const tempFolder = uuidv4(); | ||
const outputPath = join( | ||
process.cwd(), | ||
`test-output/${tempFolder}/snyk-direct-json-test-output.json`, | ||
); | ||
|
||
exec( | ||
`node ${main} test --json --json-file-output=${outputPath}`, | ||
(err, stdout) => { | ||
if (err) { | ||
throw err; | ||
} | ||
const stdoutJson = stdout; | ||
const outputFileContents = readFileSync(outputPath, 'utf-8'); | ||
unlinkSync(outputPath); | ||
rmdirSync(`test-output/${tempFolder}`); | ||
t.equals(stdoutJson, outputFileContents); | ||
}, | ||
); | ||
}, | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please also document this somewhere? Readme or help.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented:
snyk help