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

refactor: set default test options #1704

Merged
merged 3 commits into from
Mar 12, 2021
Merged

Conversation

lili2311
Copy link
Contributor

@lili2311 lili2311 commented Mar 10, 2021

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

refactor settings default test options so it can be re-used in another command that relies on test running first

@lili2311 lili2311 self-assigned this Mar 10, 2021
@lili2311 lili2311 requested review from a team as code owners March 10, 2021 11:58
@lili2311 lili2311 force-pushed the refactor/set-default-test-options branch from 5e4b887 to c12977a Compare March 10, 2021 13:43
Copy link
Contributor

@aviadhahami aviadhahami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :)

import * as config from '../../../lib/config';
import { Options, ShowVulnPaths, TestOptions } from '../../../lib/types';

export function setDefaultTestOptions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should keep adding jest-unit test for these new modules

Copy link
Contributor Author

@lili2311 lili2311 Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are these structured? Right now I am dumping all new tests into top level test directory because of the jest pattern restrictions 😢 can we update this to allow us to add tests in correct folder structures instead?

  • code: unit/src/lib/index.ts
  • test: test/lib/index.spec.ts? Maybe for now test/jest/unit/lib/index.spec.ts until we fully migrate to Jest?

It will be hard to separate jest tests later from system/acceptance/unit etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added, please advise if it can move somewhere better than top level of test directory


export function setDefaultTestOptions(options: Options): Options & TestOptions {
const svpSupplied = (options['show-vulnerable-paths'] || '')
.toString()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this essentially adds support for --show-vulnerable-paths to be treated as --show-vulnerable-paths=true WDYT?

Otherwise if you run test with snyk test --show-vulnerable-paths you get a bad error that says
toLowerCase is not a function because it is not a string. Or alternative is to add validation for this options and throw outside of this function somewhere probably

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this sounds in line with how arg parsing libraries should treat this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitphill while @aviadhahami is off, could you help 👀 ?

@lili2311 lili2311 force-pushed the refactor/set-default-test-options branch from c47c9db to 0545ea6 Compare March 11, 2021 18:30
@lili2311 lili2311 requested a review from a team as a code owner March 11, 2021 18:30
@lili2311 lili2311 requested a review from orkamara March 11, 2021 18:30
@lili2311 lili2311 force-pushed the refactor/set-default-test-options branch from 0545ea6 to 249a43d Compare March 11, 2021 18:31
@lili2311 lili2311 requested review from JackuB and aviadhahami March 12, 2021 09:46
@@ -13,8 +13,7 @@ export type DepTree = legacyApi.DepTree;
export type ShowVulnPaths = 'none' | 'some' | 'all';

export interface TestOptions {
traverseNodeModules: boolean;
interactive: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a protect option for wizard only


export function setDefaultTestOptions(options: Options): Options & TestOptions {
const svpSupplied = (options['show-vulnerable-paths'] || '')
.toString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this sounds in line with how arg parsing libraries should treat this

it('defaults to show-vulnerable-paths:some & org from config when no options passed in', () => {
const updated = setDefaultTestOptions({ path: '/' });
expect(updated).toEqual({
org: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, in the jest's equals logic, is org: undefined same as not having org key at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does indeed!

@lili2311 lili2311 force-pushed the refactor/set-default-test-options branch from 249a43d to 0f2ee40 Compare March 12, 2021 10:59
@JackuB
Copy link
Contributor

JackuB commented Mar 12, 2021

Just a nit, noticed a typo in the commit message, which would propagate it to the release notes:

features:
- delete vuln paths option once transofrmed + tests
+ delete vuln paths option once transformed

Add tests for the setDefaultTestOptions()
@lili2311 lili2311 force-pushed the refactor/set-default-test-options branch from 0f2ee40 to 442e37f Compare March 12, 2021 12:55
@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2021

Expected release notes (by @lili2311)

features:
delete vuln paths option once transformed (442e37f)

others (will not be included in Semantic-Release notes):
update Protect types (15dce36)
set default test options (4c3fbf9)
Remove writeable stream to skip writing tarball to the disk. (c1ca6d4)
install AWS CLI in the release step (d2266c1)

  • I hereby acknowledge these release notes are 🥙 AWESOME 🥙

This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants