test: add coverage for phantom-utils (getDeclaredPackages and installCmd)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 715
- Forks
- 145
- Avg merge
- 21h 39m
- Merged PRs (30d)
- 66
Description
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
- Comment here saying you would like to take it, so nobody duplicates your work.
- Fork the repo and create a branch, for example
test/phantom-utils-coverage. - Run
npm installthennpm testto confirm a clean starting point. - Create
tests/overrides/phantom-utils.test.ts. Look at any file intests/for the house style; the imports use a.jsextension even though the files are TypeScript, which is expected. - 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
- Run
npm testand confirm everything passes. - Open a pull request with
Closes #NNNin 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading src/overrides/detectors/phantom-utils.ts and a nearby file in tests/ for the house style. Run npm install and npm test, then add tests/overrides/phantom-utils.test.ts covering the listed dependency-section and package-manager cases. Done means the new tests pass with npm test and the pull request references this issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100