Skip to content

Commit

Permalink
Empty stack for ValidateError (jestjs#3587)
Browse files Browse the repository at this point in the history
* Empty stack for ValidateError

* Fix indentation in reporter validation errors
  • Loading branch information
thymikee authored and cpojer committed May 17, 2017
1 parent 922a134 commit 75516cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ Object {
`;
exports[`Custom Reporters Integration invalid format for adding reporters 1`] = `
"● Reporter Validation Error:
"● Reporter Validation Error:
Unexpected value for Path at index 0 of reporter at index 0
Expected:
string
Got:
number
Reporter configuration:
Unexpected value for Path at index 0 of reporter at index 0
Expected:
string
Got:
number
Reporter configuration:
[
3243242
]
Expand Down
22 changes: 11 additions & 11 deletions packages/jest-config/src/reporterValidationErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {getType} = require('jest-matcher-utils');
const {DOCUMENTATION_NOTE, BULLET} = require('./utils');

const validReporterTypes = ['array', 'string'];
const ERROR = `${BULLET} Reporter Validation Error`;
const ERROR = `${BULLET}Reporter Validation Error`;

/**
* Reporter Vaidation Error is thrown if the given arguments
Expand All @@ -31,10 +31,10 @@ function createReporterError(
reporterValue: Array<ReporterConfig> | string,
): ValidationError {
const errorMessage =
`Reporter at index ${reporterIndex} must be of type:\n` +
` ${chalk.bold.green(validReporterTypes.join(' or '))}\n` +
` but instead received:\n` +
` ${chalk.bold.red(getType(reporterValue))}`;
` Reporter at index ${reporterIndex} must be of type:\n` +
` ${chalk.bold.green(validReporterTypes.join(' or '))}\n` +
` but instead received:\n` +
` ${chalk.bold.red(getType(reporterValue))}`;

return new ValidationError(ERROR, errorMessage, DOCUMENTATION_NOTE);
}
Expand All @@ -48,13 +48,13 @@ function createArrayReporterError(
valueName: string,
): ValidationError {
const errorMessage =
`Unexpected value for ${valueName} ` +
` Unexpected value for ${valueName} ` +
`at index ${valueIndex} of reporter at index ${reporterIndex}\n` +
' Expected:\n' +
` ${chalk.bold.red(expectedType)}\n` +
' Got:\n' +
` ${chalk.bold.green(getType(value))}\n` +
` Reporter configuration:\n` +
' Expected:\n' +
` ${chalk.bold.red(expectedType)}\n` +
' Got:\n' +
` ${chalk.bold.green(getType(value))}\n` +
` Reporter configuration:\n` +
` ${chalk.bold.green(JSON.stringify(arrayReporter, null, 2)
.split('\n')
.join('\n '))}`;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-validate/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ValidationError extends Error {
super();
comment = comment ? '\n\n' + comment : '\n';
this.name = '';
this.stack = '';
this.message = chalk.red(chalk.bold(name) + ':\n\n' + message + comment);
Error.captureStackTrace(this, () => {});
}
Expand Down

0 comments on commit 75516cb

Please sign in to comment.