Skip to content

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

Draft
lwasser wants to merge 6 commits intoall-contributors:mainfrom
lwasser:prompt-tests
Draft

test(prompt.js): enhance prompt.js test coverage#438
lwasser wants to merge 6 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!!

// ensure the config file exists
await util.configFile.readConfig(argv.config)
const configData = await util.configFile.readConfig(argv.config)
Object.assign(argv, configData)
Copy link
Member Author

Choose a reason for hiding this comment

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

This returns NULL if you don't assign the outputs here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea I saw this (and also introduced it haha oops) - Proper fix is in #440

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you!! We can merge 440 first. i'll rebase here and update tests as needed. i'll actually move this to draft for the time being until that is done!

}

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 .

import generate from '../index.js'
import contributors from './fixtures/contributors.json'

/**
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've added docstrings using JSDoc throughout. make it easier to read everything.

})

/**
* Tests that addContributor calls infoFetcher with the correct arguments
Copy link
Member Author

Choose a reason for hiding this comment

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

This tests for the assignment error, which was a part of why the CLI was failing previously. The config data were not being populated


function fixtures() {
const options = {
repoType: 'github',
Copy link
Member Author

Choose a reason for hiding this comment

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

Essentially, in the test, I was seeing null lwasser vs github lwasser.

@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.


/**
* Tests that addContributor properly propagates errors when infoFetcher rejects.
* The same error should be returned without being swallowed or transformed.
Copy link
Member Author

Choose a reason for hiding this comment

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

Essentially, we had stacking bugs here... so the errors didn't fully represent what was going wrong and it wasn't clear where the actual bugs were.

@lwasser lwasser marked this pull request as draft February 14, 2026 21:16
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.

2 participants