Comparing version 1.3.2 to 1.3.3
@@ -7,5 +7,3 @@ "use strict"; | ||
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)) { | ||
@@ -16,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 { | ||
@@ -22,0 +19,0 @@ trace.push(key); |
@@ -55,3 +55,2 @@ "use strict"; | ||
const err = new Error(); | ||
/* istanbul ignore else */ | ||
if (Error.captureStackTrace) { | ||
@@ -58,0 +57,0 @@ Error.captureStackTrace(err, ssf); |
@@ -19,9 +19,5 @@ "use strict"; | ||
const trace = given.__trace__; | ||
// 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); | ||
@@ -37,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) { | ||
@@ -67,3 +61,2 @@ delete props[key]; | ||
if (typeof afterEach === 'function') { | ||
// clear the cache after every test | ||
afterEach(() => { | ||
@@ -70,0 +63,0 @@ const cache = given.__cache__; |
"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 | ||
/* istanbul ignore else */ | ||
if (Error.captureStackTrace) { | ||
@@ -20,0 +9,0 @@ Error.captureStackTrace(this, ssf); |
@@ -10,13 +10,8 @@ "use strict"; | ||
const disallowedProps = [ | ||
// props created by this library | ||
'__props__', | ||
'__cache__', | ||
'__trace__', | ||
// prototype props | ||
...allProps( | ||
// this is a noop function so the contents do not need to be covered | ||
/* istanbul ignore next */ | ||
() => undefined), | ||
...allProps(Function.prototype), | ||
]; | ||
const isValid = (key) => !disallowedProps.includes(key); | ||
exports.default = isValid; |
{ | ||
"name": "givens", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Easy test setup without side effects", | ||
@@ -5,0 +5,0 @@ "main": "dist/getGiven.js", |
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
16131
236