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 - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

test/timeout.js

6

bron.js
#!/usr/bin/env node
const { EOL } = require('os');
const { existsSync } = require('fs');
const { run } = require('.');
const args = process.argv.slice(2);
const files = args.filter(file => file !== '--serial');
const files = args.filter(existsSync);
const isSerial = args.some(arg => arg === '--serial');
const timeout = parseInt(/(?<=--timeout[ =])[0-9]+/.exec(args.join(' ')), 10) || 15000;
run({ files, isSerial })
run({ files, isSerial, timeout })
.then(({ total, failed, passed }) => {

@@ -12,0 +14,0 @@ const summary = [];

@@ -6,37 +6,49 @@ const { types } = require('util');

let tests, only, results;
let tests, only;
let passed, failed, skipped;
const createHandlers = title => [
() => {
passed++;
console.log(`✔ ${title}`);
},
err => {
failed++;
console.log(`✖ ${title}`);
console.error(err);
}
];
const start = ({ title, timeout, resolve }) => {
let called;
const end = err => {
if (called) return;
called = true;
clearTimeout(timer);
if (err instanceof Error) {
failed++;
console.log(`✖ ${title}`);
console.error(err);
} else {
passed++;
console.log(`✔ ${title}`);
}
resolve();
};
const timer = setTimeout(end, timeout, new Error(`Test "${title}" timed out after ${timeout}ms`));
return end;
};
const execute = async ({ tests, isSerial }) => {
const execute = async ({ tests, isSerial, timeout = 15000 }) => {
const results = [];
for (const index in tests) {
const [title, testFn] = tests[index];
const [pass, fail] = createHandlers(title);
try {
const testResult = isSerial ? await testFn() : testFn();
results.push(testResult);
if (isPromise(testResult)) {
testResult.then(pass).catch(fail);
} else {
pass();
const test = new Promise(resolve => {
const end = start({ title, timeout, resolve });
try {
const testResult = testFn();
if (isPromise(testResult)) {
testResult.then(() => end()).catch(end);
} else {
end();
}
} catch (err) {
end(err);
}
} catch (err) {
fail(err);
}
});
results.push(isSerial ? await test : test);
}
return results;
};
const run = async ({ files, isSerial }) => {
[tests, results, only] = [[], [], []];
const run = async ({ files, isSerial, timeout }) => {
[tests, only] = [[], [], []];
[passed, failed, skipped] = [0, 0, 0];

@@ -46,3 +58,3 @@

await execute({ tests: only.length ? only : tests, isSerial });
const results = await execute({ tests: only.length ? only : tests, isSerial, timeout });

@@ -49,0 +61,0 @@ await Promise.all(results).catch(err => {});

{
"name": "bron",
"version": "1.0.2",
"version": "1.1.0",
"description": "Tiny test runner",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -10,4 +10,8 @@ # bron

- Run tests in parallel (default), or serial
- Timeouts (default: 15s)
- Requires Node.js v8+ (Node.js v12 has better validations and error messages)
[![Build Status](https://travis-ci.org/webpro/bron.svg?branch=master)](https://travis-ci.org/webpro/bron)
[![npm version](https://badge.fury.io/js/bron.svg)](https://www.npmjs.com/package/bron)
## Why?

@@ -19,15 +23,14 @@

Turns out this isn't very hard to implement, bron is only <70 LOC. In case you need more from your test framework, I'm
happy to recommend one of the more full fledged options:
Turns out this isn't very hard to implement, all source code of bron combined is only <100 LOC. In case you need more
from your test framework, I'm happy to recommend one of the more full fledged options:
| Runner | Dependencies | Size |
| -------------- | :----------: | ----: |
| Bron (v1.0.0) | 0 | 3K |
| Tape (v4.10.2) | 32 | 263K |
| Mocha (v6.1.4) | 115 | 1.52M |
| Ava (v2.0.0) | 453 | 3.95M |
| Bron (v1.1.0) | 0 | 5K |
| Tape (v4.11.0) | 32 | 265K |
| Mocha (v6.2.0) | 116 | 1.53M |
| Ava (v2.2.0) | 387 | 3.68M |
## Not featuring...
- Timeouts (TODO)
- Extensive command-line options

@@ -58,3 +61,3 @@ - TAP reporting

```
bron <file> [--serial]
bron <file> [--serial] [--timeout=500]
```

@@ -183,1 +186,5 @@

You can use `.only` multiple times (each `.only` will run).
## Timeout
Add `--timeout=n` (with `n` in milliseconds) to change the default value for each test (`15000`).

@@ -108,2 +108,24 @@ const { EOL } = require('os');

}
logStub.reset();
errorStub.reset();
{
const { total, failed, passed } = await run({ files: ['test/timeout.js'], timeout: 100 });
const output = logStub.args.map(args => args[0]);
assert.deepEqual(output, [
'✔ should not time out',
'✔ should not time out (1ms)',
'✔ should not time out (50ms)',
'✖ should time out (150ms)',
'✖ should time out (150ms)'
]);
assert.equal(total, 5);
assert.equal(failed, 2);
assert.equal(passed, 3);
console.info(output.join(EOL));
}
} catch (err) {

@@ -110,0 +132,0 @@ console.warn(err);

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