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

@irontitan/sloth

v0.1.2

Published

A simple but useful set of tools to aid NodeJS developers on writing tests.

Downloads

41

Readme

Sloth

A simple but useful set of tools to aid NodeJS developers on writing tests.

This is a WIP. Functionallity is stable, but documentation is not so good yet.

Usage

Database

The database module can be used to mock a mongodb database using mongodb-memory-server. It works by receiving a set of states, which you can later activate easily by name.

Example

Define one or more states following the StateMap interface.

This can be done inline, instead of separate file. Keep things apart is, usually, more organized, tho

import { Content } from '@irontitan/sloth'

export interface States {
  userAlreadyExists: Content[],
  resultsArePaginated: Content[]
}

const states: States = {
  userAlreadyExists: [
    {
      collection: 'users',
      data: {
        _id: '5d9c216721d400b621d9f8c4',
        login: 'lalala',
        password: '',
        status: 'valid'
      }
    }
  ],
  resultsArePaginated: [
    {
      collection: 'users',
      data: [
        {
          _id: '5d9c216721d400b621d9f8c4',
          login: 'lalala',
          password: '',
          status: 'invalid'
        },
        {
          _id: '5d9c216721d400b621d9f8c4',
          login: 'lalala',
          password: '',
          status: 'invalid'
        }
      ]
    }
  ]
}

export default states

On your test file, you can call the init function passing said states, in order to receive an object implementing the SlothDatabase interface.

After that, whenever you need to change the state of your database, you can call the setState function, which receives the name of the desired state, and sets it for you.

import sloth from '@irontitan/sloth'
import states, { States } from './states'
import { SlothDatabase } from './src/database'

describe('POST /', () => {
  let database: SlothDatabase<States>
  let app: AxiosInstance

  before(async () => {
    database = await sloth.database.init(states)
    axiosist(app.factory({ ...config, mongodb: database.config }))
  })

  afterEach(async () => {
    await database.clear()
  })

  describe('Some test', () => {
    before(async () => {
      await database.setState('userAlreadyExists')
    })
  })
})

API

All the API is documented through TSDoc on the code. An HTML version is comming soon.

Contributing

See CONTRIBUTING.md