Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oclif/test

Package Overview
Dependencies
Maintainers
3
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oclif/test

test helpers for oclif components

  • 0.10.16
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
183K
increased by4.03%
Maintainers
3
Weekly downloads
 
Created

What is @oclif/test?

@oclif/test is a testing framework specifically designed for testing oclif-based CLI applications. It provides utilities to simulate command execution, check outputs, and handle various test scenarios.

What are @oclif/test's main functionalities?

Simulate Command Execution

This feature allows you to simulate the execution of a CLI command and check the output. In this example, the command 'hello --name world' is executed, and the test checks if the output contains 'hello world'.

const {expect, test} = require('@oclif/test');

test
  .stdout()
  .command(['hello', '--name', 'world'])
  .it('runs hello --name world', ctx => {
    expect(ctx.stdout).to.contain('hello world');
  });

Check Command Errors

This feature allows you to test how your CLI handles errors. In this example, the command 'hello --name' is missing a required value, and the test checks if the error message contains 'Missing required flag'.

const {expect, test} = require('@oclif/test');

test
  .stderr()
  .command(['hello', '--name'])
  .catch(err => {
    expect(err.message).to.contain('Missing required flag');
  })
  .it('runs hello --name with missing value', ctx => {});

Mocking HTTP Requests

This feature allows you to mock HTTP requests during your tests. In this example, a GET request to 'https://api.example.com/data' is mocked to return 'test data', and the test checks if the command 'fetch-data' outputs 'test data'.

const {expect, test} = require('@oclif/test');
const nock = require('nock');

test
  .nock('https://api.example.com', api => api
    .get('/data')
    .reply(200, {data: 'test data'})
  )
  .stdout()
  .command(['fetch-data'])
  .it('runs fetch-data and mocks HTTP request', ctx => {
    expect(ctx.stdout).to.contain('test data');
  });

Other packages similar to @oclif/test

Keywords

FAQs

Package last updated on 13 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc