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

yatlib

v0.0.2

Published

**Stands for Yet Another Test Lib**

Downloads

7

Readme

YATLIB

Stands for Yet Another Test Lib

Why ?

Glad you asked !

Because I believe, deep down in my heart, that Jest terribly sucks and is directly responsible for the loss of years of my life that I will never get back.

Made for programmers who meet one or more of these criterias

  • Likes Typescript
  • Likes For loops and Functions (**WOW**)
  • Likes logging text messages in the terminal using good old fashion console.logs
  • Doesn't like when a program swallows logs sent to the terminal
  • Doesn't like when a library needs 100000 other libs to run
  • Doesn't like when a library needs to "transform" with babel to even run your code
  • Prefers coding than browsing Stack Overflow
  • Doesn't mind importing the dependencies it uses

Basically, YATLIB does less than Jest.

Installation

Install YATLIB like you would typically do for any node package:

npm i --save-dev yatlib
#or
yarn add --dev yatlib

Usage

To use YATLIB, all you need to do is import it like this:

// some-test.test.ts
import yatlib from 'yatlib'
import validatePath from './somebadlookingpieceofcode.ts'

const main = async () => {
  await yatlib.test({
    name: '69 is not 42',
    handler: async () => {
      yatlib.expect(69).not.toBe(42)
    }
  })

  const validPaths: string[] = ['/', '/somedir', '/somedir/somefile.txt']

  for (const p of validPaths) {
    await yatlib.test({
      name: `path ${p} is valid`,
      handler: async () => {
        yatlib.expect(validatePath(p)).toBeTrue()
      }
    })
  }

  if (!yn(process.env.YATLIB)) {
    // process.env.YATLIB is defined when using YATLIB's CLI
    const { tests } = yatlib
    const testCount = tests.length
    const successCount = tests.filter((t) => t.success).length
    console.log(`Total: ${successCount}/${testCount}`)

    const failingTestCount = testCount - successCount
    if (failingTestCount > 0) {
      process.exit(1)
    }

    process.exit(0)
  }
}

main()

To run your test, you have 2 choices.

  1. You can simply run your test like you would for any other typescript/javascript file. You can use ts-node or build your test using tsc and run the resulting *.js file with node.

  2. You can use YATLIB's CLI. More on this in the next section.

CLI

YATLIB comes with a CLI that allows you to run all tests located in a target directory. To use it run:

npx yatlib --path /your/tests/directory
# or
yarn yatlib --path /your/tests/directory

When a test file is ran by the YATLIB's CLI, the environment variable YATLIB is set to 1.

How it works

YATLIB is slightly different than Jest. These differences may not seem like much but they give IMO a better product.

Instead of parsing all test files to first locate test and then run them, YATLIB runs a test when it sees one. This make the use of weird complicated test hooks like beforeAll() and afterEach() obsolete.

This is quite handy if you want to run the exact same test suite using multiple different infrastructure using a for loop.

Also, the only reason why a test would fail is if an exeption occurs inside its handler. All the expect functions do is to throw if a condition is not met. Therefore, to make your own custom expecters, all you have to do is to create a function that throws or not. Tests will pass or fail accordingly.

Documentation

There is currently no documentation, but the package is fully typed. To learn more about a function or feature, just press on ctrl+space in your favorite IDE and the intellisense will give you a hand.

Disclaimer ⚠️

YATLIB is still very early in its development and is subject to massive breaking changes.