diff --git a/.eslintrc b/.eslintrc index e93835c3..50bbf97e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,5 +2,9 @@ "root": true, "rules": { "indent": ["error", 4], + "space-before-function-paren": [2, { + "anonymous": "always", + "named": "never", + }], }, } diff --git a/bin/tape b/bin/tape index c479c03b..74f4aba5 100755 --- a/bin/tape +++ b/bin/tape @@ -17,7 +17,7 @@ if (typeof opts.require === 'string') { opts.require = [opts.require]; } -opts.require.forEach(function(module) { +opts.require.forEach(function (module) { if (module) { /* This check ensures we ignore `-r ""`, trailing `-r`, or * other silly things the user might (inadvertently) be doing. diff --git a/index.js b/index.js index 48528eb9..2fcc7846 100644 --- a/index.js +++ b/index.js @@ -40,7 +40,7 @@ exports = module.exports = (function () { return getHarness().onFinish.apply(this, arguments); }; - lazyLoad.onFailure = function() { + lazyLoad.onFailure = function () { return getHarness().onFailure.apply(this, arguments); }; @@ -48,7 +48,7 @@ exports = module.exports = (function () { return lazyLoad - function getHarness (opts) { + function getHarness(opts) { if (!opts) opts = {}; opts.autoclose = !canEmitExit; if (!harness) harness = createExitHarness(opts); @@ -56,7 +56,7 @@ exports = module.exports = (function () { } })(); -function createExitHarness (conf) { +function createExitHarness(conf) { if (!conf) conf = {}; var harness = createHarness({ autoclose: defined(conf.autoclose, false) @@ -104,7 +104,7 @@ exports.test.skip = Test.skip; var exitInterval; -function createHarness (conf_) { +function createHarness(conf_) { if (!conf_) conf_ = {}; var results = createResult(); if (conf_.autoclose !== false) { @@ -115,8 +115,8 @@ function createHarness (conf_) { var t = new Test(name, conf, cb); test._tests.push(t); - (function inspectCode (st) { - st.on('test', function sub (st_) { + (function inspectCode(st) { + st.on('test', function sub(st_) { inspectCode(st_); }); st.on('result', function (r) { diff --git a/lib/default_stream.js b/lib/default_stream.js index 8e9f4c76..d1a718a9 100644 --- a/lib/default_stream.js +++ b/lib/default_stream.js @@ -6,7 +6,7 @@ module.exports = function () { var stream = through(write, flush); return stream; - function write (buf) { + function write(buf) { for (var i = 0; i < buf.length; i++) { var c = typeof buf === 'string' ? buf.charAt(i) @@ -17,7 +17,7 @@ module.exports = function () { } } - function flush () { + function flush() { if (fs.writeSync && /^win/.test(process.platform)) { try { fs.writeSync(1, line + '\n'); } catch (e) { stream.emit('error', e) } diff --git a/lib/results.js b/lib/results.js index cfe6c022..b0b011d3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -16,7 +16,7 @@ var nextTick = typeof setImmediate !== 'undefined' module.exports = Results; inherits(Results, EventEmitter); -function Results () { +function Results() { if (!(this instanceof Results)) return new Results; this.count = 0; this.fail = 0; @@ -34,7 +34,7 @@ Results.prototype.createStream = function (opts) { var output, testId = 0; if (opts.objectMode) { output = through(); - self.on('_push', function ontest (t, extra) { + self.on('_push', function ontest(t, extra) { if (!extra) extra = {}; var id = testId++; t.once('prerun', function () { @@ -73,7 +73,7 @@ Results.prototype.createStream = function (opts) { var t; while (t = getNextTest(self)) { t.run(); - if (!t.ended) return t.once('end', function(){ nextTick(next); }); + if (!t.ended) return t.once('end', function () { nextTick(next); }); } self.emit('done'); }); @@ -134,7 +134,7 @@ Results.prototype.close = function () { self._stream.queue(null); }; -function encodeResult (res, count) { +function encodeResult(res, count) { var output = ''; output += (res.ok ? 'ok ' : 'not ok ') + count; output += res.name ? ' ' + res.name.toString().replace(/\s+/g, ' ') : ''; @@ -181,7 +181,7 @@ function encodeResult (res, count) { return output; } -function getNextTest (results) { +function getNextTest(results) { if (!results._only) { return results.tests.shift(); } @@ -195,6 +195,6 @@ function getNextTest (results) { } while (results.tests.length !== 0) } -function invalidYaml (str) { +function invalidYaml(str) { return regexpTest(yamlIndicators, str); } diff --git a/lib/test.js b/lib/test.js index 50b95c42..e58e33d7 100644 --- a/lib/test.js +++ b/lib/test.js @@ -39,7 +39,7 @@ var getTestArgs = function (name_, opts_, cb_) { return { name: name, opts: opts, cb: cb }; }; -function Test (name_, opts_, cb_) { +function Test(name_, opts_, cb_) { if (! (this instanceof Test)) { return new Test(name_, opts_, cb_); } @@ -113,7 +113,7 @@ Test.prototype.test = function (name, opts, cb) { }); } - nextTick(function() { + nextTick(function () { if (!self._plan && self.pendingCount == self._progeny.length) { self._end(); } @@ -132,14 +132,14 @@ Test.prototype.plan = function (n) { this.emit('plan', n); }; -Test.prototype.timeoutAfter = function(ms) { +Test.prototype.timeoutAfter = function (ms) { if (!ms) throw new Error('timeoutAfter requires a timespan'); var self = this; - var timeout = safeSetTimeout(function() { + var timeout = safeSetTimeout(function () { self.fail('test timed out after ' + ms + 'ms'); self.end(); }, ms); - this.once('end', function() { + this.once('end', function () { safeClearTimeout(timeout); }); } @@ -201,7 +201,7 @@ Test.prototype._pendingAsserts = function () { return this._plan - (this._progeny.length + this.assertCount); }; -Test.prototype._assert = function assert (ok, opts) { +Test.prototype._assert = function assert(ok, opts) { var self = this; var extra = opts.extra || {}; diff --git a/test/anonymous-fn/test-wrapper.js b/test/anonymous-fn/test-wrapper.js index 9702c9f1..bdf9dedc 100644 --- a/test/anonymous-fn/test-wrapper.js +++ b/test/anonymous-fn/test-wrapper.js @@ -1,6 +1,6 @@ // Example of wrapper function that would invoke tape module.exports = function (testCase) { - return function(t) { + return function (t) { setUp(); testCase(t); tearDown(); diff --git a/test/child_ordering.js b/test/child_ordering.js index 12efafe9..08d3c760 100644 --- a/test/child_ordering.js +++ b/test/child_ordering.js @@ -2,8 +2,8 @@ var test = require('../'); var childRan = false; -test('parent', function(t) { - t.test('child', function(t) { +test('parent', function (t) { + t.test('child', function (t) { childRan = true; t.pass('child ran'); t.end(); @@ -11,7 +11,7 @@ test('parent', function(t) { t.end(); }); -test('uncle', function(t) { +test('uncle', function (t) { t.ok(childRan, 'Child should run before next top-level test'); t.end(); }); @@ -19,13 +19,13 @@ test('uncle', function(t) { var grandParentRan = false; var parentRan = false; var grandChildRan = false; -test('grandparent', function(t) { +test('grandparent', function (t) { t.ok(!grandParentRan, 'grand parent ran twice'); grandParentRan = true; - t.test('parent', function(t) { + t.test('parent', function (t) { t.ok(!parentRan, 'parent ran twice'); parentRan = true; - t.test('grandchild', function(t) { + t.test('grandchild', function (t) { t.ok(!grandChildRan, 'grand child ran twice'); grandChildRan = true; t.pass('grand child ran'); @@ -34,7 +34,7 @@ test('grandparent', function(t) { t.pass('parent ran'); t.end(); }); - t.test('other parent', function(t) { + t.test('other parent', function (t) { t.ok(parentRan, 'first parent runs before second parent'); t.ok(grandChildRan, 'grandchild runs before second parent'); t.end(); @@ -43,7 +43,7 @@ test('grandparent', function(t) { t.end(); }); -test('second grandparent', function(t) { +test('second grandparent', function (t) { t.ok(grandParentRan, 'grandparent ran'); t.ok(parentRan, 'parent ran'); t.ok(grandChildRan, 'grandchild ran'); diff --git a/test/create_multiple_streams.js b/test/create_multiple_streams.js index 4b87d044..befcbdaa 100644 --- a/test/create_multiple_streams.js +++ b/test/create_multiple_streams.js @@ -1,6 +1,6 @@ var tape = require('../'); -tape.test('createMultipleStreams', function(tt) { +tape.test('createMultipleStreams', function (tt) { tt.plan(2); var th = tape.createHarness(); @@ -11,7 +11,7 @@ tape.test('createMultipleStreams', function(tt) { th('test one', function (tht) { tht.plan(1); - setTimeout( function() { + setTimeout( function () { tht.pass(); testOneComplete = true; }, 100); @@ -22,7 +22,7 @@ tape.test('createMultipleStreams', function(tt) { tht.end(); }); - th.onFinish(function() { + th.onFinish(function () { tt.equal(th._results.count, 2, "harness test ran"); tt.equal(th._results.fail, 0, "harness test didn't fail"); }); diff --git a/test/nested-async-plan-noend.js b/test/nested-async-plan-noend.js index 69f43b9d..1acc1416 100644 --- a/test/nested-async-plan-noend.js +++ b/test/nested-async-plan-noend.js @@ -1,33 +1,33 @@ var test = require('../'); -test('Harness async test support', function(t) { +test('Harness async test support', function (t) { t.plan(3); t.ok(true, 'sync child A'); - t.test('sync child B', function(tt) { + t.test('sync child B', function (tt) { tt.plan(2); - setTimeout(function(){ - tt.test('async grandchild A', function(ttt) { + setTimeout(function () { + tt.test('async grandchild A', function (ttt) { ttt.plan(1); ttt.ok(true); }); }, 50); - setTimeout(function() { - tt.test('async grandchild B', function(ttt) { + setTimeout(function () { + tt.test('async grandchild B', function (ttt) { ttt.plan(1); ttt.ok(true); }); }, 100); }); - setTimeout(function() { - t.test('async child', function(tt) { + setTimeout(function () { + t.test('async child', function (tt) { tt.plan(2); tt.ok(true, 'sync grandchild in async child A'); - tt.test('sync grandchild in async child B', function(ttt) { + tt.test('sync grandchild in async child B', function (ttt) { ttt.plan(1); ttt.ok(true); }); diff --git a/test/nested-sync-noplan-noend.js b/test/nested-sync-noplan-noend.js index 42735a80..8dba7ad3 100644 --- a/test/nested-sync-noplan-noend.js +++ b/test/nested-sync-noplan-noend.js @@ -25,14 +25,14 @@ tap.test('nested sync test without plan or end', function (tt) { test.createStream().pipe(concat(tc)); - test('nested without plan or end', function(t) { - t.test('first', function(q) { + test('nested without plan or end', function (t) { + t.test('first', function (q) { setTimeout(function first() { q.ok(true); q.end() }, 10); }); - t.test('second', function(q) { + t.test('second', function (q) { setTimeout(function second() { q.ok(true); q.end() diff --git a/test/nested2.js b/test/nested2.js index 58ae8f3d..fc02c4a7 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -1,9 +1,9 @@ var test = require('../'); -test(function(t) { +test(function (t) { var i = 0 - t.test('setup', function(t) { - process.nextTick(function() { + t.test('setup', function (t) { + process.nextTick(function () { t.equal(i, 0, 'called once') i++ t.end() @@ -11,7 +11,7 @@ test(function(t) { }) - t.test('teardown', function(t) { + t.test('teardown', function (t) { t.end() }) diff --git a/test/onFailure.js b/test/onFailure.js index e8efdbdb..f744f75f 100644 --- a/test/onFailure.js +++ b/test/onFailure.js @@ -3,19 +3,19 @@ var tape = require("../").createHarness(); //Because this test passing depends on a failure, //we must direct the failing output of the inner test -var noop = function(){} +var noop = function () {} var mockSink = {on:noop, removeListener:noop, emit:noop, end:noop} tape.createStream().pipe(mockSink); -tap.test("on failure", { timeout: 1000 }, function(tt) { +tap.test("on failure", { timeout: 1000 }, function (tt) { tt.plan(1); - tape("dummy test", function(t) { + tape("dummy test", function (t) { t.fail(); t.end(); }); - tape.onFailure(function() { + tape.onFailure(function () { tt.pass("tape ended"); }); }); diff --git a/test/onFinish.js b/test/onFinish.js index 5b77fae2..80ccf051 100644 --- a/test/onFinish.js +++ b/test/onFinish.js @@ -3,10 +3,10 @@ var tape = require("../"); tap.test("on finish", {timeout: 1000}, function (tt) { tt.plan(1); - tape.onFinish(function() { + tape.onFinish(function () { tt.pass('tape ended'); }); - tape('dummy test', function(t) { + tape('dummy test', function (t) { t.end(); }); }); diff --git a/test/only-twice.js b/test/only-twice.js index 488e49ba..2a7dbd05 100644 --- a/test/only-twice.js +++ b/test/only-twice.js @@ -8,8 +8,8 @@ tap.test('only twice error', function (assert) { t.end() }); - assert.throws(function() { - test.only('second only', function(t) { + assert.throws(function () { + test.only('second only', function (t) { t.end(); }); }, { diff --git a/test/plan_optional.js b/test/plan_optional.js index a092eab2..680dbcbb 100644 --- a/test/plan_optional.js +++ b/test/plan_optional.js @@ -6,7 +6,7 @@ test('plan should be optional', function (t) { }); test('no plan async', function (t) { - setTimeout(function() { + setTimeout(function () { t.pass('ok'); t.end(); }, 100); diff --git a/test/require/a.js b/test/require/a.js index 097eb883..8419fb71 100644 --- a/test/require/a.js +++ b/test/require/a.js @@ -1,6 +1,6 @@ var tape = require('../..'); -tape.test('module-a', function(t) { +tape.test('module-a', function (t) { t.plan(1) t.pass('loaded module a') }) diff --git a/test/require/b.js b/test/require/b.js index 2f10a0ec..a1b6393c 100644 --- a/test/require/b.js +++ b/test/require/b.js @@ -1,6 +1,6 @@ var tape = require('../..'); -tape.test('module-b', function(t) { +tape.test('module-b', function (t) { t.plan(1) t.pass('loaded module b') }) diff --git a/test/require/test-a.js b/test/require/test-a.js index 769e40cd..d62dacfa 100644 --- a/test/require/test-a.js +++ b/test/require/test-a.js @@ -1,6 +1,6 @@ var tape = require('../..'); -tape.test('test-a', function(t) { +tape.test('test-a', function (t) { t.ok(global.module_a, 'module-a loaded in same context') t.pass('test ran after module-a was loaded') t.end() diff --git a/test/require/test-b.js b/test/require/test-b.js index 4eb3b681..447c230c 100644 --- a/test/require/test-b.js +++ b/test/require/test-b.js @@ -1,6 +1,6 @@ var tape = require('../..'); -tape.test('test-b', function(t) { +tape.test('test-b', function (t) { t.ok(global.module_b, 'module-b loaded in same context') t.pass('test ran after module-b was loaded') t.end() diff --git a/test/skip.js b/test/skip.js index c3bf8d9e..234c75a9 100644 --- a/test/skip.js +++ b/test/skip.js @@ -28,21 +28,21 @@ tap.test('test SKIP comment', function (assert) { }); }); -test('skip this', { skip: true }, function(t) { +test('skip this', { skip: true }, function (t) { t.fail('this should not even run'); ran++; t.end(); }); -test.skip('skip this too', function(t) { +test.skip('skip this too', function (t) { t.fail('this should not even run'); ran++; t.end(); }); -test('skip subtest', function(t) { +test('skip subtest', function (t) { ran++; - t.test('skip this', { skip: true }, function(t) { + t.test('skip this', { skip: true }, function (t) { t.fail('this should not even run'); t.end(); }); diff --git a/test/stackTrace.js b/test/stackTrace.js index 8da3b529..02bbb243 100644 --- a/test/stackTrace.js +++ b/test/stackTrace.js @@ -234,7 +234,7 @@ tap.test('preserves stack trace for failed assertions where actual===falsy', fun }); }); -function getDiag (body) { +function getDiag(body) { var yamlStart = body.indexOf(' ---'); var yamlEnd = body.indexOf(' ...\n'); var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { @@ -248,6 +248,6 @@ function getDiag (body) { return withStack; } -function stripAt (body) { +function stripAt(body) { return body.replace(/^\s*at:\s+Test.*$\n/m, ''); } diff --git a/test/timeout.js b/test/timeout.js index 9f4cd825..b74b11a1 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -1,7 +1,7 @@ var test = require('../'); var ran = 0; -test('timeout', function(t) { +test('timeout', function (t) { t.pass('this should run'); ran++; setTimeout(function () { @@ -9,7 +9,7 @@ test('timeout', function(t) { }, 100); }); -test('should still run', { timeout: 50 }, function(t) { +test('should still run', { timeout: 50 }, function (t) { t.equal(ran, 1); t.end(); });