1
0
mirror of https://github.com/actions/labeler synced 2026-05-09 16:31:01 +02:00
This commit is contained in:
David Kale
2020-09-08 13:25:36 -04:00
parent e4246d2b5b
commit 91fcbb0108
4227 changed files with 416837 additions and 457884 deletions

View File

@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', {
});
exports.default = void 0;
var _assert = require('assert');
var _jestMatcherUtils = require('jest-matcher-utils');
var _chalk = _interopRequireDefault(require('chalk'));
@@ -102,7 +104,7 @@ const formatNodeAssertErrors = (event, state) => {
error = errors;
}
return error.code === 'ERR_ASSERTION'
return isAssertionError(error)
? {
message: assertionErrorMessage(error, {
expand: state.expand
@@ -139,27 +141,30 @@ const operatorMessage = operator => {
};
const assertThrowingMatcherHint = operatorName =>
_chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('function') +
_chalk.default.dim(')');
operatorName
? _chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('function') +
_chalk.default.dim(')')
: '';
const assertMatcherHint = (operator, operatorName) => {
let message =
_chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('received') +
_chalk.default.dim(', ') +
_chalk.default.green('expected') +
_chalk.default.dim(')');
const assertMatcherHint = (operator, operatorName, expected) => {
let message = '';
if (operator === '==') {
message +=
' or ' +
if (operator === '==' && expected === true) {
message =
_chalk.default.dim('assert') +
_chalk.default.dim('(') +
_chalk.default.red('received') +
_chalk.default.dim(') ');
_chalk.default.dim(')');
} else if (operatorName) {
message =
_chalk.default.dim('assert') +
_chalk.default.dim('.' + operatorName + '(') +
_chalk.default.red('received') +
_chalk.default.dim(', ') +
_chalk.default.green('expected') +
_chalk.default.dim(')');
}
return message;
@@ -181,8 +186,7 @@ function assertionErrorMessage(error, options) {
if (operatorName === 'doesNotThrow') {
return (
assertThrowingMatcherHint(operatorName) +
'\n\n' +
buildHintString(assertThrowingMatcherHint(operatorName)) +
_chalk.default.reset(`Expected the function not to throw an error.\n`) +
_chalk.default.reset(`Instead, it threw:\n`) +
` ${(0, _jestMatcherUtils.printReceived)(actual)}` +
@@ -195,8 +199,7 @@ function assertionErrorMessage(error, options) {
if (operatorName === 'throws') {
return (
assertThrowingMatcherHint(operatorName) +
'\n\n' +
buildHintString(assertThrowingMatcherHint(operatorName)) +
_chalk.default.reset(`Expected the function to throw an error.\n`) +
_chalk.default.reset(`But it didn't throw anything.`) +
_chalk.default.reset(
@@ -207,8 +210,7 @@ function assertionErrorMessage(error, options) {
}
return (
assertMatcherHint(operator, operatorName) +
'\n\n' +
buildHintString(assertMatcherHint(operator, operatorName, expected)) +
_chalk.default.reset(`Expected value ${operatorMessage(operator)}`) +
` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +
_chalk.default.reset(`Received:\n`) +
@@ -219,5 +221,18 @@ function assertionErrorMessage(error, options) {
);
}
function isAssertionError(error) {
return (
error &&
(error instanceof _assert.AssertionError ||
error.name === _assert.AssertionError.name ||
error.code === 'ERR_ASSERTION')
);
}
function buildHintString(hint) {
return hint ? hint + '\n\n' : '';
}
var _default = formatNodeAssertErrors;
exports.default = _default;