Skip to content

test(prompt.js): enhance prompt.js test coverage#438

Merged
lwasser merged 2 commits intoall-contributors:mainfrom
lwasser:prompt-tests
Mar 1, 2026
Merged

test(prompt.js): enhance prompt.js test coverage#438
lwasser merged 2 commits intoall-contributors:mainfrom
lwasser:prompt-tests

Conversation

@lwasser
Copy link
Member

@lwasser lwasser commented Feb 13, 2026

This PR enhances test coverage for prompt.js. I started here because there were issues in the CLI with prompts not working, and the module was largely uncovered by tests. This PR adds tests and fixes several bugs I identified along the way.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

return inquirer.prompt(questions).then(_.assign(defaults))
}

module.exports.getQuestions = getQuestions
Copy link
Member Author

Choose a reason for hiding this comment

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

/** @testonly */

i tried this but knip continues to flag these imports

Copy link
Member Author

Choose a reason for hiding this comment

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

Interestingly, it's only flagging 1 or the two unused imports. I'm not sure why. @JoshuaKGoldberg, do you have any ideas why this might be getting flagged by Knip or what I'm doing wrong? many thanks!!

src/cli.js Outdated
}

run()
if (require.main === module) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I want to be able to test the individual functions in these modules. if there is a better way i'm very interested in that. but this just allows us to explore addContribution but also use cli.js as a cli too - i'm not sure what the best way to do this is in general as knip does not like these exports that are test only .

@lwasser lwasser marked this pull request as ready for review February 14, 2026 19:48
@lwasser
Copy link
Member Author

lwasser commented Feb 14, 2026

Ok friends - this led me down a rabbit hole! I am stopping here, but we need more test coverage. I found a bunch of bugs in the CLI and fixed them here, but we need tests for the CLI itself, which I opened #439 for that effort. It will require some more mocking. Please test this pr locally to ensure the CLI runs as expected!

My biggest issue right now is figuring out how to export functions for use in tests without making Knip angry. I tried ignore but it's still failing the pr

Test coverage has increased a lot with this pr but codecov is failing it because there is still a lot of uncovered code. (specifically the cli.js module needs more tests.

@lwasser lwasser marked this pull request as draft February 14, 2026 21:16
@lwasser lwasser force-pushed the prompt-tests branch 4 times, most recently from f4fadc2 to ffec72e Compare February 20, 2026 02:27
@lwasser lwasser marked this pull request as ready for review February 28, 2026 00:43
@lwasser
Copy link
Member Author

lwasser commented Feb 28, 2026

Ok i'd love a review of this. This is my first time writing tests in node and it seems there are some foundational differences between how node vs python works - both in docstrings / documentation and also exports and imports. Everything is running now but I'd love a careful review to ensure this looks OK as is (or did I break some node conventions that I don't know about!!).

Generally, do node developers not add docstrings? I ask because i'm used to docstrings that you can then automatically turn into api docs

and also is exporting functions so we can test them ok? i've read different things about this too but unit tests seems important here for us.

thank you for any and all feedback!!

@lwasser lwasser requested a review from jdalrymple February 28, 2026 00:45
@lwasser
Copy link
Member Author

lwasser commented Mar 1, 2026

Thanks for the review @Berkmann18 !! i'll merge.

@lwasser lwasser merged commit 03eb6e8 into all-contributors:main Mar 1, 2026
5 checks passed
@lwasser lwasser deleted the prompt-tests branch March 1, 2026 17:49
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.

3 participants