Browse Source

fix lint issues with latest XO

failure-output
Sindre Sorhus 8 years ago
parent
commit
c9259200c7
  1. 6
      api.js
  2. 19
      bench/run.js
  3. 4
      cli.js
  4. 2
      index.js
  5. 7
      lib/assert.js
  6. 1
      lib/caching-precompiler.js
  7. 12
      lib/enhance-assert.js
  8. 2
      lib/logger.js
  9. 8
      lib/test-worker.js
  10. 14
      lib/test.js
  11. 4
      lib/throws-helper.js
  12. 5
      package.json
  13. 7
      profile.js
  14. 46
      test/assert.js
  15. 3
      test/ava-files.js
  16. 1
      test/cli.js
  17. 353
      test/concurrent.js
  18. 1
      test/fork.js
  19. 1
      test/hooks.js
  20. 4
      test/profile.js
  21. 5
      test/reporters/mini.js
  22. 5
      test/reporters/verbose.js
  23. 30
      test/runner.js
  24. 352
      test/sequence.js
  25. 45
      test/test-collection.js
  26. 42
      test/test.js
  27. 2
      test/visual/print-lorem-ipsum.js
  28. 1
      test/visual/run-visual-tests.js
  29. 112
      test/watcher.js

6
api.js

@ -109,8 +109,10 @@ Api.prototype._run = function (files, _options) {
}
var cacheEnabled = self.options.cacheEnabled !== false;
var cacheDir = (cacheEnabled && findCacheDir({name: 'ava', files: files})) ||
uniqueTempDir();
var cacheDir = (cacheEnabled && findCacheDir({
name: 'ava',
files: files
})) || uniqueTempDir();
self.options.cacheDir = cacheDir;
self.precompiler = new CachingPrecompiler(cacheDir, self.options.babelConfig);

19
bench/run.js

