Skip to content

Instantly share code, notes, and snippets.

@emilong
Last active October 14, 2016 22:41
Show Gist options
  • Save emilong/ec805d403f328b7b6f90f99c0850d9f7 to your computer and use it in GitHub Desktop.
Save emilong/ec805d403f328b7b6f90f99c0850d9f7 to your computer and use it in GitHub Desktop.
const sanitize = require('sanitize-filename');
// Declared outside any describe() or context() block so that it's called after every test.
// this is bound by Mocha to let us have access to the current test state, so we make sure
// to avoid a fat-arrow function declaration here.
afterEach(function(){
const filename = `${sanitize(this.currentTest.title.replace(/\s+/g, '-'))}-${+new Date()}`;
if (this.currentTest.state === 'failed') {
return captureLogs(`${filename}.log`)
.then(() => takeScreenshot(`${filename}.png`));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment