-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
beforeAll is being run even when it is inside xdescribe #4487
Comments
This may be related to #4166 |
Yup, looks like the same thing. I'll just notify @aaronabramov so he's aware of it. |
This bug still persist, why this issue was closed? For those interested, here's workaround patch, that ensures no Best is to load it in setup test file (one configured through setupTestFrameworkScriptFile setting) // Decorate treeProcessor to detect whether test is disabled
// (due to other group/test being marked with "only")
const treeProcessor = require.requireActual('jest-jasmine2/build/tree_processor',
{ isInternalModule: true });
const origTreeProcessorFn = treeProcessor.default;
treeProcessor.default = function treeProcessor(options) {
const runnableIds = options.runnableIds;
const tree = options.tree;
const isDirectlyEnabled = (node, parentEnabled) =>
(node._isEnabled = parentEnabled || runnableIds.indexOf(node.id) !== -1);
const resolveEnabled = (node, enabled) => {
if (!node.children || !node.children.length) return;
let hasChildEnabled = false;
node.children.forEach(child => {
resolveEnabled(child, isDirectlyEnabled(child, enabled));
if (child._isEnabled) hasChildEnabled = true;
});
if (!node._isEnabled && hasChildEnabled) {
node._isEnabled = true;
node.children.forEach(child => {
if (child._isBeforeAfterHack) child._isEnabled = true;
});
}
};
resolveEnabled(tree, isDirectlyEnabled(tree, false));
return origTreeProcessorFn.call(this, options);
};
// Dummy spec retriever (allows to detect whether parent group is skipped)
const getDummySpec = () => {
const spec = global.jasmine.getEnv().describe('ignore', Function.prototype);
spec._isBeforeAfterHack = true;
spec._parentMarkedPending = spec.markedPending;
spec.markedPending = true;
spec.onException = () => {};
return spec;
};
const decorateBeforeAfter = name => {
const originalFn = global[name];
global[name] = function (fn, ...args) {
const tmpSpec = getDummySpec();
if (tmpSpec._parentMarkedPending) return null;
return originalFn.call(this, Object.defineProperty(function (done, ...args) {
if (tmpSpec._isEnabled === false) {
if (done) done();
return null;
}
return fn.call(this, done, ...args);
}, 'length', { configurable: true, value: fn.length }), ...args);
};
};
decorateBeforeAfter('beforeAll');
decorateBeforeAfter('afterAll'); |
This is an issue for me. I naively tried to comment out a block of tests by changing describe to xdescribe, and the beforeAlls still run. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
beforeAll is being run even when it is inside xdescribe
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can
yarn install
andyarn test
.What is the expected behavior?
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
The text was updated successfully, but these errors were encountered: