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

fluent-gwt

v2.2.0

Published

A native JS fluent Given/When/Then library for improving BDD test structure

Downloads

16

Readme

Fluent-GWT

Fluent-GWT is a native-Javascript Given/When/Then library which integrates into node test flows. The API helps codify the G/W/T or Arrange/Act/Assert workflow in your tests, making it easier to understand which part of the test is accomplishing what work.

Fluent-GWT provides extra helping information when tests fail, by logging which section of the test generated the error. This reduces time spent searching for the misbehaving code.

Why Another GWT Library?

Though Jasmine-Given, Mocha-Given, and Mocha-GWT exist, they all require, at the very least, a parser/interpreter and a new language in the toolchain. This makes them hard to integrate into current testing solutions and unfriendly if users are already feeling tooling fatigue. Fluent-GWT aims to simplify this problem and improve testing for people who aren't comfortable with the extra build tooling.

Setup

Install with npm:

npm install fluent-gwt --save-dev

Usage

Fluent-GWT can be used by requiring it into your test file (node) -- client test are currently unsupported.

Requiring in node looks like this:

const gwt = require('fluent-gwt')
    .configure({
        verbose: true // default is false
    });

Below is an example of a test using Fluent-GWT (used in Mocha):

it('tests a behavior when a user defines a simple, synchronous test', function () {
    return gwt
        .given(
            'User event is described and has an initial state',
            () => 'test string'
        )
        .when(
            'Behavior is called, capture outcome',
            (valueToUse) => valueToUse + ': success'
        )
        .then(
            'Outcome should match expectation',
            (outcomeToTest) => assert.equal(outcomeToTest, 'test string: success')
        );
});

Fluent-GWT supports Arrange/Act/Assert (otherwise known as A/A/A or triple-A) style test setup:

it('works as expected when arrange/act/assert is preferred by the user', function () {
    return gwt
        .arrange(
            'a promise-returning function is used',
            () => Promise.resolve('async string')
        )
        .act(
            'an asynchronous when is used',
            (givenResult) => Promise.resolve(givenResult)
        )
        .assert(
            'the async string should pass through',
            (actualResult) => assert.equal(actualResult, 'async string')
        )
});

Fluent-GWT also supports callback-resolving functions this way:

it('supports callback-style behaviors when a user needs to', function () {
    return gwt
        .given(
            'a promise-returning function is used',
            // gwt.fromCallback converts the callback-resolving function
            // into something Fluent-GWT can use
            gwt.fromCallback(callback => callback(null, 'callback string'))
        )
        .when(
            'an asynchronous when is used',
            (givenResult) => Promise.resolve(givenResult)
        )
        .then(
            'the async string should pass through',
            (actualResult) => assert.equal(actualResult, 'callback string')
        )
});

Fluent-GWT is promise-returning, so you can always "then" or "catch" against it:

it('provides GWT output when a test fails', function () {
    return gwt
        .given(
            'User event is described and has an initial state',
            () => 'test string'
        )
        .when(
            'Behavior is called, capture outcome',
            (valueToUse) => valueToUse + ': success'
        )
        .then(
            'Outcome should match expectation',
            () => {
                throw new Error('This test failed because reasons');
            })

        .then(function () {
            assert.isFalse(true);
        })
        .catch(function (error) {
            const failureMessage = 'Test failed:\n\n' +
                'Given: User event is described and has an initial state\n' +
                'When: Behavior is called, capture outcome\n' +
                'Then: Outcome should match expectation\n' +
                '\n' +
                'Error message: This test failed because reasons'

            assert.equal(error.message, failureMessage);
        });
});