diff --git a/.eslintrc b/.eslintrc index 7c161435..4a8fb4a0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -25,6 +25,11 @@ "named": "never", }], "no-extra-semi": "error", + "no-shadow": ["error", { + "builtinGlobals": false, + "hoist": "functions", + "allow": [] + }], "no-undef": "error", "no-useless-escape": "error", "object-curly-newline": ["error", { diff --git a/bin/tape b/bin/tape index a912c087..027fbb1b 100755 --- a/bin/tape +++ b/bin/tape @@ -47,13 +47,13 @@ if (typeof opts.ignore === 'string') { var files = opts._.reduce(function (result, arg) { // If glob does not match, `files` will be an empty array. // Note: `glob.sync` may throw an error and crash the node process. - var files = glob.sync(arg); + var globFiles = glob.sync(arg); - if (!Array.isArray(files)) { + if (!Array.isArray(globFiles)) { throw new TypeError('unknown error: glob.sync("' + arg + '") did not return an array or throw. Please report this.'); } - return result.concat(files); + return result.concat(globFiles); }, []).filter(function (file) { return !matcher || !matcher.shouldIgnore(file); }).map(function (file) { @@ -75,13 +75,13 @@ function importFiles(hasSupport) { tape.wait(); - var promise = files.reduce(function (promise, file) { + var filesPromise = files.reduce(function (promise, file) { return promise ? promise.then(function () { return importOrRequire(file); }) : importOrRequire(file); }, null); - return promise ? promise.then(function () { tape.run(); }) : tape.run(); + return filesPromise ? filesPromise.then(function () { tape.run(); }) : tape.run(); } // vim: ft=javascript diff --git a/lib/test.js b/lib/test.js index 37a85348..71325f52 100644 --- a/lib/test.js +++ b/lib/test.js @@ -423,7 +423,7 @@ Test.prototype.skip = function skip(msg, extra) { }); }; -function assert(value, msg, extra) { +var testAssert = function assert(value, msg, extra) { this._assert(value, { message: defined(msg, 'should be truthy'), operator: 'ok', @@ -431,11 +431,11 @@ function assert(value, msg, extra) { actual: value, extra: extra }); -} +}; Test.prototype.ok = Test.prototype['true'] = Test.prototype.assert -= assert; += testAssert; function notOK(value, msg, extra) { this._assert(!value, { diff --git a/test/async-await/async5.js b/test/async-await/async5.js index a58930ec..eca3bc4a 100644 --- a/test/async-await/async5.js +++ b/test/async-await/async5.js @@ -33,8 +33,8 @@ test('async5', async function myTest(t) { port: server.address().port, path: '/', method: 'GET' - }, function (res) { - cb(null, res); + }, function (resp) { + cb(null, resp); }); req.end(); })(); diff --git a/test/child_ordering.js b/test/child_ordering.js index c2cb2c29..6c75f587 100644 --- a/test/child_ordering.js +++ b/test/child_ordering.js @@ -5,10 +5,10 @@ var test = require('../'); var childRan = false; test('parent', function (t) { - t.test('child', function (t) { + t.test('child', function (st) { childRan = true; - t.pass('child ran'); - t.end(); + st.pass('child ran'); + st.end(); }); t.end(); }); @@ -24,22 +24,22 @@ var grandChildRan = false; test('grandparent', function (t) { t.ok(!grandParentRan, 'grand parent ran twice'); grandParentRan = true; - t.test('parent', function (t) { - t.ok(!parentRan, 'parent ran twice'); + t.test('parent', function (st) { + st.ok(!parentRan, 'parent ran twice'); parentRan = true; - t.test('grandchild', function (t) { - t.ok(!grandChildRan, 'grand child ran twice'); + st.test('grandchild', function (s2t) { + s2t.ok(!grandChildRan, 'grand child ran twice'); grandChildRan = true; - t.pass('grand child ran'); - t.end(); + s2t.pass('grand child ran'); + s2t.end(); }); - t.pass('parent ran'); - t.end(); + st.pass('parent ran'); + st.end(); }); - 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(); + t.test('other parent', function (st) { + st.ok(parentRan, 'first parent runs before second parent'); + st.ok(grandChildRan, 'grandchild runs before second parent'); + st.end(); }); t.pass('grandparent ran'); t.end(); diff --git a/test/nested2.js b/test/nested2.js index 130b9583..685fd15a 100644 --- a/test/nested2.js +++ b/test/nested2.js @@ -4,17 +4,17 @@ var test = require('../'); test(function (t) { var i = 0; - t.test('setup', function (t) { + t.test('setup', function (st) { process.nextTick(function () { - t.equal(i, 0, 'called once'); + st.equal(i, 0, 'called once'); i++; - t.end(); + st.end(); }); }); - t.test('teardown', function (t) { - t.end(); + t.test('teardown', function (st) { + st.end(); }); t.end(); diff --git a/test/objectMode.js b/test/objectMode.js index 0145a691..fd71d8cc 100644 --- a/test/objectMode.js +++ b/test/objectMode.js @@ -24,21 +24,21 @@ tap.test('object results', function (assert) { assert.equal(objects.length, 13); - forEach(objects, function (obj) { - if (obj.type === 'assert') { + forEach(objects, function (object) { + if (object.type === 'assert') { asserts++; - } else if (obj.type === 'test') { - testIds.push(obj.id); + } else if (object.type === 'test') { + testIds.push(object.id); - if (obj.skip) { + if (object.skip) { skips++; - } else if (obj.todo) { + } else if (object.todo) { todos++; } - } else if (obj.type === 'end') { - endIds.push(obj.text); + } else if (object.type === 'end') { + endIds.push(object.text); // test object should exist - assert.notEqual(testIds.indexOf(obj.test), -1); + assert.notEqual(testIds.indexOf(object.test), -1); } }); diff --git a/test/promises/subTests.js b/test/promises/subTests.js index a4a6b129..bb8d0d9b 100644 --- a/test/promises/subTests.js +++ b/test/promises/subTests.js @@ -4,14 +4,14 @@ var test = require('../../'); if (typeof Promise === 'function' && typeof Promise.resolve === 'function') { test('promise', function (t) { - t.test('sub test that should fail', function (t) { + t.test('sub test that should fail', function () { return new Promise(function (resolve, reject) { reject(new Error('rejection message')); }); }); - t.test('sub test that should pass', function (t) { - t.plan(1); - t.ok(true); + t.test('sub test that should pass', function (st) { + st.plan(1); + st.ok(true); }); }); } else { diff --git a/test/skip.js b/test/skip.js index 6682f048..7a1523de 100644 --- a/test/skip.js +++ b/test/skip.js @@ -44,9 +44,9 @@ test.skip('skip this too', function (t) { test('skip subtest', function (t) { ran++; - t.test('skip this', { skip: true }, function (t) { - t.fail('this should not even run'); - t.end(); + t.test('skip this', { skip: true }, function (st) { + st.fail('this should not even run'); + st.end(); }); t.end(); }); diff --git a/test/subcount.js b/test/subcount.js index 09cb1358..62b94746 100644 --- a/test/subcount.js +++ b/test/subcount.js @@ -4,13 +4,13 @@ var test = require('../'); test('parent test', function (t) { t.plan(2); - t.test('first child', function (t) { - t.plan(1); - t.pass('pass first child'); + t.test('first child', function (st) { + st.plan(1); + st.pass('pass first child'); }); - t.test(function (t) { - t.plan(1); - t.pass('pass second child'); + t.test(function (st) { + st.plan(1); + st.pass('pass second child'); }); }); diff --git a/test/subtest_plan.js b/test/subtest_plan.js index 9bab4730..b3063b96 100644 --- a/test/subtest_plan.js +++ b/test/subtest_plan.js @@ -9,15 +9,15 @@ test('parent', function (t) { t.pass('assertion in parent'); - t.test('first child', function (t) { - t.plan(1); - t.pass('pass first child'); + t.test('first child', function (st) { + st.plan(1); + st.pass('pass first child'); firstChildRan = true; }); - t.test('second child', function (t) { - t.plan(2); - t.ok(firstChildRan, 'first child ran first'); - t.pass('pass second child'); + t.test('second child', function (st) { + st.plan(2); + st.ok(firstChildRan, 'first child ran first'); + st.pass('pass second child'); }); }); diff --git a/test/throws.js b/test/throws.js index c0cb895d..e2a6d609 100644 --- a/test/throws.js +++ b/test/throws.js @@ -8,18 +8,6 @@ var assign = require('object.assign'); var stripFullStack = require('./common').stripFullStack; -function fn() { - throw new TypeError('RegExp'); -} - -function getNonFunctionMessage(fn) { - try { - fn(); - } catch (e) { - return e.message; - } -} - var getter = function () { return 'message'; }; var messageGetterError = Object.defineProperty( { custom: 'error' },