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

@mojotech/prismatest

v0.3.2

Published

Use test views to decouple tests from implementation details

Downloads

24

Readme

Prismatest Core

This module provides the core functionality used for constructing and combining test views. It is not intended to be used directly in a test, but rather it is intended to be used for implementing adapters which are then imported and used in your tests.

Implementing Adapters

Implementing adapters requires specifying two types and three functions. Adapters specify the type of elements they interact with and the type of selectors they run. They also specify how selectors are composed, how selectors are executed, and how selector results are iterated. Selectors cannot be functions, but they can be classes.

Composing Selectors

This function as implemented by the adapter must be associative. In its first argument it takes the first selector to run. In its second argument it takes the second selector to run. Calling this function should return a new selector that effectively runs the first selector, followed by the second selector.

composeSelectors: (first: SelectorType, second: SelectorType) => SelectorType

Executing Selector

This function takes in its first argument the selector to run. It takes in its second argument the element against which the selector should be run. The function should run the selector and return the results. The result type is an implementation detail of the adapter and is not exposed to the end user.

executeSelector: (selector: SelectorType, element: ElementType) => ElementResultsType

Iterate Selector Results

This function takes in its first argument the results from running a selector. It takes in its second argument a function that takes a single element from the results and returns a value. This function should run its input function on every result from the selector and collect the return values in an array. The function should return this array.

iterateSelectorResults: (results: ElementResultsType, fn: (element: ElementType) => Value) => Value[]

Default Views

The adapter should specify test views consistent with the default views required of all adapters. See the main project API document for more information about these.

Construction Function

The core module exports a single construction function named makeAdapter that should be used to construct the adapter. The types for the arguments to makeAdapter are also exported as ComposeSelectors, RunSelector, IterateSelector, and DefaultViews.

CSS Adapter

The test view examples used a CSS adapter. The CSS adapter might have been implemented like this (excluding the default views for brevity):

const composeSelectors = (first, second) => first + " " + second;

const runSelector = (selector, element) => element.querySelectorAll(selector);

const iterateSelector = (nodes, fn) => {
  const result = [];
  for(let i=0 ; i < nodes.length; i++) {
    const node = nodes.item(i);

    result.push(fn(node));
  }
  return result;
};

export default makeAdapter(
  composeSelectors,
  runSelector,
  iterateSelector
);

Those wishing to see an implementation of the default views can look at existing adapters.

Testing Adapters

The Prismatest Adapter Tests module provides a test suite that should be used for testing adapters. All adapters should pas the test suite to be considered fully-functional.

Typescript

Prismatest is written in Typescript. Adapters should also be written in Typescript to ensure the best possible compatibility with all functionality.