From f7cb8c02dc620b6894afac7728d522aea89b0afc Mon Sep 17 00:00:00 2001 From: Joe Lapp Date: Sun, 17 Jul 2016 16:31:00 -0500 Subject: [PATCH] .only no longer runs all tests having the same name --- index.js | 5 +++-- lib/results.js | 6 +++--- lib/test.js | 2 ++ test/only4.js | 10 ++++++++++ test/only5.js | 10 ++++++++++ 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 test/only4.js create mode 100644 test/only5.js diff --git a/index.js b/index.js index 2f067ae3..edb65a32 100644 --- a/index.js +++ b/index.js @@ -138,9 +138,10 @@ function createHarness (conf_) { var only = false; test.only = function (name) { if (only) throw new Error('there can only be one only test'); - results.only(name); + var t = test.apply(null, arguments); + results.only(t.number); only = true; - return test.apply(null, arguments); + return t; }; test._exitCode = 0; diff --git a/lib/results.js b/lib/results.js index e47c7d53..178aaa75 100644 --- a/lib/results.js +++ b/lib/results.js @@ -83,8 +83,8 @@ Results.prototype.push = function (t) { self.emit('_push', t); }; -Results.prototype.only = function (name) { - this._only = name; +Results.prototype.only = function (number) { + this._only = number; }; Results.prototype._watch = function (t) { @@ -176,7 +176,7 @@ function getNextTest (results) { do { var t = results.tests.shift(); if (!t) continue; - if (results._only === t.name) { + if (results._only === t.number) { return t; } } while (results.tests.length !== 0) diff --git a/lib/test.js b/lib/test.js index 497c58a4..a707f275 100644 --- a/lib/test.js +++ b/lib/test.js @@ -13,6 +13,7 @@ var nextTick = typeof setImmediate !== 'undefined' : process.nextTick ; var safeSetTimeout = setTimeout; +var nextTestNumber = 1; inherits(Test, EventEmitter); @@ -44,6 +45,7 @@ function Test (name_, opts_, cb_) { var args = getTestArgs(name_, opts_, cb_); + this.number = nextTestNumber++; this.readable = true; this.name = args.name || '(anonymous)'; this.assertCount = 0; diff --git a/test/only4.js b/test/only4.js new file mode 100644 index 00000000..d570b5bc --- /dev/null +++ b/test/only4.js @@ -0,0 +1,10 @@ +var test = require('../'); + +test('only4 duplicate test name', function (t) { + t.fail('not 1'); + t.end(); +}); + +test.only('only4 duplicate test name', function (t) { + t.end(); +}); diff --git a/test/only5.js b/test/only5.js new file mode 100644 index 00000000..0e158872 --- /dev/null +++ b/test/only5.js @@ -0,0 +1,10 @@ +var test = require('../'); + +test.only('only5 duplicate test name', function (t) { + t.end(); +}); + +test('only5 duplicate test name', function (t) { + t.fail('not 2'); + t.end(); +});