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 match option #477

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var cli = meow([
' --tap, -t Generate TAP output',
' --verbose, -v Enable verbose output',
' --no-cache Disable the transpiler cache',
' --match, -m Only run tests with titles matching',
Copy link
Member

Choose a reason for hiding this comment

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

Only run tests with matching title

Copy link
Member

Choose a reason for hiding this comment

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

The flag docs also needs to be reflected in the CLI help output in the readme.

'',
'Examples',
' ava',
Expand All @@ -62,7 +63,8 @@ var cli = meow([
], {
string: [
'_',
'require'
'require',
'match'
],
boolean: [
'fail-fast',
Expand All @@ -75,7 +77,8 @@ var cli = meow([
t: 'tap',
v: 'verbose',
r: 'require',
s: 'serial'
s: 'serial',
m: 'match'
}
});

Expand All @@ -90,6 +93,7 @@ var api = new Api(cli.input.length ? cli.input : arrify(conf.files), {
failFast: cli.flags.failFast,
serial: cli.flags.serial,
require: arrify(cli.flags.require),
match: cli.flags.match,
cacheEnabled: cli.flags.cache !== false
});

Expand Down
8 changes: 6 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ var chainableMethods = {
}
};

function Runner() {
function Runner(opts) {
if (!(this instanceof Runner)) {
return new Runner();
return new Runner(opts);
}

EventEmitter.call(this);

this.match = (opts && opts.match) ? opts.match : '';

this.results = [];
this.tests = new TestCollection();
this._addTestResult = this._addTestResult.bind(this);
Expand All @@ -48,6 +50,8 @@ optionChain(chainableMethods, function (opts, title, fn) {
title = null;
}

opts.skipped = opts.skipped || (title && title.indexOf(this.match) === -1);

this.tests.add({
metadata: opts,
fn: fn,
Expand Down
26 changes: 26 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,29 @@ test('only test', function (t) {
t.end();
});
});

test('skip test based on match option', function (t) {
t.plan(3);

var runner = new Runner({
match: 'dont skip me'
});

runner.test('skip me1', function () {
t.fail();
});

runner.skip('skip me2', function () {
t.fail();
});

runner.test('dont skip me', function () {
t.pass();
});

runner.run().then(function () {
t.is(runner.stats.passCount, 1);
t.is(runner.stats.failCount, 0);
t.end();
});
});