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

ripjam

v0.0.11

Published

tools for breaking and re-assembling things

Downloads

32

Readme

ripjam

Tools for breaking things down and building them back up

Testing

Use ripjam/test if you want to make re-usable testing (with curried parameters) easier.

By default it is designed to work out of the box with jest but it's very easy to use with other testing frameworks.

// test.spec.js
import { curry } from 'ramda'
import { hook } from 'ripjam/test'

const { riptest, same, shared } = hook()

function basic(x) {
  return x * 2
}

const testBasic = riptest(basic)

testBasic('basic test', 1, 2)
testBasic('basic test with array params', [1], 2)

const mult = curry(function _multiply(a, b) {
  return a * b
})

same([mult(2), basic], 'double', 100, 200)

const oldImplementation = { basic, a: z => 'dope: ' + z }
const newImplementation = {
  basic: mult(2),
  complex: mult(-2),
  a: x => ['dope:', x].join(' ')
}

const answers = {
  basic: [100, 200],
  a: ['yo', 'dope: yo']
}

shared(
  [oldImplementation, newImplementation],
  'test all the shared functionality',
  answers
)

After running jest on the above, it will print:

PASS test.spec.js
  ✓ "basic test": 𝞴 "basic" (unary) (2 ms)
  ✓ "basic test with array params": 𝞴 "basic" (unary)
  ✓ "double": 𝞴 unnamed (unary)
  ✓ "double": 𝞴 "basic" (unary)
  ✓ same implementation of "double": (𝞴 unnamed (unary)) and (𝞴 "basic" (unary)) (1 ms)
  ✓ "basic: test all the shared functionality": 𝞴 "basic" (unary)
  ✓ "basic: test all the shared functionality": 𝞴 unnamed (unary)
  ✓ same implementation of "basic: test all the shared functionality": (𝞴 "basic" (unary)) and (𝞴 unnamed (unary))
  ✓ "a: test all the shared functionality": 𝞴 "a" (unary) (1 ms)
  ✓ "a: test all the shared functionality": 𝞴 "a" (unary)
  ✓ same implementation of "a: test all the shared functionality": (𝞴 "a" (unary)) and (𝞴 "a" (unary))

Exclusive / specific interface testing

If the shared is given two implementations like the above and the answers object is missing an expected value, this will throw an error, unless you add a specific only or skip array to your answers object, e.g.

const answers = {
  basic: [100, 200],
  a: ['yo', 'dope: yo']
  only: ['a'], // test only the 'a' interface on both objects
  skip: ['basic'] // do not test the 'basic' interface on both objects (not needed here as `only` above does the same)
}

shared(
  [oldImplementation, newImplementation],
  'test all the shared functionality',
  answers
)

Custom testing hook

If you would like to use a different testing framework, you can manually assemble the same behavior like so:

// custom-ripjam.js
import { riptestWithConfiguration, sameImplementation, sameInterface } from 'ripjam/test'

// you supply these
const binaryTestingFunction = (str, run) => test(str, run)
const binaryAssertionFunction = (input, output) => expect(input).toEqual(output)

const customhook = () => {
  const riptest = riptestWithConfiguration(binaryTestingFunction, binaryAssertionFunction)
  const config = {riptest, check: binaryTestingFunction, claim: binaryAssertionFunction}
  const same = sameImplementation(config)
  const shared = sameInterface(config)
  return { riptest, same, shared }
}

export const hook = customhook

Now you can use the above file instead of ripjam/test and it should be identical.