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

tsst-tycho

v0.4.0

Published

Helper utility for transforming typescript tests to allow testing for semantics rather than functionality.

Downloads

7

Readme

Installation

# global
npm install -g tsst
# local
npm install tsst --save-dev

What is it?

Uhh. This is an experimental library/tool/utility/thing to aid testing of TypeScript semantics.

What does it do?

At its core, this is a TypeScript transformer that takes semantic build errors and turns them into runtime errors. Here's the show-don't-tell explanation.

Your tests

type ZeroOneToBoolean<T extends "0" | "1">
    = {"0": false, "1": true}[T];

describe("ZeroOneToBoolean", () => {
    it("works with '0'", () => {
        type A = ZeroOneToBoolean<"0">;
    });

    it("works with '1'", () => {
        type A = ZeroOneToBoolean<"1">;
    });

    // This test should fail for demonstration purposes
    it("works with the number 0", () => {
        type A = ZeroOneToBoolean<0>;
    });
});

What your tests become

describe("ZeroOneToBoolean", () => {
    it("works with 0", () => {
    });

    it("works with 1", () => {
    });

    // This test should fail for demonstration purposes
    it("works with the number 0", () => {
        throw new Error("​​Type '0' does not satisfy the constraint '\"0\" | \"1\"'.​​");
    });
});

In this early form, this only tests for successful compilation.

What might it do soon?

  • [ ] Negative tests that let you expect specific errors
  • [x] Have some form of cli that makes it more usable
  • [ ] Have its own tests. This project is currently horrendously untested because I'm not sure what the best way to test this is.
  • [ ] Have a better name?
  • [ ] Change completely in any number of ways
  • [ ] Stop parsing full tests and become a block-local transformation

How does one use this?

If you install this package globally, you can use tsst to transform the tests. This is a very basic builder. It uses the local tsconfig.json and takes a single argument for a test glob.

# global install
tsst "**/*.test.ts"
# local install
node_modules/.bin/tsst "**/*.test.ts"

The TypeScript compiler provides hooks for specifying custom transformers, but tsc does not expose these. While many common tools like ts-loader are starting to support transformers, most don't yet provide transformers with access to the ts.Program object that this requires.

I've been messing about with Wallaby.js a bit recently, and tried to get it working with that, to partial success. They were absolutely fantastic about adding support for transformers for me with a feature-request-to-release turn-around time of about 2 hours. Wallaby.js runs and reports the transformed tests correctly, but there are some problems with line numbers and error positions not lining up. I haven't fully pinned these down yet, and am not sure to what degree these issues are solvable by this tool.