From cefa56cfe44afd0fc009a9dbb84fb53823f590a4 Mon Sep 17 00:00:00 2001 From: Arnulfo Solis Date: Tue, 30 Jun 2020 19:13:54 +0200 Subject: [PATCH 1/4] provide the spec title based from the specs name --- lib/contextProxy.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/contextProxy.js b/lib/contextProxy.js index 3fc4ec1..00b3a32 100644 --- a/lib/contextProxy.js +++ b/lib/contextProxy.js @@ -6,8 +6,18 @@ function ContextProxy(spec) { this.spec = spec; this.config = {}; + this.title = spec ? spec.name : undefined; } +/** + * Returns the full title of the test. + * + * @return {string} + */ +ContextProxy.prototype.fullTitle = function() { + return this.title; +}; + /** * Set test timeout. * From 44c6fd75568bbdb83dc908eec26b3db2c31dd5f2 Mon Sep 17 00:00:00 2001 From: Arnulfo Solis Date: Tue, 30 Jun 2020 19:14:12 +0200 Subject: [PATCH 2/4] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fb381e..5bd2791 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mocha.parallel", - "version": "0.15.6", + "version": "0.15.7", "description": "Run async mocha specs in parallel", "main": "lib/parallel.js", "scripts": { From dd36fabd2ef20ac01957a96bf74132fc40dcbb94 Mon Sep 17 00:00:00 2001 From: Arnulfo Solis Date: Tue, 30 Jun 2020 19:33:01 +0200 Subject: [PATCH 3/4] move everything to the spec rather than in the proxy --- lib/contextProxy.js | 12 +----------- lib/parallel.js | 4 ++++ spec/fixtures/contextProxy.js | 7 +++++++ spec/spec.js | 3 ++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/contextProxy.js b/lib/contextProxy.js index 00b3a32..2c62248 100644 --- a/lib/contextProxy.js +++ b/lib/contextProxy.js @@ -4,20 +4,10 @@ * @param {Spec} [spec] */ function ContextProxy(spec) { - this.spec = spec; + this.spec = spec || {}; this.config = {}; - this.title = spec ? spec.name : undefined; } -/** - * Returns the full title of the test. - * - * @return {string} - */ -ContextProxy.prototype.fullTitle = function() { - return this.title; -}; - /** * Set test timeout. * diff --git a/lib/parallel.js b/lib/parallel.js index fc6be65..bc744f3 100644 --- a/lib/parallel.js +++ b/lib/parallel.js @@ -223,6 +223,10 @@ function patchIt(specs) { var spec = { name: name, + title: name, + fullTitle: function() { + return this.title; + }, getPromise: function() { var start = Date.now(); return createWrapper(fn, spec.ctx)().then(function(duration) { diff --git a/spec/fixtures/contextProxy.js b/spec/fixtures/contextProxy.js index 65f2e54..192305c 100644 --- a/spec/fixtures/contextProxy.js +++ b/spec/fixtures/contextProxy.js @@ -23,4 +23,11 @@ parallel('suite', function() { it('test4', function(done) { setTimeout(done, 2500); }); + + it('test5', function(done) { + assert.strictEqual('test5', this.spec.title); + assert.strictEqual('test5', this.spec.fullTitle()); + assert.strictEqual('test5', this.spec.name); + done(); + }); }); diff --git a/spec/spec.js b/spec/spec.js index 29c1495..3c72218 100644 --- a/spec/spec.js +++ b/spec/spec.js @@ -259,12 +259,13 @@ describe('parallel', function() { stdout = stdout.replace(/\n\s+/g, ' '); // remove new lines assert(err); assert(!stderr.length); - assert(stdout.indexOf('2 passing') !== -1); + assert(stdout.indexOf('3 passing') !== -1); assert(stdout.indexOf('1 pending') !== -1); assert(stdout.indexOf('1 failing') !== -1); assert(stdout.indexOf('1) suite test1:') !== -1); assert(stdout.indexOf('timeout of 100ms exceeded') !== -1); + done(); }); }); From b6c27f4ef50add5e57a4046327359a2d784dd3c1 Mon Sep 17 00:00:00 2001 From: Arnulfo Solis Date: Tue, 30 Jun 2020 19:37:32 +0200 Subject: [PATCH 4/4] Add titlePath as well --- lib/parallel.js | 3 +++ spec/fixtures/contextProxy.js | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/parallel.js b/lib/parallel.js index bc744f3..0ef9469 100644 --- a/lib/parallel.js +++ b/lib/parallel.js @@ -224,6 +224,9 @@ function patchIt(specs) { var spec = { name: name, title: name, + titlePath: function() { + return this.title; + }, fullTitle: function() { return this.title; }, diff --git a/spec/fixtures/contextProxy.js b/spec/fixtures/contextProxy.js index 192305c..bfe1a00 100644 --- a/spec/fixtures/contextProxy.js +++ b/spec/fixtures/contextProxy.js @@ -28,6 +28,7 @@ parallel('suite', function() { assert.strictEqual('test5', this.spec.title); assert.strictEqual('test5', this.spec.fullTitle()); assert.strictEqual('test5', this.spec.name); + assert.strictEqual('test5', this.spec.titlePath()); done(); }); });