Skip to content

Commit

Permalink
Implement a match option.
Browse files Browse the repository at this point in the history
This aims to resolve issue #476. --match can be passed to ava which
means to only run tests with a title matching the provided match
string. The skipped metadata flag will be added to each test not
matching the match string.
  • Loading branch information
matthewbauer committed Jan 27, 2016
1 parent ffef6d6 commit f3c8a58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
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',
'',
'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();
});
});

0 comments on commit f3c8a58

Please sign in to comment.