Comparing version 1.3.1 to 1.3.2
@@ -7,3 +7,5 @@ "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)) { | ||
@@ -14,5 +16,6 @@ const partialTrace = [ | ||
]; | ||
trace.length = 0; | ||
trace.length = 0; // reset trace | ||
throw new givenError_1.default(`recursive variable ${key} detected\ntrace: ${partialTrace.join(' => ')}`, ssi); | ||
} | ||
// try to evaluate and cache | ||
try { | ||
@@ -19,0 +22,0 @@ trace.push(key); |
@@ -7,3 +7,3 @@ "use strict"; | ||
allowed: false, | ||
message: 'cannot call givens from a lifecycle hook', | ||
message: 'cannot call given from a lifecycle hook', | ||
}; | ||
@@ -14,3 +14,3 @@ } | ||
allowed: false, | ||
message: 'cannot call givens from a test', | ||
message: 'cannot call given from a test', | ||
}; | ||
@@ -27,3 +27,3 @@ } | ||
allowed: false, | ||
message: 'cannot call givens from a test', | ||
message: 'cannot call given from a test', | ||
}; | ||
@@ -34,3 +34,3 @@ } | ||
allowed: false, | ||
message: 'cannot call givens from a lifecycle hook', | ||
message: 'cannot call given from a lifecycle hook', | ||
}; | ||
@@ -44,12 +44,12 @@ } | ||
function jasmineContextMatcher(rawStack) { | ||
if (/jasmine\.js/.test(rawStack)) { | ||
if (!/Env\.describe/.test(rawStack)) { | ||
return { | ||
allowed: false, | ||
message: 'given must be called inside a describe', | ||
}; | ||
} | ||
return { allowed: true }; | ||
if (!/jasmine\.js/.test(rawStack)) { | ||
return undefined; | ||
} | ||
return undefined; | ||
if (!/Env\.describe/.test(rawStack)) { | ||
return { | ||
allowed: false, | ||
message: 'given must be called inside a describe', | ||
}; | ||
} | ||
return { allowed: true }; | ||
} | ||
@@ -60,2 +60,3 @@ function getContextInfo(ssf) { | ||
const err = new Error(); | ||
/* istanbul ignore else */ | ||
if (Error.captureStackTrace) { | ||
@@ -62,0 +63,0 @@ Error.captureStackTrace(err, ssf); |
@@ -19,5 +19,9 @@ "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); | ||
@@ -33,4 +37,6 @@ 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) { | ||
@@ -44,13 +50,20 @@ delete props[key]; | ||
} | ||
if (typeof before === 'function') { | ||
else if (typeof before === 'function') { | ||
before(`givens setup ${key}`, push); | ||
} | ||
else { | ||
throw new givenError_1.default('no test runner found', given); | ||
} | ||
if (typeof afterAll === 'function') { | ||
afterAll(pop); | ||
} | ||
if (typeof after === 'function') { | ||
else if (typeof after === 'function') { | ||
after(`givens teardown ${key}`, pop); | ||
} | ||
else { | ||
throw new givenError_1.default('no test runner found', given); | ||
} | ||
}; | ||
if (typeof afterEach === 'function') { | ||
// clear the cache after every test | ||
afterEach(() => { | ||
@@ -63,4 +76,7 @@ const cache = given.__cache__; | ||
} | ||
else { | ||
throw new givenError_1.default('no test runner found', getGivenFunc); | ||
} | ||
return given; | ||
}; | ||
exports.default = getGivenFunc; |
"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) { | ||
@@ -9,0 +20,0 @@ Error.captureStackTrace(this, ssf); |
@@ -10,8 +10,13 @@ "use strict"; | ||
const disallowedProps = [ | ||
// props created by this library | ||
'__props__', | ||
'__cache__', | ||
'__trace__', | ||
...allProps(() => undefined), | ||
// prototype props | ||
...allProps( | ||
// this is a noop function so the contents do not need to be covered | ||
/* istanbul ignore next */ | ||
() => undefined), | ||
]; | ||
const isValid = (key) => !disallowedProps.includes(key); | ||
exports.default = isValid; |
{ | ||
"name": "givens", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Easy test setup without side effects", | ||
@@ -13,24 +13,25 @@ "main": "dist/getGiven.js", | ||
"scripts": { | ||
"prepack": "npm run build", | ||
"prepack": "make dist", | ||
"clean": "make clean", | ||
"install:tests": "npm-run-all install:tests:**", | ||
"install:tests:js-jest": "cd integration-tests/javascript/jest && npm i --no-package-lock", | ||
"install:tests:js-mocha": "cd integration-tests/javascript/mocha && npm i --no-package-lock", | ||
"install:tests:js-jasmine": "cd integration-tests/javascript/jasmine && npm i --no-package-lock", | ||
"install:tests:ts-jest": "cd integration-tests/typescript/jest && npm i --no-package-lock", | ||
"build": "tsc --removeComments && npm run copy-dts", | ||
"build:tests": "tsc --inlineSourceMap && npm run copy-dts", | ||
"copy-dts": "copyfiles -u 1 \"src/getGiven.d.ts\" dist", | ||
"install:tests:manual": "cd test/manual-tests && npm ci", | ||
"install:tests:js-jest": "cd test/integration-tests/javascript/jest && npm ci", | ||
"install:tests:js-mocha": "cd test/integration-tests/javascript/mocha && npm ci", | ||
"install:tests:js-jasmine": "cd test/integration-tests/javascript/jasmine && npm ci", | ||
"install:tests:ts-jest": "cd test/integration-tests/typescript/jest && npm ci", | ||
"lint": "npm-run-all --continue-on-error lint:**", | ||
"lint:main": "eslint ./src/**.* ./test/**.* --ext .ts", | ||
"lint:js-jest": "eslint ./integration-tests/javascript/jest/test/**.* --ext .js", | ||
"lint:js-mocha": "eslint ./integration-tests/javascript/mocha/test/**.* --ext .js", | ||
"lint:js-jasmine": "eslint ./integration-tests/javascript/jasmine/spec/**.* --ext .js", | ||
"lint:ts-jest": "eslint ./integration-tests/typescript/jest/test/**.* --ext .ts", | ||
"lint:src": "eslint ./src/**.* --ext .ts", | ||
"lint:unit": "eslint ./test/unit-tests/**.* --ext .ts", | ||
"lint:manual": "eslint ./test/manual-tests/**.* --ext .js", | ||
"lint:js-jest": "eslint ./test/integration-tests/javascript/jest/test/**.* --ext .js", | ||
"lint:js-mocha": "eslint ./test/integration-tests/javascript/mocha/test/**.* --ext .js", | ||
"lint:js-jasmine": "eslint ./test/integration-tests/javascript/jasmine/spec/**.* --ext .js", | ||
"lint:ts-jest": "eslint ./test/integration-tests/typescript/jest/test/**.* --ext .ts", | ||
"test": "npm-run-all --continue-on-error test:**", | ||
"test:unit": "jest", | ||
"test:js-jest": "cd integration-tests/javascript/jest && npm test", | ||
"test:js-mocha": "cd integration-tests/javascript/mocha && npm test", | ||
"test:js-jasmine": "cd integration-tests/javascript/jasmine && npm test", | ||
"test:ts-jest": "cd integration-tests/typescript/jest && npm test", | ||
"clean": "./clean.sh" | ||
"test:manual": "cd test/manual-tests && npm run coverage", | ||
"test:js-jest": "cd test/integration-tests/javascript/jest && npm test", | ||
"test:js-mocha": "cd test/integration-tests/javascript/mocha && npm run coverage", | ||
"test:js-jasmine": "cd test/integration-tests/javascript/jasmine && npm run coverage", | ||
"test:ts-jest": "cd test/integration-tests/typescript/jest && npm test" | ||
}, | ||
@@ -60,26 +61,32 @@ "keywords": [ | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-plugin-jasmine": "^4.1.0", | ||
"eslint-plugin-jest": "^23.8.2", | ||
"eslint-plugin-jasmine": "^4.1.0", | ||
"eslint-plugin-mocha": "^4.1.0", | ||
"jest": "^25.1.0", | ||
"npm-run-all": "^4.1.5", | ||
"source-map-url-cli": "^0.1.0", | ||
"ts-jest": "^25.2.1", | ||
"typescript": "^3.8.3" | ||
}, | ||
"eslintConfig": { | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
"jest": { | ||
"automock": true, | ||
"verbose": true, | ||
"roots": [ | ||
"<rootDir>/src", | ||
"<rootDir>/test/unit-tests" | ||
], | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended" | ||
"testMatch": [ | ||
"**/?(*.)+(spec|test).+(ts|tsx|js)" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-var-requires": "off" | ||
} | ||
"transform": { | ||
"^.+\\.ts$": "ts-jest" | ||
}, | ||
"coverageReporters": [ | ||
"lcov" | ||
], | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"src/**/*.ts" | ||
] | ||
} | ||
} |
@@ -8,3 +8,5 @@ <p align="center"> | ||
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/enova/givens/CI?label=tests"> | ||
<a href='https://coveralls.io/github/enova/givens?branch=master'><img src='https://coveralls.io/repos/github/enova/givens/badge.svg?branch=master' alt='Coverage Status' /></a> | ||
<a href="https://codecov.io/gh/enova/givens"> | ||
<img src="https://codecov.io/gh/enova/givens/branch/master/graph/badge.svg" /> | ||
</a> | ||
<a href='https://github.com/enova/givens/blob/master/LICENSE'><img alt="MIT License" src="https://img.shields.io/github/license/enova/givens"></a> | ||
@@ -11,0 +13,0 @@ </p> |
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
17597
263
119
15