Skip to content

Instantly share code, notes, and snippets.

@yoav-lavi
Created October 13, 2019 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoav-lavi/19f75d24181862d69399548abd49be26 to your computer and use it in GitHub Desktop.
Save yoav-lavi/19f75d24181862d69399548abd49be26 to your computer and use it in GitHub Desktop.
Scriptable describe + test
exports.describe = async (name, callback) => {
const output = [];
const test = async (name, callback) => {
const testStartTime = Date.now();
const testResult = await callback();
const testTime =
Date.now() - testStartTime;
output.push(
`• ${name} (${testTime}ms): ${
testResult ? '✅' : '❌'
}`
);
};
const suiteStartTime = Date.now();
await callback(test);
const totalTime =
Date.now() - suiteStartTime;
output.push(`${totalTime}ms total`);
const alert = new Alert();
alert.title = name;
alert.message = output.join('\n');
alert.addAction('Done');
alert.present();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment