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

astr

v1.2.4

Published

Run TypeScript/JavaScript tests in NodeJS or Chromium

Downloads

27

Readme

Astr, a flexible test runner for TypeScript and JavaScript projects

Features include

  • Supports async test methods or tests that return Promises
  • Can run tests under NodeJS or Chromium, using Puppeteer

Basic usage

To get started:

npm install --save astr

Then use the run-scripts.js script to run your tests:

node node_modules/astr/bin/run-tests.js --testdir tests/

The above command will run tests found in all .js files in the tests/ directory.

Author your tests like this:

import { registerTest, registerModule } from "astr";

registerModule("Basic tests");

registerTest({
	name: "One equals one",
	func: async (assert) =>
	{
		assert.equals(1, 1);
	}
});

To run tests in Chromium instead, use the --runtime argument:

node node_modules/astr/bin/run-tests.js --testdir tests/ --runtime puppeteer

When tests run in Chromium, note that the function passed as the func property to registerTest will execute in the context of the browser page. In this case, the function can access window, document, etc., but keep in mind that variables outside of the function body will not be in scope during execution.

Command line flags

--help

Show usage instructions

--list

Only list found tests, don't run them.

--testdir [path/to/tests]

Directory to look in to find tests. Will assume all files with names ending in ".js" are test files.

--runtime [node|puppeteer]

Which runtime to use to run the tests. Defaults to "node."

--trx [path/to/outfile.trx]

Outputs results as a TRX file

API

The astr module exposes the following functions and interfaces:

registerTest(options: {
	/** A name for the test. Used when displaying test results */
	name: string,

	/** Paths to JavaScript files that should be included in the page before the test is executed. */
	dependencies?: string[],

	/** The test to execute. */
	func: (assert: Assert) => (void | Promise<void>),
})
/**
  * Indicates that subsequent calls to registerTest should place tests inside a module with
  * a given name. Test modules are used to group test result output. Calls to registerTest
  * before any call to registerModule has been made will place tests in a default module
  * with no name.
 */
registerModule(name: string)
/**
  * Registers a function to be called before every test in the current module
 */
registerTestInit(func: () => void | Promise<void>))
interface Assert
{
	equals(expected: any, actual: any, message?: string);
	
	truthy(value: any, message?: string);

	throws(func: Function, message?: string);

	deepEqual(expected: any, actual: any, message?: string);
}