Skip to content

Instantly share code, notes, and snippets.

@niieani
Created March 4, 2018 18:51
Show Gist options
  • Save niieani/7065bead4f57cea0b9d25cc937df1585 to your computer and use it in GitHub Desktop.
Save niieani/7065bead4f57cea0b9d25cc937df1585 to your computer and use it in GitHub Desktop.
jest async suite
const { default: reporter } = require.requireActual(
"jest-jasmine2/build/reporter"
);
function runSuite(suite, parentSuite) {
const topSuite = jasmine.getEnv().topSuite();
const { children, id, result } = topSuite;
// setting this suite to disabled will not cause jest to
// clearResourcesForRunnable for this suite's ID
suite.disabled = true;
if (parentSuite) suite.parentSuite = parentSuite;
topSuite.children = [suite];
topSuite.id = suite.id;
// suite.result = result;
const cleanup = err => {
suite.disabled = false;
// topSuite.children = children;
// .filter(
// child => !suite.children.includes(child) && child !== suite
// );
topSuite.id = id;
// console.log(suite);
// topSuite.result = result;
return err;
};
return jasmine
.getEnv()
.execute()
.then(cleanup, cleanup);
}
function describeAndRun(name, fn, parentSuite) {
const itStashed = it;
global.it = global.fit;
const suite = describe(name, fn);
global.it = itStashed;
return runSuite(suite, parentSuite);
}
module.exports.runSuite = runSuite;
module.exports.describeAndRun = describeAndRun;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment