Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var figures = require('figures');
var globby = require('globby');
var chalk = require('chalk');
var resolveCwd = require('resolve-cwd');
var AvaError = require('./lib/ava-error');
var fork = require('./lib/fork');
var formatter = require('./lib/enhance-assert').formatter();

Expand Down Expand Up @@ -138,7 +139,7 @@ Api.prototype.run = function () {
})
.then(function (files) {
if (files.length === 0) {
return Promise.reject(new Error('Couldn\'t find any files to test'));
return Promise.reject(new AvaError('Couldn\'t find any files to test'));
}

self.fileCount = files.length;
Expand Down
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ api.run()
logger.exit(api.failCount > 0 || api.rejectionCount > 0 || api.exceptionCount > 0 ? 1 : 0);
})
.catch(function (err) {
if (err.name === 'Error') {
if (err.name === 'AvaError') {
console.log(' ' + chalk.red(figures.cross) + ' ' + err.message);
} else {
console.error(err.stack);
Expand Down
12 changes: 12 additions & 0 deletions lib/ava-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

function AvaError(message) {
if (!(this instanceof AvaError)) {
return new AvaError(message);
}

this.message = message;
this.name = 'AvaError';
}

module.exports = AvaError;
7 changes: 4 additions & 3 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var path = require('path');
var objectAssign = require('object-assign');
var Promise = require('bluebird');
var debug = require('debug')('ava');
var AvaError = require('./ava-error');
var send = require('./send');

module.exports = function (file, opts) {
Expand All @@ -29,13 +30,13 @@ module.exports = function (file, opts) {

ps.on('exit', function (code) {
if (code > 0 && code !== 143) {
return reject(new Error(relFile + ' exited with a non-zero exit code: ' + code));
return reject(new AvaError(relFile + ' exited with a non-zero exit code: ' + code));
}

if (testResults) {
resolve(testResults);
} else {
reject(new Error('Test results were not received from ' + relFile));
reject(new AvaError('Test results were not received from ' + relFile));
}
});

Expand All @@ -48,7 +49,7 @@ module.exports = function (file, opts) {
message += ', make sure to import "ava" at the top of your test file';
}

reject(new Error(message));
reject(new AvaError(message));
});
});

Expand Down