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

@pubnub/tomato

v1.13.0

Published

CLI mock server for contract testing

Downloads

102

Readme

@pubnub/tomato npm

CLI mock server tool for contract testing

Installation

npm install @pubnub/tomato

Usage

npx tomato

Configuration

Tomato will look for a toma.toml configuration file in the current working directory.

|Option|Default|Type|Description| |-|-|-|-| |port|8090|number|Port to start the server at| |contracts|./contracts/**/*.ts|Glob \| Glob[]|Location of the contract files| |openapi|./openapi/**/*.yaml|Glob \| Glob[]|Location of the OpenAPI specs| |env|none|Record<string, string>|Additional environment variables exposed as process.env|

Contract files

Contract is a TypeScript file that:

  • exports its name:

    export const name = "MyContractName"
  • exports a default consumer function:

    export default async function() {}
  • optionally exports a provider function:

    export async function provider() {}

Contract context

Contracts are run inside an isolated Node.js environment and have access to some additional helpers.

timetoken.now()

Generates a string timetoken with nanosecond resolution.

json(path: string)

Read and parse a JSON file.

expect({ description: string, validations?: Array<(request: Request) => void>}, number?): Promise<Request>

Asynchronous function that waits for the next request (waits for 30000 milliseconds by default, which can be changed with the last argument) and validates it against an array of assert functions before returning an instance of Request.

expectAll({ description: string, match: (request: Request) => bool, validations?: Array<(request: Request) => void>}[], number?): Promise<Request[]>

Asynchronous function that waits for a list of next requests (waits for 30000 milliseconds by default, which can be changed with the last argument) and validates it against an array of assert functions before returning an array of Request instances.

This function is useful when a few endpoints can be called simultaneously, and it is unknown which will be accepted first by the mock server. match function will be used to match the validation configuration to the proper request. The returned list of Request instances will be ordered in the same order as the passed parameters.

Request.respond({ status: number, headers?: Record<string, string>, body?: any }): Promise<void>

Asynchronous function that responds to a request.

assert

assert groups assertion functions.

Examples:
// expected last segment of path to equal "hello"
assert.request.path.lastSegment.equals('"hello"')

// expected path to match /^\/hello/i
assert.request.path.matches('^/hello', 'i')

// expected path to start with '/v2/request/hello'
assert.request.path.startsWith('/v2/request/hello') 

// expected method to be one of ["GET", "POST"]
assert.request.method.isOneOf(['GET', 'POST'])

// expected method to equal "POST"
assert.request.method.equals('POST')

// expected query["lmao"] to equal "123"
assert.request.query.lmao.equals('123')

// expected query["tt"] to be greater than 10
assert.request.query.tt.asNumber.gt(10)