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

journeys

v1.0.2

Published

Build, execute and test user journeys through a REST API

Downloads

3

Readme

Simple API Testing with User Journeys

The intention of this small command-line utility is to provide a means to easily run "User Journeys" over a REST API either as part of development workflow, or, by importing sub-modules, as part of a continuous deployment or integration pipeline. The input object should provide key/values corresponding to a particular user journey, where the value provides an array of actions defined in their simplest terms as follows:

{ 
    /*
        Fields marked * are optional.
        Functions are called in the scope of the "request".
        The request scope may or may not include the whole "test" scope.
    */
    
    userOne: [
        {
            description: 'Insert first test description',
            headers: {
                send: {
                    // Insert headers to send (key/value pairs)
                    // **OR** provide keys and functions that supply values
                    // Send empty object if none
                },
                receive: {
                    // Insert headers to expect in response (key/value pairs)
                    // **OR** provide keys and functions that supply values
                    // Send empty object if none
                }        
            },
            method: '[DELETE,GET,POST,PUT]',
            *send: 'INSERT JSON DATA' **OR** function() {
                return { ...MY JSON DATA... };
            },
            status: 'INSERT EXPECTED STATUS',
            url: 'INSERT ENDPOINT URL (FROM BASE (SEE BELOW))' **OR** function() {
                // Use this to add path variables or query params
                return 'ENDPOINT URL (FROM BASE (SEE BELOW))';
            },
            *validate: function(response) {
                // Insert response tests here
            },
            *then: function(response) {
                // Insert post actions here
            }
        },
        {
            description: 'Insert second test description',
            headers: {
                send: {
                    // Insert headers to send (key/value pairs)
                    // **OR** provide keys and functions that supply values
                    // Send empty object if none
                },
                receive: {
                    // Insert headers to expect in response (key/value pairs)
                    // **OR** provide keys and functions that supply values
                    // Send empty object if none
                }        
            },
            method: '[DELETE,GET,POST,PUT]',
            *send: 'INSERT JSON DATA' **OR** function() {
                return { ...MY JSON DATA... };
            },
            status: 'INSERT EXPECTED STATUS',
            url: 'INSERT ENDPOINT URL (FROM BASE (SEE BELOW))' **OR** function() {
                // Use this to add path variables or query params
                return 'ENDPOINT URL (FROM BASE (SEE BELOW))';
            },
            *validate: function(response) {
                // Insert response tests here
            },
            *then: function(response) {
                // Insert post actions here
            }
        },
        
        // ... Insert more actions ad infinitum
    ],
    userTwo: [ 
        ... 
    ],
    
    // ... Insert more users ad infinitum
}

Each action within a particular user journey will be performed in sequence, but each user journey will be executed in parallel with all other user journeys. With enough tests and/or by adding your own means to auto-generate test data, this pattern could potentially be used for (but is not limited to) stress-testing of APIs and/or the testing of contracts between microservices.

It is expected that user journeys would be stored within their own file and imported/required. Furthermore, since the testing "functions" could also be required in the same manner and are likely to take a finite number of forms, it would be possible for the tests themselves to be maintained by a team with more automated testing experience, while the declarative JSON syntax required for the creation of User Journeys could be undertaken by those with more knowledge of customer requirements and usage patterns.

The utility provides console output in the following (success) form:

User Journey of UserOne:
    ✓ UserOne performs ActionA
    ✓ UserOne performs ActionB
    ✓ UserOne performs ActionC
    
User Journey of UserTwo:
    ✓ UserTwo performs ActionA
    ✓ UserTwo performs ActionB
    ✓ UserTwo performs ActionC
    

And in the following (fail) form:

User Journey of UserOne:
    ✓ UserOne performs Action A
    ✗ UserTwo performs Action B 

Error is:
    expect(received).toBeFalsy()

Received: "5eb7a7c49443093064a8c50e"
Error: expect(received).toBeFalsy()

Received: "5eb7a7c49443093064a8c50e"
    at Object.test ({ Stack follows ... }) 

Once installed globally (see below), you can run the utility using:

journeys /path/to/user/journeys --url base_url_of_api_under_test

Two examples are provided at: /examples/computed.js and /examples/simple.js. In the same folder, a very basic Express server that reflects its input is provided for demonstration. Once you have installed Express (npm install express), uuid (npm install uuid) and jest (npm install jest), run node server.js from the /examples folder to start the server prior to running the examples.

Whilst the command line utility provides clear human-readable information as to the results of your tests, it is also possible to import sub-modules (most likely the file at src/journeys) and bind your results into a promise chain for the purposes of Continuous Integration or Continuous Deployment pipelines. This also allows for convenient control over pre- and post-test setup/teardown.

Installation

(1) Install globally for use on the command line with:

npm install -g journeys

(2) Install on a project basis for use of sub-modules in a CI/CD pipeline by omitting the global declaration:

npm install journeys