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

@xxxxst/tsunit

v0.0.1

Published

typescript util test

Downloads

7

Readme

tsunit

a typescript unit test like csharp

https://github.com/xxxxst/tsunit

English 简体中文

speciality

  • pretty API
  • run in chrome
  • easy to locate the error
  • support async test
npm install @xxxxst/tsunit
  • enable decortor
  • enable source map

see more at the example

https://github.com/xxxxst/example-tsunit

test file - ComTest.ts

@TestClass()
export default class ComTest {
    @Test()
    matchTest() {
        Assert.equal(1, 1);
        Assert.notEqual("aa", "bb");
    }

    @Ignore()
    @Test()
    ignoreTest() {
        Assert.equal(1, 2, "info");
    }

    @Test(1, 2)
    @Test("a", "b")
    noMatchTest(except, actual) {
        Assert.equal(except, actual, "info");
    }

    @AsyncTest()
    async asyncTest() {
        var rst = await this.getHttp();
        Assert.equal("data", rst);
    }

    async getHttp() {
        return new Promise(resolve => setTimeout(()=>{
            resolve("data");
        }, 0));
    }
}

test file - ComTest2.ts

@TestClass({autoRun:false})
export default class ComTest2 {
    constructor(arg1, arg2) {

    }
}

entry point file

// dont't need to create the test class
import './ComTest';

// second way to import
// make sure the class is used
import ComTest from './ComTest';
ComTest

// run test by yourself
import ComTest2 from './ComTest2';
// ... your init code
setTimeout(()=>{
    // run test
    Assert.run(ComTest2, "arg1", "arg2");
}, 0);

open console to view test info

decorators

@TestClass(option?:{autoRun?:boolean}, ...args)

  • class decorator
  • mark test class
  • autoRun auto run test, default is true
  • args test class constructor arguments

@Test(...args)

  • function decorator
  • mark test function
  • args arguments

@AsyncTest(...args)

  • function decorator
  • mark asynchronous test function
  • need to use async/await
  • args arguments

@Ignore()

  • function decorator
  • ignore (async) test function

Assert

Assert.run(class, ...args)

  • run class by yourself
  • need tu use autoRun:false in @TestClass()
  • class test class
  •  args test class constructor arguments

Assert.setLang(obj)

  • set language, default is english
  • obj language key/map, see more at source code
    • build-in language:
    • Assert.lang_en_us english
    • Assert.lang_zh_cn chinese

Assert.equal(expected:any, actual:any, desc: string = "")

  • assert if is equal, compare each param if is object
  • expected expected value
  • actual actual value
  • desc describe info

orther assert

-|- :-|:- Assert.equal | (expected:any, actual:any, desc: string = "") Assert.notEqual | (expected:any, actual:any, desc: string = "") Assert.strongEqual | (expected:any, actual:any, desc: string = "") Assert.strongNotEqual | (expected:any, actual:any, desc: string = "") Assert.same | (expected:any, actual:any, desc: string = "") Assert.notSame | (expected:any, actual:any, desc: string = "") Assert.isTrue | (actual:any, desc: string = "") Assert.isFalse | (actual:any, desc: string = "") Assert.isEmpty | (actual:any, desc: string = "") Assert.isNotEmpty | (actual:any, desc: string = "") Assert.isNull | (actual:any, desc: string = "") Assert.isNotNull | (actual:any, desc: string = "") Assert.isUndefined | (actual:any, desc: string = "") Assert.isNotUndefined | (actual:any, desc: string = "") Assert.isBool | (actual:any, desc: string = "") Assert.isArray | (actual:any, desc: string = "") Assert.isObject | (actual:any, desc: string = "") Assert.isString | (actual:any, desc: string = "") Assert.isNumber | (actual:any, desc: string = "") Assert.success | (desc: string = "") Assert.fail | (desc: string = "")

assert usage

base on webpack + typescript + vue(ui test)

https://github.com/xxxxst/example-tsunit