New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bron

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bron

Tiny test runner

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-58.82%
Maintainers
1
Weekly downloads
 
Created
Source

bron

Tiny test runner

  • Single test() function, plus .skip() and .only()
  • No magic, no separate processes, no dependencies
  • Use the Node.js built-in assert module, or bring your own (e.g. chai, should.js)
  • Run tests in parallel (default), or serial
  • Requires Node.js v8+ (Node.js v12 has better validations and error messages)

Installation

npm install bron -D

Add a test script to run the tests (npm test), e.g.:

{
  "scripts": {
    "test": "bron test/*.js"
  }
}

Usage from CLI

bron <file> [--serial]

Writing tests

sync

const test = require('bron');
const assert = require('assert').strict;

const add = (x, y) => x + y;

test('should pass', () => {
  assert.equal(add(1, 2), 3);
});

test('should fail', () => {
  assert.equal(add(1, 2), 4);
});
$ bron test.js
✔ should pass
✖ should fail
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

3 !== 4

    at /Users/lars/Projects/bron/sync.js:11:10
    ...

✖ 1 test(s) failed
✔ 1 test(s) passed

async

No magic, but know that the tests run in parallel.

const addAsync = (x, y) => (x && y ? Promise.resolve(x + y) : Promise.reject('no can do'));

test('should pass with resolved promise', () => {
  assert.doesNotReject(addAsync(1, 2));
});

test('should pass with rejected promise', () => {
  assert.rejects(addAsync(1), /no can do/);
});

serial

Add --serial:

const wait = ms => new Promise(r => setTimeout(r, ms));

test('should run serial (first)', async () => {
  await wait(100);
  assert(true);
});

test('should run serial (last)', async () => {
  await wait(0);
  assert(true);
});
$ bron --serial
✔ should run serial (first)
✔ should run serial (last)

promises

Return a promise, and the test will pass (resolved) or fail (rejected).

const addAsync = (x, y) => (x && y ? Promise.resolve(x + y) : Promise.reject('no can do'));

test('should pass with resolved promise', () => {
  return addAsync(1, 2);
});

test('should fail with rejected promise', () => {
  return addAsync(1);
});
$ bron
✔ should pass with resolved promise
✖ should fail with rejected promise
no can do

✖ 1 test(s) failed.
✔ 1 test(s) passed.

.skip

test.skip('should be skipped', () => {
  assert.equal(1, 1);
});

.only

test.only('should pass', () => {
  assert.equal(1, 1);
});

test('should be skipped', () => {
  assert.equal(1, 1);
});

You can use .only multiple times (each .only will run).

Keywords

FAQs

Package last updated on 07 Jun 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc