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

tunit

v1.0.7

Published

The node.js coding test plugin,it is similar to junit

Downloads

6

Readme

Welcome to TUnit!

This a unit test plugin on the node.js, if you used junit before, you'll learn it soon.. TUnit is used in typescript projects so that coding with annotation.


Table of contents


Install

npm install tunit --save-dev

Example

The following code uses typescript
  • First of all, you'd better create a entity class TUnitTest.ts

    The file name can't named "Test".

    It is recommended to use try commands pack exec statment to catch error so that to prevent execution interruption.

import { BeforeClass,Before,Test,After,AfterClass,TUnit,Assert } from 'tunit';

@TUnit() 
export default class TUnitTest {
	@BeforeClass
	init(next:Function):void {
		setTimeout(():void=>{
			try {
				console.log('This is BeforeClass Method');
				next();
			}
			catch(err) {
				next(err);
			}
		}, 2000);	
	}
	@Before
	beforeTesting(next:Function) {
		console.log('This is Before Method');
		try {
			const assert = Assert.assertNotNull(null, 'This is a null result');
			next(null, assert);
		}
		catch(err) {
			next(err);
		}
	}
	@After
	afterTesting(next:Function) {
		console.log('This is After Method');
		try {
			throw new Error('This is a error mssages')
			next();
		}
		catch(err) {
			next(err);
		}
	}
	@Test
	testing(next:Function) {
		console.log('This is Test Method');
		setTimeout(function() {
			console.log('Test Method is executing after 1 sec');
			next('testing');
		}, 1000);
	}
	@AfterClass
	end(next:Function) {
		console.log('This is AfterClass Method');
		next()
	}
}
  • The whole process of the test is a generator function, so the method next is important in asynchronous threads, which is the key to whether the whole test can run smoothly. This function takes two arguments, the result of the run and the return value after the assertion
next(result?:any, assert?:any):void
  • Finally, to run this file.
ts-node ./TUnitTest.ts

Annotations

| Annotation | Description | | ------------- |:-------------| |@BeforeClass|It to be run once before any of the test methods in the class.| |@Before|Annotating a public void method with @Before causes that method to be run before the Test method.| |@Test|Annotating a public void method with @Test causes that method to be run the Test method.| |@After|Annotating a public void method with @After causes that method to be run after the Test method.| |@AfterClass|It to be run once after any of the test methods in the class.| |@TUnit(params)|It is important. This annotation tell tunit plugin to run the Test class. It has a parameter that log file path if you want to get operational processes. The log file include running result, test status, error message and so on.|

Assertion Methods

  • All methods are static. If testing is successful, return true otherwise throw AssertionError.

| Methods | Description | | ------------- |:-------------| |fail(msg?: string):void|Throw an AssertionError.| |assertNull(obj: any, msg?: string):boolean|Assert the argument is null.| |assertNotNull(obj: any, msg?: string):boolean|Assert the argument is not null.| |assertUndefined(obj: any, msg?: string):boolean|Assert the argument is undefied.| |assertNotUndefined(obj: any, msg?: string):boolean|Assert the argument is not undefied.| |assertNullOrUndefined(obj: any, msg?: string):boolean|Assert the argument is null or undefied.| |assertNotNullAndUndefined(obj: any, msg?: string): boolean|Assert the argument neither null nor undefied.| |assertSame(expected: any, actual: any, msg?: string): boolean|That's equal to '=='| |assertNotSame(expected: any, actual: any, msg?: string): boolean|That's equal to '!='| |assertEquals(expected: any, actual: any, msg?: string): boolean|That's equal to '==='| |assertNotEquals(expected: any, actual: any, msg?: string): boolean|That's equal to '!=='| |assertTrue(condition: boolean, msg?: string): boolean|Assert the argument is true| |assertFalse(condition: boolean, msg?: string): boolean|Assert the argument is false|

More specifications, in the building...

NPM