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

@elasticpath/component-test-framework

v1.2.33

Published

A framework for component tests written using ts-flow

Downloads

702

Readme

Elasticpath Component Test Framework

Installation

With Yarn

yarn add --dev @elasticpath/component-test-framework

With NPM

npm install --save-dev @elasticpath/component-test-framework

Usage

The framework exposes a few classes:

Api

This is the class responsible for communicating with your API. You can use the methods directly, however, it's usually a better idea to have it as a binding.

Example

import { binding, then } from 'cucumber-tsflow'
import { Api } from 'component-test-framework'

@binding([ Api ])
export default class MyStepDefinitions {
    constructor(protected api: Api) {
    
    }
    
    @then(...)
    public async myStep(): void {
      await this.api.get('/products')
    }
    
    ...

Payloads

Because everything that comes from the Gherkin language is a string, it's impossible to specify literals such as null. The framework has a Payload class to handle such cases. Whenever you want to send a payload to the API, you can use

const payload = new Payload(table.hashes()[0])

Type conversions

The framework is clever when it comes to type conversions. Consider the following Gherkin table

| null | 123 | foo | "" | [{"foo": "bar"}] |

When sent to the framework, they are all strings

[ "null", "123", "foo", "\"\"", "[{\"foo\": \"bar\"}]"]

The new Payload method does some conversion for us. Here's a mapping of the conversion:

{
    "null": null,
    "123": "123",
    "foo": "foo",
    "\"\"": "",
    "[{"foo": "bar"}]": [{"foo": "bar"}],
}

You may have noticed the number remains a string. The framework could convert that, however there are certain cases where you need to keep it as a string (a product upc_ean can be specified like a number but is a string). Therefore, the framework introduces a special symbol to force an integer. Given the following gherkin table, the framework will parse the first value as an integer and leave the second as a string

| <i>123 | 456 |

ResourceStore

When working with the API in your component tests, it's often benificial to reference the last created resource

Example

Given An admin creates a product
When They get the created product

For this, we can use the ResourceStore. When ever you use the API module, it stores the resource that was created, or fetched in the resource store. Knowing that, we can create our step definition to easily fetch the last created resource

Example

import { ResourceStore } from 'component-test-framework'
...
const resource: Resource =  ResourceStore.LastCreated('file')

We can also get all of the resources under one type

Example

import { ResourceStore } from 'component-test-framework'
...
const resource =  ResourceStore.FetchByType('file')

And find a resource

Example

import { ResourceStore } from 'component-test-framework'
...
const resource =  ResourceStore.Find('file', 'id', 'abc-123')

Each method on the ResourceStore returns a Resource

Resource

This is a representation of a resource.

const resource = new Resource(data)

These are usually only created by the ResourceStore. However, there are a few public methods

asPayload()

Useful if you want to build an update payload for your PUT request. If no argument is supplied, then the resource is returned as a payload, which removes attributes not allowed in payloads (relationships) and nullifies values which are string "null"

If an argument is supplied, this function will merge the data from that with the current data

Example

const resource = ResourceStore.LastCreated('hierarchy')
const payload = resource.asPayload(table.hashes()[0])

Publishing

Publishing is handled via the GitLab pipeline. On an MR branch, the pipeline checks to see if the version in package.json is already a published version, and fails if so, letting you know that the version needs to be updated.

Actual publishing happens on a merge to main.

In the event that a rollback is needed, the rollback MR will fail because the version in package.json will exist on NPM. To resolve this, you will need to bump the version in package.json.