Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baddsert

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baddsert - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

41

badd.ts

@@ -5,2 +5,11 @@ 'use strict';

export interface IComparator {
(a: any, b: any): boolean
}
let maybeToString = item => {
if (!item) { return item; }
return item.toString ? item.toString() : item;
};
// Some init thing

@@ -10,6 +19,6 @@ // Gets a label, creates a file named that in the above folder

export let baddsertInject = getStoredResults => {
return fileName => {
return (fileName: string): Function => {
let stored = getStoredResults(fileName);
return (label: string, data) => {
return (label: string, data: any, comparator?: IComparator): void => {
// Mreh. TODO: Better way to handle symbols

@@ -22,9 +31,27 @@ if (typeof data === 'symbol') {

if (stored[label] && stored[label].hasOwnProperty('reference')) {
try {
deepStrictEqual(stored[label].reference, data);
} catch (e) {
stored[label].current = data;
throw new Error(`${label}: Expected ${data.toString()} to equal ${stored[label].reference}.`);
// We have a previous result
if (comparator) {
// Use the provided comparison tool
let result;
try {
result = comparator(stored[label].reference, data);
} catch (e) {
result = false;
}
if (!result) {
stored[label].current = data;
throw new Error(`${label}: Expected '${maybeToString(data)}' to equal '${stored[label].reference}'.`);
}
} else {
// Use default
try {
deepStrictEqual(stored[label].reference, data);
} catch (e) {
stored[label].current = data;
throw new Error(`${label}: Expected '${maybeToString(data)}' to equal '${stored[label].reference}'.`);
}
}
} else {
// We don't have it, assume correct
console.log(`Making new entry for ${label}, populated with ${data}`);

@@ -31,0 +58,0 @@ stored[label] = {

5

dist/badd.d.ts

@@ -1,1 +0,4 @@

export declare let baddsertInject: (getStoredResults: any) => (fileName: any) => (label: string, data: any) => void;
export interface IComparator {
(a: any, b: any): boolean;
}
export declare let baddsertInject: (getStoredResults: any) => (fileName: string) => Function;
'use strict';
const assert_1 = require('assert');
let maybeToString = item => {
if (!item) {
return item;
}
return item.toString ? item.toString() : item;
};
// Some init thing

@@ -7,5 +13,5 @@ // Gets a label, creates a file named that in the above folder

exports.baddsertInject = getStoredResults => {
return fileName => {
return (fileName) => {
let stored = getStoredResults(fileName);
return (label, data) => {
return (label, data, comparator) => {
// Mreh. TODO: Better way to handle symbols

@@ -17,11 +23,30 @@ if (typeof data === 'symbol') {

if (stored[label] && stored[label].hasOwnProperty('reference')) {
try {
assert_1.deepStrictEqual(stored[label].reference, data);
// We have a previous result
if (comparator) {
// Use the provided comparison tool
let result;
try {
result = comparator(stored[label].reference, data);
}
catch (e) {
result = false;
}
if (!result) {
stored[label].current = data;
throw new Error(`${label}: Expected '${maybeToString(data)}' to equal '${stored[label].reference}'.`);
}
}
catch (e) {
stored[label].current = data;
throw new Error(`${label}: Expected ${data.toString()} to equal ${stored[label].reference}.`);
else {
// Use default
try {
assert_1.deepStrictEqual(stored[label].reference, data);
}
catch (e) {
stored[label].current = data;
throw new Error(`${label}: Expected '${maybeToString(data)}' to equal '${stored[label].reference}'.`);
}
}
}
else {
// We don't have it, assume correct
console.log(`Making new entry for ${label}, populated with ${data}`);

@@ -28,0 +53,0 @@ stored[label] = {

@@ -1,1 +0,1 @@

export declare let baddsert: (fileName: any) => (label: string, data: any) => void;
export declare let baddsert: (fileName: string) => Function;

@@ -61,4 +61,21 @@ 'use strict';

it('should persist an undefined item', () => {
// No check, just reading test output, yeaaaahhh...
realB('undef', undefined);
});
it.only('allows the user to pass a different comparator', () => {
let didThrow = true;
try {
baddsert('diff comparator', 'moosle0');
baddsert('diff comparator', 'moosle', (a, b) => {
realB('comparator a', a);
realB('comparator b', b);
return false;
});
didThrow = false;
}
catch (e) {
realB('comparator reject', e.message);
}
realB('comparator didThrow', didThrow);
});
});
{
"name": "baddsert",
"version": "0.1.6",
"version": "0.1.7",
"description": "Baseline Acceptance Driven Development for JavaScript",

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

@@ -26,3 +26,3 @@ # baddsert

let result = hammertime(`can't touch this`);
docTests('I am a steg-o-sarus', result);
docTests('I am a steg-o-saurus', result);
});

@@ -35,2 +35,4 @@ ```

There's an optional third param that allows you to define your own equality. Otherwise baddsert will just use `deepStrictEqual` from Node's assert package.
And now, the magic happens. When you run your tests, baddsert will take the result from the first test and save it under the `badd-baseline` directory (in this case, as the file `docTests`). Future runs will throw if the value passed in is not `deepStrictEqual` to the original one.

@@ -48,4 +50,34 @@

### Installation
I
nstall the baddsert cli globally:
```sh
$ npm install -g baddsert
```
Add it as a dev dependency (for npm scripts & such)
```sh
$ npm install --save-dev baddsert
```
When installing as a dev dependency it is recommended you add this to your npm scripts in your package.json
```json
{
"scripts": {
"baddsert": "baddsert"
}
}
```
Then you can run baddsert as such (without requiring a global install)
```sh
$ npm run baddsert
```
Easy as pie.
Further reading: https://medium.com/@tinganho/baseline-acceptance-driven-development-f39f7010a04#.d1fdg36x0
Further reading on BADD development practices: https://medium.com/@tinganho/baseline-acceptance-driven-development-f39f7010a04#.d1fdg36x0

@@ -68,4 +68,22 @@ 'use strict';

it('should persist an undefined item', () => {
// No check, just reading test output, yeaaaahhh...
realB('undef', undefined);
});
it.only('allows the user to pass a different comparator', () => {
let didThrow = true;
try {
baddsert('diff comparator', 'moosle0')
baddsert('diff comparator', 'moosle', (a, b) => {
realB('comparator a', a);
realB('comparator b', b);
return false;
});
didThrow = false;
} catch (e) {
realB('comparator reject', e.message);
}
realB('comparator didThrow', didThrow);
});
});

@@ -31,3 +31,3 @@

"no-duplicate-variable": true,
"no-eval": true,
"no-eval": false,
"no-inferrable-types": false,

@@ -34,0 +34,0 @@ "no-internal-module": true,

Sorry, the diff of this file is not supported yet

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