Skip to content

test: add coverage for phantom-utils (getDeclaredPackages and installCmd) #1088

Description

@sonukapoor

This issue is reserved for first-time contributors. If you have contributed to open source before, please leave it for someone who has not. There are other issues labelled good first issue that are not reserved.

The task

src/overrides/detectors/phantom-utils.ts has two small functions and no tests. Both are pure, so no mocking or setup is needed.

What the functions do

getDeclaredPackages(packageJson) collects every dependency name declared across dependencies, devDependencies, peerDependencies and optionalDependencies, and returns them as a Set.

installCmd(packageManager) maps a package manager to its install command: pnpm gives pnpm add, yarn gives yarn add, bun gives bun add, and anything else gives npm install.

Steps

  1. Comment here saying you would like to take it, so nobody duplicates your work.
  2. Fork the repo and create a branch, for example test/phantom-utils-coverage.
  3. Run npm install then npm test to confirm a clean starting point.
  4. Create tests/overrides/phantom-utils.test.ts. Look at any file in tests/ for the house style; the imports use a .js extension even though the files are TypeScript, which is expected.
  5. Write the tests. Suggested cases:
    • collects names from all four dependency sections
    • returns an empty set for an empty package.json
    • ignores a section that is an array rather than an object
    • ignores a section that is null
    • deduplicates a package that appears in two sections
    • returns the right command for each of pnpm, yarn, bun, npm
  6. Run npm test and confirm everything passes.
  7. Open a pull request with Closes #NNN in the body, using this issue's number.

Tips

Prefer one behaviour per test with a name that says what the behaviour is. it("deduplicates a package declared in two sections") is better than it("works").

Ask questions here if anything is unclear. A question is not a bother, and getting stuck is normal.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    first-timers-onlyReserved for contributors making their first contribution to this projectgood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions