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

qfx-busted-tstl

v0.1.3

Published

TypeScript definitions for the Busted testing suite

Downloads

7

Readme

TypeScript declarations for Busted

This repository contains TypeScript declarations for Busted. An Elegant Lua unit testing framework.

You can install these via npm.

yarn add -D busted-tstl
# or
npm install -D busted-tstl

link them up in your tsconfig.json file.

It is recommended to use lua-types with these declarations as those will tell TypeScript about Lua's environment.

{
    "compilerOptions": {
        "lib": ["esnext"],
        "types": [
            "busted-tstl",
            "lua-types/5.1
        ]
    }
}

start creating your busted tests within .ts files (preferably with the suffix _spec.ts within a folder named spec).

describe("mocks", () => {
    it("replaces a table with spies", () => {
        const t = {
            thing: function (this: void, msg) { print(msg) }
        };

        const m = mock(t); // mocks the table with spies, so it will print

        m.thing("Coffee");
        assert.spy(m.thing).was.called_with("Coffee");
    });

    it("replaces a table with stubs", () => {
        const t = {
            thing: function (this: void, msg) { print(msg) }
        };

        const m = mock(t, true); // mocks the table with stubs, so it will not print

        m.thing("Coffee");
        assert.stub(m.thing).was.called_with("Coffee");
        mock.revert(m); // reverts all stubs/spies in m
        m.thing("Tea"); // DOES print 'Tea'
    });
});

Then transpile the file(s) with TypeScriptToLua and run busted!

tstl spec/test_spec.ts
tstl -p tsconfig.json
busted      # Install with `luarocks install busted`

It is recommended to use lua-types with these declarations as those will tell TypeScript about Lua's environment.

Assertion Statement Info

Assertion statements can be built with underscores and/or dots.

assert.is.True(true);           // Equivalent
assert.is_true(true);           // Equivalent

assert.is.not.True(false);      // Equivalent
assert.is_not_true(false);      // Equivalent

Verbs can be chained. However if there is a not or no within the chain, the assertion is expected to be fail. This cannot be reverted with another not or no.

assert.is.is.is.not.is.not.False(true);   // Assertion failed.
                                          // This was expected because of `not`

Async Tests

To use async() and done() make sure your test case is wrapped in a pending(...) call.

async(); // error, trying to call nil value
done(); // error, trying to call nil value

pending("waiting for sleep to complete", () => {
  async();
  sleep(5000);
  done();
});