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

ts-tester

v0.0.1

Published

testing library

Downloads

9

Readme

This is a testing library.

Running the tester

to install:

npm install ts-tester

sample test file:

let tester = require('ts-tester')
let filter = <string>, fixing = <boolean>
let testing = tester(filter, fixing)
let input = <array>, output = <array>, test = <function> 
testing.run({
  input,
  output,
  test
})

OR more commonly (since filter and fixing are usually provided via command line if at all):

let testing = require('ts-tester')()
testing.run({
  input: [...],
  output: [...],
  test: (param1, param2, ...) => {
    //do something
    ...
  }
})

Put either one of the above into a file that can be named whatever you want although be sure to add code where there is <> or ... . Then you can run the file by calling node directly on the file i.e. node tests.js or FILTER=... tests.js or FIXING=1 FILTER=... tests.js.

what it do:

In the above example, the input array represents a series of inputs that individually will be provided as an array of arguments to the test function also provided. These will then be checked against the output provided to see if they are same. If not then an error will be shown in the console. For example,

testing.run({
  group1: {
    input: ['1', '2', '3'],
    output: [1, 2, 3],
    test: parseInt
  }
})

is a valid test that will pass. However,

testing.run({
  group1: {
    input: ['1', '2', '3'],
    output: ['blah', 'red', 'blue'],
    test: parseInt
  }
})

will not. Elsewhere in the documentation the object that is set to group1 is called the test object.

Tests can also be nested and child test groups will inherit the defined keywords in the parent tests. For example,

testing.run({
  group1: {
    input: ['1', '2', '3'],
    test: parseInt,
    good: {
      output: [1, 2, 3],
    },
    bad: {
      output: ['blah', 'red', 'blue'],
    }
  }
})

"group1.good" will pass and "group1.bad" will not.

Above filters and fixing are two parameters to and indiviual set of tests contained within a file. Both of these parameters can also be passed as environment variables and will be used only if the corresponding parameter is falsy. The environment variables are named 'FILTER' and 'FIXING'.

filter is a string declaring what tests to run. Examples are: 'group1' to run a test group called "group1"; 'group1.subgroup1' to run a subgroup of a test group called "subgroup1", 'group1#3' to run the third test in a group called "group1", 'group2#-1' to run the last test in a test group called "group2", 'group1,group2' to run test groups "group1" and "group2", and 'group2#3-5' to run the third through fifth tests of test group "group2".

fixing if truthy attempts to automatically write the output of running a test with the given inputs into the test file. Make sure you backup your code before running this. Only the run file is affected. If you did node * in your tests directory, then do to shell expansion it would attempt to rewrite all test output.

For this to work correctly, you need to indent the line one indentation below the line where the test object is defined. For example,

testing.run({
  group1: {
    input: ['1', '2', '3'],
    output: [],
    test: parseInt
  }
})

works but the following is bad:

testing.run({
  group1: {
  input: ['1', '2', '3'],
  output: [],
  test: parseInt
  }
})

NOTE THAT YOU SHOULDNT MIX TAB AND SPACES WHEN USING THIS!