New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

impunity

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

impunity

js test runner that finds unit tests in any imported ES module

Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
76
-1.3%
Maintainers
1
Weekly downloads
 
Created
Source

Impunity, finds and runs unit tests in any imported ES module.

Do you like keeping your unit tests close to your code, with as little fanfare as possible? Does it annoy you to export things just to be able to test them? Inspired by rust's cargo, I want to write unit tests in the same file as the code they test. With this tool, you write the following in any module of your project:

export default class SomeClass {

}

export function tests() {
	return {
		test_a(assert) {
			assert(new SomeClass().a, undefined);
		}
	}
}

A test function receives the nodejs assert module so you don't need to import it.

After installing with npm install --global impunity, you run the tests with impunity --entry-point your/main.js (use --force-esm-dirs src/ if you use ES modules with ".js" extension) and it will discover all the tests in any file (indirectly) imported from your entry point, and run them:

(node:2031) ExperimentalWarning: The ESM module loader is experimental.
 * subpath::filename::test_a ... ok

impunity looks for an exported function called tests (you can choose another name to look for with the --symbol ... flag).

To remove the tests from a production build, Rollup does a good job of removing unused code automatically during bundling.

Typescript

impunity uses esbuild-node-loader to transform source files, including typescript files.

FAQs

Package last updated on 19 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts