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

@wind-js/testkit.wind.js

v1.0.0

Published

[![npm](https://img.shields.io/npm/v/@wind-js/testkit.wind.js.svg)](https://www.npmjs.com/package/@wind-js/testkit.wind.js) [![Build Status](https://travis-ci.org/wind-js/testkit.wind.js.svg?branch=master)](https://travis-ci.org/wind-js/testkit.wind.js) [

Downloads

7

Readme

logomakr_8cwvt1

npm Build Status Coverage Status PRs Welcome issues Welcome npm GitHub issues GitHub pull requests Downloads

testkit.wind.js

TestKit for writing tests for wind.js. This is not a test runner but a set of tools to interact with an actor system, you will need a runner like Jest.

Quick Start

Install the package as a development dependency:

PS> npm i @wind-js/testkit.wind.js --save-dev

Create your own test file with your framework of choice and set up the corresponding fixtures:

const TestKit = require("@wind-js/testkit.wind.js");

describe("My First Test", () => {
    let testKit = TestKit();

    beforeEach(() => {
        testKit.start();
    });

    afterEach(async () => {
        await testKit.stop();
    });

    /// your test goes here
});

By default, TestKit will create a new Actor System with the default configuration. If you want to use your own pre-configured actor system (with your own materialization or supervision) you can pass it through a parameter in the testkit function.

    let testKit = TestKit(myActorSystem);

The testkit promotes decoupling the ActorSystem from the actor itself, so instead of building actor classes, it's better to create an Actor Factory that can receive the ActorSystem. Like this:

module.exports = (Actor) => {
    return class PingActor extends Actor { 
        onReceive() { return "ping"; }
    };
};

Then you can instantiate your own actors in the TestKit:

    let PingActor = require("./ping-actor")(testKit.Actor);
    let myPingActor = new PingActor();

An example of test could be:

    test("that ping always return ping when asked", async () => {
        let myPing = new PingActor();
        let result = await testKit.sendTo(myPing, {}).transactionResult();

        expect(result).resolves.toBe("ping");
    });

Method References

TestKit.mock(onReceive = () => {})

Creates a mock actor that, when receives a message, calls the provided onReceive function. If no function is passed, it calls an empty function.

TestKit.stub()

Creates a stub of an actor that saves all received messages on a store that can be queried later with mailboxOf.

TestKit.sendTo(actor, message)

Setups a transaction with the actor and the sent message. Returns a SendToDSL instance.

SendToDSL.stateOf()

Returns the state of the actor after processing the message. Example:

 let actor = testKit.mock(function () { this.state = true });
let state = await testKit.sendTo(actor, {}).stateOf();

expect(state).toEqual({ id: actor.id, state: true });

SendToDSL.mailboxOf(stubActor)

Returns the current mailbox of an stub actor. Example:

let pongActor = testKit.stub();
let pingActor = testKit.mock(function () { this.tell(pongActor, { happy: true }) });

let [message] = await testKit.sendTo(pingActor, {}).mailboxOf(pongActor);

expect(message).toEqual({ happy: true });

SendToDSL.transactionResult()

Returns a promise with the current result of the transaction. If everything went well, the promise will be resolved with the result of the transaction, in case of failures, the promise will be rejected with the exception.

Example of Success:

let actor = testKit.mock(function () { return "happy" });
let mood = testKit.sendTo(actor, {}).transactionResult();

expect(mood).resolves.toBe("happy");

Example of Failure:

let actor = testKit.mock(function () { throw "sad" });
let mood = testKit.sendTo(actor, {}).transactionResult();

expect(mood).rejects.toBe("sad");

Contribution PRs Welcome Issues Welcome

PR and issues are always welcome as a quick way of contributing to the project. Remember to be polite, this is a open source project and ordinary requirements for PRs and issues are also a requirement.

If you want to be a long-term contributor and participate actively on the design of new features on the project, contact us! Check the package.json to see who you need to contact.

Logo

Player graphic by pixel_perfect from Flaticon is licensed under CC BY 3.0. Check out the new logo that I created on LogoMakr.com https://logomakr.com/8CWVt1