jest-plugin-must-assert
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"jest": { | ||
"testEnvironment": "node", | ||
"setupFilesAfterEnv": ["../../"] | ||
"setupFilesAfterEnv": ["../../"], | ||
"testRunner": "jest-circus/runner" | ||
} | ||
} |
@@ -1,5 +0,5 @@ | ||
const pathJestAPI = require("./src"); | ||
const patchJestAPI = require('./src'); | ||
pathJestAPI({ | ||
logger: console | ||
patchJestAPI({ | ||
logger: console, | ||
}); |
{ | ||
"name": "jest-plugin-must-assert", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Jest plugin for async tests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,3 @@ # `jest-plugin-must-assert` | ||
Asynchronous tests could be challenging to get _right_, particulrary for junior | ||
developers or Engineers new to async JavaScript. The most common mistake is an async | ||
developers or engineers new to async JavaScript. The most common mistake is an async | ||
test which does not fire any assertions, either due to logic or even syntax errors. | ||
@@ -15,4 +15,4 @@ Static analysis(linters) gets close to pointing out the issues, but is not enough to catch logic mistakes. | ||
[Jest, unfortunately, has not "failWithoutAssertions" configuration options, so this plugin aims to remedy that.]() | ||
The plugin patches Jest API to force tests without any assertions to fail. In addition | ||
[Jest, unfortunately, has no "failWithoutAssertions" configuration options, so this plugin aims to remedy that.](https://github.com/facebook/jest/issues/2209) | ||
The plugin patches the Jest API to force tests without any assertions to fail. In addition | ||
to failing tests without assertions this plugin also patches a bug in Jest which | ||
@@ -39,5 +39,5 @@ leads to [assertions "leaking" accross different tests](https://github.com/facebook/jest/issues/8297). | ||
// <rootDir>/must-assert-setup.js | ||
const mustAssert = require('jest-plugin-must-assert/manual'); | ||
const patchJestAPI = require('jest-plugin-must-assert/manual'); | ||
mustAssert({ | ||
patchJestAPI({ | ||
/** | ||
@@ -50,10 +50,20 @@ * Control the task execution during a test. You may log a custom warning message | ||
* | ||
* @param {Object} options Options for the handler (see below) | ||
* | ||
* Options: | ||
* @param {Number} originTestId The unique ID of the test where the task is oginating from | ||
* @param {Number} currentTestId The unique ID of the currently executing test | ||
* @param {Function} log The log method (logger.warn) | ||
* @param {String} testName The name of the test which triggered this event | ||
* @param {String} taskType The type of task being invoked (micro/macro task) | ||
* @param {String} taskSource The source of the taks ("promise.then", "setTimeout" etc) | ||
* @param {Object} logger The logger object (defaults to console) | ||
* | ||
* @return {Boolean} true/false for whether or not the task should execute | ||
*/ | ||
onInvokeTask(originTestId, currentTestId, log) { | ||
return false; | ||
} | ||
/** | ||
* Logger DI. Used by the internal methods to log warnings/errors. Should match console API. | ||
*/ | ||
logger, | ||
@@ -60,0 +70,0 @@ }); |
module.exports = patchJestAPI; | ||
function onInvokeTaskDefault(originZoneId, currentZoneId, log) { | ||
function onInvokeTaskDefault({ | ||
originZoneId, | ||
currentZoneId, | ||
testName, | ||
taskType, | ||
taskSource, | ||
logger, | ||
}) { | ||
if (originZoneId !== currentZoneId) { | ||
log( | ||
`Test "${current.name}" is attempting to invoke a ${task.type}(${ | ||
task.source | ||
}) after test completion. Ignoring` | ||
logger.warn( | ||
`Test "${testName}" is attempting to invoke a ${taskType}(${taskSource}) after test completion. Ignoring` | ||
); | ||
@@ -60,3 +65,12 @@ return false; | ||
onInvokeTask(delegate, current, target, task, applyThis, applyArgs) { | ||
if (!onInvokeTask(current.get('id'), currentZone, logger.warn)) { | ||
if ( | ||
!onInvokeTask({ | ||
originZoneId: current.get('id'), | ||
currentZoneId: currentZone, | ||
testName: name, | ||
taskType: task.type, | ||
taskSource: task.source, | ||
logger: logger, | ||
}) | ||
) { | ||
return; | ||
@@ -63,0 +77,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
14481
367
84