Skip to content

Commit

Permalink
feat(errors): provide the actual bad string in ValidateScheme (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
pratik97 authored and lirantal committed Nov 7, 2019
1 parent dfa2a30 commit 45fb7d2
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/lockfile-lint-api/__tests__/validators.host.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Validator: Host', () => {
type: 'error',
errors: [
{
message: 'detected invalid host for package: @babel/code-frame',
message: `detected invalid host(s) for package: @babel/code-frame\n expected: registry.npmjs.org\n actual: registry.yarnpkg.com\n`,
package: '@babel/code-frame'
}
]
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('Validator: Host', () => {
type: 'error',
errors: [
{
message: 'detected invalid host for package: @babel/code-frame',
message: `detected invalid host(s) for package: @babel/code-frame\n expected: registry.npmjs.org,github.com\n actual: registry.yarnpkg.com\n`,
package: '@babel/code-frame'
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Validator: HTTPS', () => {
type: 'error',
errors: [
{
message: `detected non-https protocol used for package: ${failedPackage}`,
message: `detected invalid protocol for package: ${failedPackage}\n expected: https:\n actual: http:\n`,
package: failedPackage
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Validator: Protocol', () => {
type: 'error',
errors: [
{
message: `detected invalid scheme for package: meow`,
message: `detected invalid scheme(s) for package: meow\n expected: ${allowedProtocols}\n actual: http:\n`,
package: 'meow'
},
{
message: `detected invalid scheme for package: @babel/generator`,
message: `detected invalid scheme(s) for package: @babel/generator\n expected: ${allowedProtocols}\n actual: git+ssh:\n`,
package: '@babel/generator'
}
]
Expand Down
4 changes: 3 additions & 1 deletion packages/lockfile-lint-api/src/validators/ValidateHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ module.exports = class ValidateHost {
if (allowedHosts.indexOf(packageResolvedURL.host) === -1) {
// throw new Error(`detected invalid origin for package: ${packageName}`)
validationResult.errors.push({
message: `detected invalid host for package: ${packageName}`,
message: `detected invalid host(s) for package: ${packageName}\n expected: ${allowedHosts}\n actual: ${
packageResolvedURL.host
}\n`,
package: packageName
})
}
Expand Down
4 changes: 3 additions & 1 deletion packages/lockfile-lint-api/src/validators/ValidateHttps.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ module.exports = class ValidateHttps {

if (packageResolvedURL.protocol !== HTTPS_PROTOCOL) {
validationResult.errors.push({
message: `detected non-https protocol used for package: ${packageName}`,
message: `detected invalid protocol for package: ${packageName}\n expected: ${HTTPS_PROTOCOL}\n actual: ${
packageResolvedURL.protocol
}\n`,
package: packageName
})
}
Expand Down
5 changes: 3 additions & 2 deletions packages/lockfile-lint-api/src/validators/ValidateScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ module.exports = class ValidateProtocol {
} catch (error) {
throw new PackageError(packageName, error)
}

if (schemes.indexOf(packageResolvedURL.protocol) === -1) {
// throw new Error(`detected invalid origin for package: ${packageName}`)
validationResult.errors.push({
message: `detected invalid scheme for package: ${packageName}`,
message: `detected invalid scheme(s) for package: ${packageName}\n expected: ${schemes}\n actual: ${
packageResolvedURL.protocol
}\n`,
package: packageName
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/lockfile-lint/__tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ describe('CLI tests', () => {
})

process.stdout.on('close', exit => {
expect(output.indexOf('detected non-https protocol used for package: debug@^4.1.1')).not.toBe(
expect(output.indexOf('detected invalid protocol for package: debug@^4.1.1\n expected: https:\n actual: http:\n')).not.toBe(
-1
)
expect(output.indexOf('detected non-https protocol used for package: ms@^2.1.1')).not.toBe(-1)
expect(output.indexOf('detected invalid protocol for package: ms@^2.1.1\n expected: https:\n actual: http:\n')).not.toBe(-1)
expect(output.indexOf('error: command failed with exit code 1')).not.toBe(-1)
done()
})
Expand Down
4 changes: 2 additions & 2 deletions packages/lockfile-lint/bin/lockfile-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ try {
console.error('ABORTING lockfile lint process due to error exceptions', '\n')
console.error(error.message, '\n')
console.error(error.stack, '\n')
console.error('error: command failed with exit code 1')
console.error('error: command failed with exit code 1', '\n')
process.exit(1)
}

Expand All @@ -45,6 +45,6 @@ debug(`total validator failures: ${validatorFailures}`)
debug(`total validator successes: ${validatorSuccesses}`)

if (validatorFailures !== 0) {
console.error('error: command failed with exit code 1')
console.error('error: command failed with exit code 1', '\n')
process.exit(1)
}

0 comments on commit 45fb7d2

Please sign in to comment.