Skip to content

Commit

Permalink
[Refactor] consistent spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 13, 2019
1 parent b74c4fd commit 34ebb4c
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 70 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"root": true,
"rules": {
"indent": ["error", 4],
"space-before-function-paren": [2, {
"anonymous": "always",
"named": "never",
}],
},
}
2 changes: 1 addition & 1 deletion bin/tape
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ exports = module.exports = (function () {
return getHarness().onFinish.apply(this, arguments);
};

lazyLoad.onFailure = function() {
lazyLoad.onFailure = function () {
return getHarness().onFailure.apply(this, arguments);
};

lazyLoad.getHarness = getHarness

return lazyLoad

function getHarness (opts) {
function getHarness(opts) {
if (!opts) opts = {};
opts.autoclose = !canEmitExit;
if (!harness) harness = createExitHarness(opts);
return harness;
}
})();

function createExitHarness (conf) {
function createExitHarness(conf) {
if (!conf) conf = {};
var harness = createHarness({
autoclose: defined(conf.autoclose, false)
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/default_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) }
Expand Down
12 changes: 6 additions & 6 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 () {
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -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, ' ') : '';
Expand Down Expand Up @@ -181,7 +181,7 @@ function encodeResult (res, count) {
return output;
}

function getNextTest (results) {
function getNextTest(results) {
if (!results._only) {
return results.tests.shift();
}
Expand All @@ -195,6 +195,6 @@ function getNextTest (results) {
} while (results.tests.length !== 0)
}

function invalidYaml (str) {
function invalidYaml(str) {
return regexpTest(yamlIndicators, str);
}
12 changes: 6 additions & 6 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
});
}
Expand Down Expand Up @@ -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 || {};

Expand Down
2 changes: 1 addition & 1 deletion test/anonymous-fn/test-wrapper.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
16 changes: 8 additions & 8 deletions test/child_ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ 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();
});
t.end();
});

test('uncle', function(t) {
test('uncle', function (t) {
t.ok(childRan, 'Child should run before next top-level test');
t.end();
});

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');
Expand All @@ -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();
Expand All @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions test/create_multiple_streams.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var tape = require('../');

tape.test('createMultipleStreams', function(tt) {
tape.test('createMultipleStreams', function (tt) {
tt.plan(2);

var th = tape.createHarness();
Expand All @@ -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);
Expand All @@ -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");
});
Expand Down
18 changes: 9 additions & 9 deletions test/nested-async-plan-noend.js
Original file line number Diff line number Diff line change
@@ -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);
});
Expand Down
6 changes: 3 additions & 3 deletions test/nested-sync-noplan-noend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions test/nested2.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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()
})
})


t.test('teardown', function(t) {
t.test('teardown', function (t) {
t.end()
})

Expand Down
8 changes: 4 additions & 4 deletions test/onFailure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
4 changes: 2 additions & 2 deletions test/onFinish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading

0 comments on commit 34ebb4c

Please sign in to comment.