@adeira/fixtures-tester
Advanced tools
Comparing version 1.0.1 to 1.1.0
# Unreleased | ||
# 1.1.0 | ||
- New function `verifyTestsFromFixtures` added - it has similar interface as `generateTestsFromFixtures` except it verifies that the operation result is `true` instead of creating Jest snapshots. This is useful when you want to run some tests on your fixtures files but there is not much to snapshot. | ||
# 1.0.1 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"main": "src/index", | ||
"module": "src/index.mjs", | ||
"name": "@adeira/fixtures-tester", | ||
@@ -9,8 +7,10 @@ "description": "Utility to ease testing with fixtures.", | ||
"private": false, | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"main": "./src/index.js", | ||
"type": "commonjs", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@adeira/js": "^2.1.0", | ||
"@babel/runtime": "^7.13.10" | ||
"@babel/runtime": "^7.14.6" | ||
} | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
Install (via Yarn or NPM): | ||
```text | ||
@@ -7,3 +9,3 @@ yarn add @adeira/fixtures-tester | ||
This function loads all the fixtures (their file content) from your folder and it snapshots the result of your callback operation. This is handy when you have several example files, you want to perform some operation on top of them and snapshot the results. | ||
This function loads all the fixture files (their file content) from your folder and snapshots the result of your callback operation. This is handy when you have several example files, you want to perform some operation on top of them and snapshot the results. | ||
@@ -13,7 +15,9 @@ ```js | ||
function operation(input) { | ||
return doSomethingWithTheInput(input); | ||
} | ||
generateTestsFromFixtures(`${__dirname}/__fixtures__`, operation); | ||
generateTestsFromFixtures( | ||
`${__dirname}/__fixtures__`, | ||
(input: string): string => { | ||
return doSomethingWithTheInput(input); // this result will be saved in a Jest snapshot | ||
}, | ||
// optionally a snapshot name | ||
); | ||
``` | ||
@@ -28,1 +32,15 @@ | ||
The error file convention is required to prevent unintentional snapshots of exceptions. | ||
## `verifyTestsFromFixtures` | ||
This function simply verifies that the callback returns `true` but it doesn't snapshot anything: | ||
```js | ||
import { verifyTestsFromFixtures } from '@adeira/fixtures-tester'; | ||
verifyTestsFromFixtures(`${__dirname}/__fixtures__`, (input: string): boolean => { | ||
return isInputValid(input) === true; | ||
}); | ||
``` | ||
This is handy when the snapshot from `generateTestsFromFixtures` would be meaningless but you still want to check all available fixtures. |
@@ -20,2 +20,4 @@ "use strict"; | ||
var _getOutputForFixture = _interopRequireDefault(require("./getOutputForFixture")); | ||
var FIXTURE_TAG = Symbol.for('FIXTURE_TAG'); | ||
@@ -68,3 +70,2 @@ /** | ||
/* eslint-disable jest/no-disabled-tests */ | ||
// $FlowFixMe[prop-missing]: we need to update our Jest type definitions (TODO) | ||
test.skip.each(fixtures.filter(function (name) { | ||
@@ -76,4 +77,5 @@ return !shouldSkip(name); | ||
fixtures = onlyFixtures; | ||
} | ||
} // eslint-disable-next-line jest/no-identical-title | ||
test.each(fixtures.filter(isFile))('matches expected output: %s', /*#__PURE__*/function () { | ||
@@ -89,3 +91,3 @@ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file) { | ||
_context.next = 3; | ||
return getOutputForFixture(input, operation, file); | ||
return (0, _getOutputForFixture.default)(input, operation, file); | ||
@@ -113,50 +115,2 @@ case 3: | ||
}()); | ||
} | ||
function getOutputForFixture(_x2, _x3, _x4) { | ||
return _getOutputForFixture.apply(this, arguments); | ||
} | ||
function _getOutputForFixture() { | ||
_getOutputForFixture = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(input, operation, file) { | ||
var shouldThrow, result; | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
shouldThrow = /\.error\.\w+$/.test(file); | ||
if (!shouldThrow) { | ||
_context2.next = 14; | ||
break; | ||
} | ||
_context2.prev = 2; | ||
_context2.next = 5; | ||
return operation(input); | ||
case 5: | ||
result = _context2.sent; | ||
_context2.next = 11; | ||
break; | ||
case 8: | ||
_context2.prev = 8; | ||
_context2.t0 = _context2["catch"](2); | ||
return _context2.abrupt("return", "THROWN EXCEPTION:\n\n".concat(_context2.t0.toString())); | ||
case 11: | ||
throw new Error("Expected test file '".concat(file, "' to throw, but it passed:\n").concat(result)); | ||
case 14: | ||
return _context2.abrupt("return", operation(input)); | ||
case 15: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[2, 8]]); | ||
})); | ||
return _getOutputForFixture.apply(this, arguments); | ||
} |
@@ -14,3 +14,11 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "verifyTestsFromFixtures", { | ||
enumerable: true, | ||
get: function get() { | ||
return _verifyTestsFromFixtures.default; | ||
} | ||
}); | ||
var _generateTestsFromFixtures = _interopRequireDefault(require("./generateTestsFromFixtures")); | ||
var _generateTestsFromFixtures = _interopRequireDefault(require("./generateTestsFromFixtures")); | ||
var _verifyTestsFromFixtures = _interopRequireDefault(require("./verifyTestsFromFixtures")); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
26520
24
319
44
1
Updated@babel/runtime@^7.14.6