@ -1,5 +1,4 @@
'use strict';
var childProcess = require('child_process');
var path = require('path');
var fs = require('fs');
@ -7,6 +6,7 @@ var arrify = require('arrify');
var Promise = require('bluebird');
var mkdirp = require('mkdirp');
var branch = require('git-branch').sync(path.join(__dirname, '..'));
var cliPath = require.resolve('../cli');
function runTests(_args) {
@ -34,7 +34,10 @@ var list;
if (process.argv.length === 2) {
list = [
{args: 'other/failures.js', shouldFail: true},
{
args: 'other/failures.js',
shouldFail: true
},
'serial/alternating-sync-async.js',
'serial/async-immediate.js',
'serial/async-timeout.js',
@ -94,22 +97,32 @@ var results = {};
Promise.each(combined, function (definition) {
var args = definition.args;
return runTests(args).then(function (result) {
var key = result.args.join(' ');
var passedOrFaild = result.err ? 'failed' : 'passed';
var seconds = result.time / 1000;
console.log('%s %s in %d seconds', key, passedOrFaild, seconds);
if (result.err && !definition.shouldFail) {
console.log(result.stdout);
console.log(result.stderr);
throw result.err;
}
results[key] = results[key] || [];
results[key].push({passed: !results.err, shouldFail: definition.shouldFail, time: seconds});
results[key].push({
passed: !results.err,
shouldFail: definition.shouldFail,
time: seconds
});
});
}).then(function () {
mkdirp.sync(path.join(__dirname, '.results'));
results['.time'] = Date.now();
fs.writeFileSync(
path.join(__dirname, '.results', branch + '.json'),
JSON.stringify(results, null, 4)

4
cli.js

@ -121,8 +121,8 @@ if (cli.flags.init) {
}
if (
(hasFlag('--watch') || hasFlag('-w')) && (hasFlag('--tap') || hasFlag('-t')) ||
conf.watch && conf.tap
((hasFlag('--watch') || hasFlag('-w')) && (hasFlag('--tap') || hasFlag('-t'))) ||
(conf.watch && conf.tap)
) {
console.error(' ' + colors.error(figures.cross) + ' The TAP reporter is not available when using watch mode.');
process.exit(1);

2
index.js

@ -22,7 +22,7 @@ if (!isForked) {
console.log();
console.error('Test files must be run with the AVA CLI:\n\n ' + chalk.grey.dim('$') + ' ' + chalk.cyan('ava ' + fp) + '\n');
process.exit(1); // eslint-disable-line
process.exit(1); // eslint-disable-line xo/no-process-exit
}
// note that test files have require('ava')

7
lib/assert.js

@ -5,6 +5,7 @@ var deepEqual = require('not-so-shallow');
var observableToPromise = require('observable-to-promise');
var isObservable = require('is-observable');
var isPromise = require('is-promise');
var x = module.exports;
Object.defineProperty(x, 'AssertionError', {value: assert.AssertionError});
@ -101,9 +102,9 @@ x.throws = function (fn, err, msg) {
assert.throws(function () {
try {
fn();
} catch (error) {
result = error;
throw error;
} catch (err) {
result = err;
throw err;
}
}, err, msg);

1
lib/caching-precompiler.js

@ -54,6 +54,7 @@ CachingPrecompiler.prototype._init = function () {
var transformRuntime = require('babel-plugin-transform-runtime');
var throwsHelper = require('babel-plugin-ava-throws-helper');
var rewriteBabelPaths = this._createRewritePlugin();
var powerAssert = this._createEspowerPlugin();

12
lib/enhance-assert.js

@ -31,6 +31,7 @@ module.exports.NON_ENHANCED_PATTERNS = [
function enhanceAssert(opts) {
var empower = require('empower-core');
var enhanced = empower(
opts.assert,
{
@ -53,8 +54,15 @@ function formatter() {
return createFormatter({
renderers: [
{ctor: AssertionRenderer},
{ctor: SuccinctRenderer, options: {maxDepth: 3}}
{
ctor: AssertionRenderer
},
{
ctor: SuccinctRenderer,
options: {
maxDepth: 3
}
}
]
});
}

2
lib/logger.js

@ -99,6 +99,6 @@ Logger.prototype.exit = function (code) {
// timeout required to correctly flush IO on Node.js 0.10 on Windows
setTimeout(function () {
process.exit(code); // eslint-disable-line
process.exit(code); // eslint-disable-line xo/no-process-exit
}, process.env.AVA_APPVEYOR ? 500 : 0);
};

8
lib/test-worker.js

@ -38,7 +38,7 @@ if (debug.enabled) {
// bind globals first before anything has a chance to interfere
var globals = require('./globals');
globals.options = opts;
var Promise = require('bluebird'); // eslint-disable-line
var Promise = require('bluebird'); // eslint-disable-line import/order
// Bluebird specific
Promise.longStackTraces();
@ -60,11 +60,11 @@ sourceMapSupport.install({
}
});
var currentlyUnhandled = require('currently-unhandled')(); // eslint-disable-line
var currentlyUnhandled = require('currently-unhandled')(); // eslint-disable-line import/order
var serializeError = require('./serialize-error');
var send = require('./send');
var throwsHelper = require('./throws-helper');
var installPrecompiler = require('require-precompiled'); // eslint-disable-line
var installPrecompiler = require('require-precompiled'); // eslint-disable-line import/order
var cacheDir = opts.cacheDir;
// check if test files required ava and show error, when they didn't
@ -120,7 +120,7 @@ process.on('ava-exit', function () {
var delay = process.env.AVA_APPVEYOR ? 100 : 0;
globals.setTimeout(function () {
process.exit(0); // eslint-disable-line
process.exit(0); // eslint-disable-line xo/no-process-exit
}, delay);
});

14
lib/test.js

@ -118,7 +118,7 @@ Test.prototype.promise = function () {
if (!this._promise) {
this._promise = {};
this._promise.promise = new Promise(function (resolve, reject) { // eslint-disable-line
this._promise.promise = new Promise(function (resolve, reject) { // eslint-disable-line no-use-extend-native/no-use-extend-native
self._promise.resolve = resolve;
self._promise.reject = reject;
}).tap(function (result) {
@ -189,15 +189,22 @@ Test.prototype.run = function () {
Test.prototype._result = function () {
var reason = this.assertError;
var passed = reason === undefined;
if (this.metadata.failing) {
passed = !passed;
if (passed) {
reason = undefined;
} else {
reason = new Error('Test was expected to fail, but succeeded, you should stop marking the test as failing');
}
}
return {passed: passed, result: this, reason: reason};
return {
passed: passed,
result: this,
reason: reason
};
};
Object.defineProperty(Test.prototype, 'end', {
@ -219,9 +226,10 @@ Test.prototype._end = function (err) {
operator: 'callback'
});
}
this._setAssertError(err);
this._setAssertError(err);
this.exit();
return;
}

4
lib/throws-helper.js

@ -16,8 +16,8 @@ module.exports = function throwsHelper(error) {
try {
var rawLines = fs.readFileSync(data.filename, 'utf8');
frame = codeFrame(rawLines, data.line, data.column, {highlightCode: true});
} catch (e) {
console.warn(e);
} catch (err) {
console.warn(err);
}
console.error(

5
package.json

@ -176,5 +176,10 @@
},
"optionalDependencies": {
"chokidar": "^1.4.2"
},
"xo": {
"rules": {
"import/newline-after-import": 0
}
}
}

7
profile.js

@ -60,7 +60,10 @@ if (cli.input.length !== 1) {
}
var file = path.resolve(cli.input[0]);
var cacheDir = findCacheDir({name: 'ava', files: [file]}) || uniqueTempDir();
var cacheDir = findCacheDir({
name: 'ava',
files: [file]
}) || uniqueTempDir();
var precompiled = {};
precompiled[file] = new CachingPrecompiler(cacheDir, conf.babel).precompileFile(file);
@ -107,7 +110,7 @@ events.on('results', function (data) {
if (process.exit) {
// Delay is For Node 0.10 which emits uncaughtExceptions async.
setTimeout(function () {
process.exit(data.stats.failCount + uncaughtExceptionCount); // eslint-disable-line
process.exit(data.stats.failCount + uncaughtExceptionCount); // eslint-disable-line xo/no-process-exit
}, 20);
}
});

46
test/assert.js

@ -128,11 +128,29 @@ test('.deepEqual()', function (t) {
});
t.doesNotThrow(function () {
assert.deepEqual({a: 'a', b: 'b'}, {b: 'b', a: 'a'});
assert.deepEqual({
a: 'a',
b: 'b'
}, {
b: 'b',
a: 'a'
});
});
t.doesNotThrow(function () {
assert.deepEqual({a: 'a', b: 'b', c: {d: 'd'}}, {c: {d: 'd'}, b: 'b', a: 'a'});
assert.deepEqual({
a: 'a',
b: 'b',
c: {
d: 'd'
}
}, {
c: {
d: 'd'
},
b: 'b',
a: 'a'
});
});
t.throws(function () {
@ -197,7 +215,19 @@ test('.deepEqual()', function (t) {
});
t.throws(function () {
assert.deepEqual({a: 'a', b: 'b', c: {d: false}}, {c: {d: 0}, b: 'b', a: 'a'});
assert.deepEqual({
a: 'a',
b: 'b',
c: {
d: false
}
}, {
c: {
d: 0
},
b: 'b',
a: 'a'
});
});
// Regression test end here
@ -290,7 +320,10 @@ test('.throws should throw if passed a bad value', function (t) {
t.throws(function () {
assert.throws('not a function');
}, {name: 'TypeError', message: /t\.throws must be called with a function, Promise, or Observable/});
}, {
name: 'TypeError',
message: /t\.throws must be called with a function, Promise, or Observable/
});
});
test('.notThrows should throw if passed a bad value', function (t) {
@ -298,7 +331,10 @@ test('.notThrows should throw if passed a bad value', function (t) {
t.throws(function () {
assert.notThrows('not a function');
}, {name: 'TypeError', message: /t\.notThrows must be called with a function, Promise, or Observable/});
}, {
name: 'TypeError',
message: /t\.notThrows must be called with a function, Promise, or Observable/
});
});
test('.notThrows()', function (t) {

3
test/ava-files.js

@ -1,9 +1,10 @@
'use strict';
var path = require('path');
var tap = require('tap');
var test = tap.test;
var AvaFiles = require('../lib/ava-files');
var test = tap.test;
tap.afterEach(function (done) {
// We changed the CWD in some of the tests.
process.chdir(path.join(__dirname, '..'));

1
test/cli.js

@ -8,6 +8,7 @@ var figures = require('figures');
var arrify = require('arrify');
var chalk = require('chalk');
var touch = require('touch');
var cliPath = path.join(__dirname, '../cli.js');
// for some reason chalk is disabled by default

353
test/concurrent.js

@ -69,9 +69,18 @@ test('all sync - all pass - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -91,9 +100,18 @@ test('all sync - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -113,9 +131,18 @@ test('all sync - begin failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -135,9 +162,18 @@ test('all sync - mid failure - no bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -157,9 +193,18 @@ test('all sync - end failure - no bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -179,9 +224,18 @@ test('all sync - multiple failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -201,7 +255,10 @@ test('all sync - begin failure - bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'}
{
passed: false,
reason: 'a'
}
]
});
t.end();
@ -221,8 +278,14 @@ test('all sync - mid failure - bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
}
]
});
t.end();
@ -242,9 +305,18 @@ test('all sync - end failure - bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -263,9 +335,18 @@ test('all async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -285,9 +366,18 @@ test('all async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -307,9 +397,18 @@ test('last async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -329,9 +428,18 @@ test('mid async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -351,9 +459,18 @@ test('first async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -373,9 +490,18 @@ test('last async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -395,9 +521,18 @@ test('mid async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -417,9 +552,18 @@ test('first async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -439,7 +583,10 @@ test('all async - begin failure - bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'}
{
passed: false,
reason: 'a'
}
]
});
t.end();
@ -459,8 +606,14 @@ test('all async - mid failure - bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
}
]
});
t.end();
@ -480,9 +633,18 @@ test('all async - end failure - bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -502,9 +664,18 @@ test('all async - begin failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -524,9 +695,18 @@ test('all async - mid failure - no bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -546,9 +726,18 @@ test('all async - end failure - no bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -568,9 +757,18 @@ test('all async - multiple failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -585,8 +783,8 @@ test('rejections are just passed through - no bail', function (t) {
reject('foo')
],
false
).run().catch(function (reason) {
t.is(reason, 'foo');
).run().catch(function (err) {
t.is(err, 'foo');
t.end();
});
});
@ -599,8 +797,8 @@ test('rejections are just passed through - bail', function (t) {
reject('foo')
],
true
).run().catch(function (reason) {
t.is(reason, 'foo');
).run().catch(function (err) {
t.is(err, 'foo');
t.end();
});
});
@ -627,15 +825,24 @@ test('sequences of sequences', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
}
]
},
{
passed: true,
reason: null,
result: [
{passed: true, result: 'c'}
{
passed: true,
result: 'c'
}
]
}
]

1
test/fork.js

@ -3,6 +3,7 @@ var path = require('path');
var test = require('tap').test;
var _fork = require('../lib/fork.js');
var CachingPrecompiler = require('../lib/caching-precompiler');
var cacheDir = path.join(__dirname, '../node_modules/.cache/ava');
var precompiler = new CachingPrecompiler(cacheDir);

1
test/hooks.js

@ -4,6 +4,7 @@ var test = require('tap').test;
var Runner = require('../lib/runner');
var _fork = require('../lib/fork.js');
var CachingPrecompiler = require('../lib/caching-precompiler');
var cacheDir = path.join(__dirname, '../node_modules/.cache/ava');
var precompiler = new CachingPrecompiler(cacheDir);

4
test/profile.js

@ -22,8 +22,8 @@ function run(files) {
test('exits normally when tests pass', function (t) {
t.plan(1);
run('es2015')
.catch(function (e) {
t.fail(e);
.catch(function (err) {
t.fail(err);
})
.then(function () {
t.pass();

5
test/reporters/mini.js

@ -213,7 +213,10 @@ test('results with passing known failure tests', function (t) {
reporter.failCount = 0;
var runStatus = {
knownFailures: [{title: 'known failure', failing: true}]
knownFailures: [{
title: 'known failure',
failing: true
}]
};
var actualOutput = reporter.finish(runStatus);
var expectedOutput = [

5
test/reporters/verbose.js

@ -233,7 +233,10 @@ test('results with passing known failure tests', function (t) {
var runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.knownFailureCount = 1;
runStatus.knownFailures = [{title: 'known failure', failing: true}];
runStatus.knownFailures = [{
title: 'known failure',
failing: true
}];
var actualOutput = reporter.finish(runStatus);
var expectedOutput = [

30
test/runner.js

@ -160,11 +160,26 @@ test('test types and titles', function (t) {
runner.test('test', fn);
var tests = [
{type: 'before', title: 'named'},
{type: 'beforeEach', title: 'beforeEach for test'},
{type: 'test', title: 'test'},
{type: 'afterEach', title: 'named for test'},
{type: 'after', title: 'after'}
{
type: 'before',
title: 'named'
},
{
type: 'beforeEach',
title: 'beforeEach for test'
},
{
type: 'test',
title: 'test'
},
{
type: 'afterEach',
title: 'named for test'
},
{
type: 'after',
title: 'after'
}
];
runner.on('test', function (props) {
@ -364,7 +379,10 @@ test('options.bail will bail out (async)', function (t) {
test('options.bail + serial - tests will never happen (async)', function (t) {
t.plan(2);
var runner = new Runner({bail: true, serial: true});
var runner = new Runner({
bail: true,
serial: true
});
var tests = [];
runner.cb(function (a) {

352
test/sequence.js

@ -69,9 +69,18 @@ test('all sync - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -91,9 +100,18 @@ test('all sync - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -113,9 +131,18 @@ test('all sync - begin failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -135,9 +162,17 @@ test('all sync - mid failure - no bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'},
{
passed: false,
reason: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -157,9 +192,18 @@ test('all sync - end failure - no bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -179,9 +223,18 @@ test('all sync - multiple failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -201,7 +254,10 @@ test('all sync - begin failure - bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'}
{
passed: false,
reason: 'a'
}
]
});
t.end();
@ -221,8 +277,14 @@ test('all sync - mid failure - bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
}
]
});
t.end();
@ -242,9 +304,18 @@ test('all sync - end failure - bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -263,9 +334,18 @@ test('all async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -285,9 +365,18 @@ test('all async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -307,9 +396,18 @@ test('last async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -329,9 +427,18 @@ test('mid async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -351,9 +458,18 @@ test('first async - no failure - no bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -373,9 +489,18 @@ test('last async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -395,9 +520,18 @@ test('mid async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -417,9 +551,18 @@ test('first async - no failure - bail', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -439,7 +582,10 @@ test('all async - begin failure - bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'}
{
passed: false,
reason: 'a'
}
]
});
t.end();
@ -459,8 +605,14 @@ test('all async - mid failure - bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
}
]
});
t.end();
@ -480,9 +632,18 @@ test('all async - end failure - bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -502,9 +663,18 @@ test('all async - begin failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: true, result: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -524,9 +694,18 @@ test('all async - mid failure - no bail', function (t) {
passed: false,
reason: 'b',
result: [
{passed: true, result: 'a'},
{passed: false, reason: 'b'},
{passed: true, result: 'c'}
{
passed: true,
result: 'a'
},
{
passed: false,
reason: 'b'
},
{
passed: true,
result: 'c'
}
]
});
t.end();
@ -546,9 +725,18 @@ test('all async - end failure - no bail', function (t) {
passed: false,
reason: 'c',
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -568,9 +756,18 @@ test('all async - multiple failure - no bail', function (t) {
passed: false,
reason: 'a',
result: [
{passed: false, reason: 'a'},
{passed: true, result: 'b'},
{passed: false, reason: 'c'}
{
passed: false,
reason: 'a'
},
{
passed: true,
result: 'b'
},
{
passed: false,
reason: 'c'
}
]
});
t.end();
@ -585,8 +782,8 @@ test('rejections are just passed through - no bail', function (t) {
reject('foo')
],
false
).run().catch(function (reason) {
t.is(reason, 'foo');
).run().catch(function (err) {
t.is(err, 'foo');
t.end();
});
});
@ -599,8 +796,8 @@ test('rejections are just passed through - bail', function (t) {
reject('foo')
],
true
).run().catch(function (reason) {
t.is(reason, 'foo');
).run().catch(function (err) {
t.is(err, 'foo');
t.end();
});
});
@ -634,15 +831,24 @@ test('sequences of sequences', function (t) {
passed: true,
reason: null,
result: [
{passed: true, result: 'a'},
{passed: true, result: 'b'}
{
passed: true,
result: 'a'
},
{
passed: true,
result: 'b'
}
]
},
{
passed: true,
reason: null,
result: [
{passed: true, result: 'c'}
{
passed: true,
result: 'c'
}
]
}
]

45
test/test-collection.js

@ -90,7 +90,10 @@ test('must be called with new', function (t) {
test('throws if no type is supplied', function (t) {
var collection = new TestCollection();
t.throws(function () {
collection.add({title: 'someTitle', metadata: {}});
collection.add({
title: 'someTitle',
metadata: {}
});
}, {message: 'Test type must be specified'});
t.end();
});
@ -98,7 +101,10 @@ test('throws if no type is supplied', function (t) {
test('throws if you try to set a hook as exclusive', function (t) {
var collection = new TestCollection();
t.throws(function () {
collection.add(mockTest({type: 'beforeEach', exclusive: true}));
collection.add(mockTest({
type: 'beforeEach',
exclusive: true
}));
}, {message: '"only" cannot be used with a beforeEach hook'});
t.end();
});
@ -106,7 +112,10 @@ test('throws if you try to set a hook as exclusive', function (t) {
test('throws if you try to set a before hook as always', function (t) {
var collection = new TestCollection();
t.throws(function () {
collection.add(mockTest({type: 'before', always: true}));
collection.add(mockTest({
type: 'before',
always: true
}));
}, {message: '"always" can only be used with after and afterEach hooks'});
t.end();
});
@ -184,7 +193,10 @@ test('adding a after test', function (t) {
test('adding a after.always test', function (t) {
var collection = new TestCollection();
collection.add(mockTest({type: 'after', always: true}, 'bar'));
collection.add(mockTest({
type: 'after',
always: true
}, 'bar'));
t.strictDeepEqual(serialize(collection), {
hooks: {
afterAlways: ['bar']
@ -206,7 +218,10 @@ test('adding a afterEach test', function (t) {
test('adding a afterEach.always test', function (t) {
var collection = new TestCollection();
collection.add(mockTest({type: 'afterEach', always: true}, 'baz'));
collection.add(mockTest({
type: 'afterEach',
always: true
}, 'baz'));
t.strictDeepEqual(serialize(collection), {
hooks: {
afterEachAlways: ['baz']
@ -252,12 +267,18 @@ test('foo', function (t) {
}
add('after1', {type: 'after'});
add('after.always', {type: 'after', always: true});
add('after.always', {
type: 'after',
always: true
});
add('beforeEach1', {type: 'beforeEach'});
add('before1', {type: 'before'});
add('beforeEach2', {type: 'beforeEach'});
add('afterEach1', {type: 'afterEach'});
add('afterEach.always', {type: 'afterEach', always: true});
add('afterEach.always', {
type: 'afterEach',
always: true
});
add('test1', {});
add('afterEach2', {type: 'afterEach'});
add('test2', {});
@ -312,12 +333,18 @@ test('foo', function (t) {
}
add('after1', {type: 'after'});
add('after.always', {type: 'after', always: true});
add('after.always', {
type: 'after',
always: true
});
add('beforeEach1', {type: 'beforeEach'});
add('before1', {type: 'before'});
add('beforeEach2', {type: 'beforeEach'});
add('afterEach1', {type: 'afterEach'});
add('afterEach.always', {type: 'afterEach', always: true});
add('afterEach.always', {
type: 'afterEach',
always: true
});
add('test1', {});
add('afterEach2', {type: 'afterEach'});
add('test2', {});

42
test/test.js

@ -9,25 +9,41 @@ var failingTestHint = 'Test was expected to fail, but succeeded, you should stop
function ava(title, fn, contextRef, report) {
var t = new Test(title, fn, contextRef, report);
t.metadata = {callback: false};
t.metadata = {
callback: false
};
return t;
}
ava.failing = function (title, fn, contextRef, report) {
var t = new Test(title, fn, contextRef, report);
t.metadata = {callback: false, failing: true};
t.metadata = {
callback: false,
failing: true
};
return t;
};
ava.cb = function (title, fn, contextRef, report) {
var t = new Test(title, fn, contextRef, report);
t.metadata = {callback: true};
t.metadata = {
callback: true
};
return t;
};
ava.cb.failing = function (title, fn, contextRef, report) {
var t = new Test(title, fn, contextRef, report);
t.metadata = {callback: true, failing: true};
t.metadata = {
callback: true,
failing: true
};
return t;
};
@ -74,6 +90,7 @@ test('infer name from function', function (t) {
var result = ava(function foo(a) {
a.pass();
}).run();
t.is(result.passed, true);
t.is(result.result.title, 'foo');
t.end();
@ -200,7 +217,13 @@ test('handle falsy testing of arrays', function (t) {
test('handle testing of objects', function (t) {
var result = ava(function (a) {
a.deepEqual({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar'});
a.deepEqual({
foo: 'foo',
bar: 'bar'
}, {
foo: 'foo',
bar: 'bar'
});
}).run();
t.is(result.passed, true);
@ -210,7 +233,14 @@ test('handle testing of objects', function (t) {
test('handle falsy testing of objects', function (t) {
var result = ava(function (a) {
a.notDeepEqual({foo: 'foo', bar: 'bar'}, {foo: 'foo', bar: 'bar', cat: 'cake'});
a.notDeepEqual({
foo: 'foo',
bar: 'bar'
}, {
foo: 'foo',
bar: 'bar',
cat: 'cake'
});
}).run();
t.is(result.passed, true);

2
test/visual/print-lorem-ipsum.js

@ -1,8 +1,8 @@
'use strict';
var fs = require('fs');
var path = require('path');
var text = fs.readFileSync(path.join(__dirname, 'lorem-ipsum.txt'), 'utf8');
var text = fs.readFileSync(path.join(__dirname, 'lorem-ipsum.txt'), 'utf8');
var lines = text.split(/\r?\n/g).map(function (line) {
return line.split(' ');
});

1
test/visual/run-visual-tests.js

@ -7,6 +7,7 @@ var arrify = require('arrify');
var Promise = require('bluebird');
var pify = require('pify');
var inquirer = pify(require('inquirer'), Promise);
var cwd = path.resolve(__dirname, '../../');
function fixture(fixtureName) {

112
test/watcher.js

@ -44,7 +44,10 @@ test('chokidar is not installed', function (t) {
});
try {
new Subject({}, {excludePatterns: [], on: function () {}}, [], []); // eslint-disable-line
new Subject({}, { // eslint-disable-line no-new
excludePatterns: [],
on: function () {}
}, [], []);
} catch (err) {
t.is(err.name, 'AvaError');
t.is(err.message, 'The optional dependency chokidar failed to install and is required for --watch. Chokidar is likely not supported on your platform.');
@ -101,13 +104,19 @@ group('chokidar is installed', function (beforeEach, test, group) {
};
resetRunStatus = function () {
runStatus = {failCount: 0, rejectionCount: 0, exceptionCount: 0};
runStatus = {
failCount: 0,
rejectionCount: 0,
exceptionCount: 0
};
return runStatus;
};
if (clock) {
clock.uninstall();
}
clock = lolex.install(0, ['setImmediate', 'setTimeout', 'clearTimeout']);
chokidarEmitter = new EventEmitter();
@ -243,9 +252,21 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
[
{label: 'is added', fire: add, event: 'add'},
{label: 'changes', fire: change, event: 'change'},
{label: 'is removed', fire: unlink, event: 'unlink'}
{
label: 'is added',
fire: add,
event: 'add'
},
{
label: 'changes',
fire: change,
event: 'change'
},
{
label: 'is removed',
fire: unlink,
event: 'unlink'
}
].forEach(function (variant) {
test('logs a debug message when a file is ' + variant.label, function (t) {
t.plan(2);
@ -258,9 +279,18 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
[
{label: 'is added', fire: add},
{label: 'changes', fire: change},
{label: 'is removed', fire: unlink}
{
label: 'is added',
fire: add
},
{
label: 'changes',
fire: change
},
{
label: 'is removed',
fire: unlink
}
].forEach(function (variant) {
test('reruns initial tests when a source file ' + variant.label, function (t) {
t.plan(12);
@ -305,9 +335,18 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
[
{label: 'failures', prop: 'failCount'},
{label: 'rejections', prop: 'rejectionCount'},
{label: 'exceptions', prop: 'exceptionCount'}
{
label: 'failures',
prop: 'failCount'
},
{
label: 'rejections',
prop: 'rejectionCount'
},
{
label: 'exceptions',
prop: 'exceptionCount'
}
].forEach(function (variant) {
test('does not clear logger if the previous run had ' + variant.label, function (t) {
t.plan(2);
@ -460,8 +499,14 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
[
{label: 'is added', fire: add},
{label: 'changes', fire: change}
{
label: 'is added',
fire: add
},
{
label: 'changes',
fire: change
}
].forEach(function (variant) {
test('(re)runs a test file when it ' + variant.label, function (t) {
t.plan(6);
@ -1100,7 +1145,10 @@ group('chokidar is installed', function (beforeEach, test, group) {
});
var emitStats = function (file, hasExclusive) {
apiEmitter.emit('stats', {file: file, hasExclusive: hasExclusive});
apiEmitter.emit('stats', {
file: file,
hasExclusive: hasExclusive
});
};
var t1 = path.join('test', '1.js');
@ -1267,8 +1315,15 @@ group('chokidar is installed', function (beforeEach, test, group) {
var other;
seed(function (files) {
runStatusEmitter.emit('test', {file: files[0], error: {}});
runStatusEmitter.emit('error', {file: files[0]});
runStatusEmitter.emit('test', {
file: files[0],
error: {}
});
runStatusEmitter.emit('error', {
file: files[0]
});
other = files[1];
});
@ -1281,9 +1336,15 @@ group('chokidar is installed', function (beforeEach, test, group) {
t.plan(1);
var first;
seed(function (files) {
runStatusEmitter.emit('test', {file: files[0], error: {}});
runStatusEmitter.emit('test', {
file: files[0],
error: {}
});
runStatusEmitter.emit('error', {file: files[1]});
first = files[0];
});
@ -1296,9 +1357,15 @@ group('chokidar is installed', function (beforeEach, test, group) {
t.plan(1);
var same;
seed(function (files) {
runStatusEmitter.emit('test', {file: files[0], error: {}});
runStatusEmitter.emit('test', {
file: files[0],
error: {}
});
runStatusEmitter.emit('error', {file: files[0]});
same = files[0];
});
@ -1312,14 +1379,21 @@ group('chokidar is installed', function (beforeEach, test, group) {
var same;
var other;
seed(function (files) {
runStatusEmitter.emit('test', {file: files[0], error: {}});
runStatusEmitter.emit('test', {
file: files[0],
error: {}
});
runStatusEmitter.emit('error', {file: files[0]});
same = files[0];
other = files[1];
});
unlink(same);
return debounce().then(function () {
return rerun(other);
}).then(function () {

Loading…
Cancel
Save