npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nest-commander-testing

v3.3.0

Published

A testing utility for nest-commander. It builds on top of ideas from @nestjs/testing and is not tied to any test framework directly.

Downloads

49,069

Readme

NestJS Commander Testing

So you;'ve built a CLI application, but you want to test it, and you want to be able to do your usual NestJS DI mocking. Well, here's your solution :fireworks:

Installation

Before you get started, you'll need to install a few packages. First and foremost, this one: nest-commander-testing (name pending). You'll also need to install @nestjs/testing as this package makes use of them under the hood, but doesn't want to tie you down to a specific version, yay peerDependencies!

npm i nest-commander-testing @nestjs/testing
# OR
yarn add nest-commander-testing @nestjs/testing
# OR
pnpm i nest-commander-testing @nestjs/testing

Testing With Mocks

So what's the use of writing a super awesome command line script if you can't test it super easily, right? Fortunately, nest-commander has some utilities you can make use of that fits in perfectly with the NestJS ecosystem, it'll feel right at home to any Nestlings out there. Instead of using the CommandFactory for building the command in test mode, you can use CommandTestFactory and pass in your metadata, very similarly to how Test.createTestingModule from @nestjs/testing works. In fact, it uses this package under the hood. You're also still able to chain on the overrideProvider methods before calling compile() so you can swap out DI pieces right in the test. A nice example of this can be seen in the basic.command.factory.spec.ts file.

Testing Inquirer Questions

If you are making use of the InquirerService, you can use CommandTestFactory.setAnswers method and pass either a single answer or multiple answers depending on how many answers you need to mock. In doing so, a mock inquirer service will act similarly to inquirer without needing to modify process.stdin or make use of any user input, allowing smooth testing in your CI pipelines. For an example of this, please check the pizza command integration test.