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

@valtech-commerce/jest-gwt

v1.0.0

Published

Given-When-Then helper for Jest

Downloads

2

Readme

@valtech-commerce/jest-gwt

npm npms.io: Score libraries.io: SourceRank Tests License: MIT

Given-When-Then helper for Jest.

Install

$ npm install @valtech-commerce/jest-gwt

Usage

Import the package in your Jest test files and extends the base GWT.

//--------------------------------------------------------
//  xyz.gwt.js
//--------------------------------------------------------
import path from "node:path";
import { given as givenBase, when as whenBase, then as thenBase } from "@valtech-commerce/jest-gwt";

const given = { ...givenBase };
const when = { ...whenBase };
const then = { ...thenBase };

let rootPath;

given.noRootPath = () => {
	rootPath = undefined;
};

given.rootPath = (value) => {
	rootPath = value;
};

when.packageIsLoaded = () => {
	when.attempting(() => {
		require(path.join(rootPath, "package.json"));
	});
};

export { given, when, then };

//--------------------------------------------------------
//  xyz.test.js
//--------------------------------------------------------
import { given, when, then } from "./xyz.gwt";

describe("Validate package.json", () => {
	beforeEach(() => {
		given.noException();
		given.noRootPath();
	});

	test("Ensure package can be loaded", () => {
		given.rootPath("..");
		when.packageIsLoaded();
		then.shouldNotHaveThrown();
	});
});

Helpers

The package comes with multiple helpers. If you want them all, import the root package @valtech-commerce/jest-gwt.

Exception @valtech-commerce/jest-gwt/exception

Check for thrown exceptions

given.noException()

Reset exception listener

when.attempting(closure: Function)

Listen for error when executing closure

when.attemptingAsync(closure: Function)

Listen for error when executing asynchronous closure

then.shouldHaveThrown()

Exception has been thrown

then.shouldHaveThrownMessageContaining(message: string)

Exception, with message excerpt, has been thrown

then.shouldNotHaveThrown(closure: Function)

No exception has been thrown

Package @valtech-commerce/jest-gwt/package

Tests for package.json

given.noPackageRoot()

Reset root path

given.noPackageConfig()

Reset parsed config

given.noPackageNamePattern()

Reset name pattern

given.noPackageKeywords()

Reset keywords

given.packageRoot(value: string)

Specify the root path of the package.json

given.packageNamePattern(value: RegExp)

Specify a pattern for the package name

given.packageKeywords(value: string[])

Specify mandatory keywords

when.packageIsParsed()

Parse the package.json file

then.packageNameShouldBeValid()

Package name matches the defined name pattern

then.packageKeywordsShouldBeValid()

Package keywords contain at least the defined keywords

then.packageExportsShouldExist()

Package exports point to existing files

Documentation

See the Changelog to see what has changed.

Contribute

See the Contributing Guidelines for ways to get started.

See the Support Guide for ways to get help.

See the Security Policy for sharing vulnerability reports.

This project has a Code of Conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Valtech Canada inc.