lirantal / lockfile-lint

Lint an npm or yarn lockfile to analyze and detect security issues
Apache License 2.0
781 stars 35 forks source link

Some tests seem to be testing the wrong thing #77

Closed bolatovumar closed 4 years ago

bolatovumar commented 4 years ago

Four tests in validators.host.test.js test that the validate method does not throw. Instead these tests should be checking the result object equality since validate method never throws.

See this test for example: https://github.com/lirantal/lockfile-lint/blob/master/packages/lockfile-lint-api/__tests__/validators.host.test.js#L45. It does this:

expect(() => {
  validator.validate(['npm'])
}).not.toThrow()

Instead, it should do this:

expect(validator.validate(['npm'])).toEqual({
  type: 'success',
  errors: []
})
lirantal commented 4 years ago

Ahh, good catch. There are some cases when they throw though: https://github.com/lirantal/lockfile-lint/blob/master/packages/lockfile-lint-api/src/validators/ValidateHost.js#L18

I agree however that the tests haven't been fixed for the newly returned values of success/errors. Let's finish the other PR you're working on and get to this next. Thanks for bringing it up 🙏