Comparing version 1.0.1 to 1.0.2
"use strict"; | ||
/* eslint-disable no-param-reassign */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,5 +7,3 @@ const givenError_1 = require("./givenError"); | ||
if (value === undefined) { | ||
// get the most recent declaration for key | ||
const topFunc = props[key][props[key].length - 1]; | ||
// check for recursive definition, and error if present | ||
if (trace.includes(key)) { | ||
@@ -17,6 +14,5 @@ const partialTrace = [ | ||
]; | ||
trace.length = 0; // reset trace | ||
trace.length = 0; | ||
throw new givenError_1.default(`recursive variable ${key} detected\ntrace: ${partialTrace.join(' => ')}`, ssi); | ||
} | ||
// try to evaluate and cache | ||
try { | ||
@@ -23,0 +19,0 @@ trace.push(key); |
@@ -16,14 +16,8 @@ "use strict"; | ||
} | ||
/* eslint-disable no-underscore-dangle */ | ||
const props = given.__props__; | ||
const cache = given.__cache__; | ||
const trace = given.__trace__; | ||
/* eslint-enable no-underscore-dangle */ | ||
// push function onto prop stack | ||
const push = () => { | ||
// add a getter with this key to the global given object if it is missing | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (!given.hasOwnProperty(key)) { | ||
props[key] = []; | ||
// make sure to pass the correct ssi for easier debugging | ||
const getter = () => evaluate_1.default(key, props, cache, trace, getter); | ||
@@ -39,6 +33,4 @@ Object.defineProperty(given, key, { | ||
}; | ||
// pop function off prop stack | ||
const pop = () => { | ||
props[key].pop(); | ||
// remove keys that no longer have values. | ||
if (props[key].length === 0) { | ||
@@ -49,3 +41,2 @@ delete props[key]; | ||
}; | ||
// remove cached props | ||
const clearCache = () => { | ||
@@ -52,0 +43,0 @@ delete cache[key]; |
export default class GivenError extends Error { | ||
constructor(message: string, ssf?: Function); | ||
constructor(message: string, ssf: Function); | ||
} |
"use strict"; | ||
// This class is heavily influenced by: | ||
// JavaScript Errors and Stack Traces in Depth | ||
// 17th of February, 2017 — Lucas Fernandes da Costa at Florianópolis, Brazil | ||
// https://lucasfcosta.com/2017/02/17/JavaScript-Errors-and-Stack-Traces.html | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// `ssf` stands for "start stack function". It is the reference to the | ||
// starting point for removing irrelevant frames from the stack trace | ||
class GivenError extends Error { | ||
constructor(message, ssf) { | ||
// 'Error' breaks prototype chain here | ||
super(`givens: ${message}`); | ||
// restore prototype chain | ||
const actualProto = new.target.prototype; | ||
Object.setPrototypeOf(this, actualProto); | ||
// If a start stack function (ssf) was provided we capture the current stack trace and pass | ||
// it to the `captureStackTrace` function so we can remove frames that come after it | ||
if (ssf && Error.captureStackTrace) { | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, ssf); | ||
} | ||
else { | ||
// If no start stack function was provided we just use the original stack property | ||
try { | ||
throw new Error(); | ||
} | ||
catch (e) { | ||
this.stack = e.stack; | ||
} | ||
} | ||
} | ||
} | ||
exports.default = GivenError; |
@@ -10,7 +10,5 @@ "use strict"; | ||
const disallowedProps = [ | ||
// props created by this library | ||
'__props__', | ||
'__cache__', | ||
'__trace__', | ||
// prototype props | ||
...allProps(() => { }), | ||
@@ -17,0 +15,0 @@ ]; |
{ | ||
"name": "givens", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Easy test setup without side effects", | ||
@@ -13,9 +13,10 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"build": "tsc --removeComments", | ||
"build:tests": "tsc --inlineSourceMap", | ||
"lint": "eslint ./src/**.* --ext .ts", | ||
"lint:fix": "eslint -c .eslintrc.js --fix ./src", | ||
"test": "npm-run-all --aggregate-output --continue-on-error --parallel --print-label test:**", | ||
"test:unit:jest": "jest test/unit/jest/**.spec.js --color", | ||
"test:unit:jest": "jest test/unit/jest/**.spec.ts --config jest-unit.config.js --color", | ||
"test:unit:mocha": "mocha test/unit/mocha/**.spec.js --color", | ||
"test:integration:jest": "jest test/integration/jest/**.test.js --color", | ||
"test:integration:jest": "jest test/integration/jest/**.test.js --config jest-integration.config.js --color", | ||
"test:integration:mocha": "mocha test/integration/mocha/**.test.js --color" | ||
@@ -33,2 +34,4 @@ }, | ||
"devDependencies": { | ||
"@types/jest": "^24.9.0", | ||
"@types/node": "^13.1.7", | ||
"@typescript-eslint/eslint-plugin": "^2.15.0", | ||
@@ -47,2 +50,3 @@ "@typescript-eslint/parser": "^2.15.0", | ||
"npm-run-all": "^4.1.5", | ||
"ts-jest": "^24.3.0", | ||
"typescript": "^3.7.4" | ||
@@ -49,0 +53,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12596
17
209