Skip to content
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

Add test.skip() #194

Merged
merged 1 commit into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ module.exports.before = runner.addBeforeHook.bind(runner);
module.exports.after = runner.addAfterHook.bind(runner);
module.exports.beforeEach = runner.addBeforeEachHook.bind(runner);
module.exports.afterEach = runner.addAfterEachHook.bind(runner);
module.exports.skip = runner.addSkippedTest.bind(runner);
5 changes: 5 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ x.test = function (props) {
return;
}

if (props.skip) {
log.write(' ' + chalk.cyan('- ' + props.title));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is cyan really the best color for skipped? Just asking. It should at least be .dim too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid .dim will make it less noticeable, and the purpose of .skip() is to temporarily disable it. So if we keep it bright, it will stay in developer's focus, that something needs fixing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's try it out like that for now.

return;
}

// if (runner.stats.testCount === 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but we can probably remove this now, right? Because of bb1304c

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, spotted this crap, will remove later in cleanup PRs ;)

// return;
// }
Expand Down
15 changes: 14 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,19 @@ Runner.prototype.addAfterEachHook = function (title, cb) {
});
};

Runner.prototype.addSkippedTest = function (title, cb) {
var test = new Test(title, cb);
test.skip = true;

this.tests.concurrent.push(test);
};

Runner.prototype._runTestWithHooks = function (test) {
if (test.skip) {
this._addTestResult(test);
return Promise.resolve();
}

var beforeHooks = this.tests.beforeEach.map(function (hook) {
var title = hook.title || 'beforeEach for "' + test.title + '"';
hook = new Test(title, hook.fn);
Expand Down Expand Up @@ -162,7 +174,8 @@ Runner.prototype._addTestResult = function (test) {
duration: test.duration,
title: test.title,
error: test.assertError,
type: test.type
type: test.type,
skip: test.skip
};

this.results.push(props);
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,30 @@ test('test types and titles', function (t) {
runner.run().then(t.end);
});

test('skip test', function (t) {
t.plan(3);

var runner = new Runner();
var arr = [];

runner.addTest(function (a) {
arr.push('a');
a.end();
});

runner.addSkippedTest(function (a) {
arr.push('b');
a.end();
});

runner.run().then(function () {
t.is(runner.stats.testCount, 1);
t.is(runner.stats.passCount, 1);
t.same(arr, ['a']);
t.end();
});
});

test('ES2015 support', function (t) {
t.plan(1);

Expand Down