|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 'use strict';
-
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.createReporterError = createReporterError;
- exports.createArrayReporterError = createArrayReporterError;
- exports.validateReporters = validateReporters;
-
- function _chalk() {
- const data = _interopRequireDefault(require('chalk'));
-
- _chalk = function () {
- return data;
- };
-
- return data;
- }
-
- function _jestGetType() {
- const data = require('jest-get-type');
-
- _jestGetType = function () {
- return data;
- };
-
- return data;
- }
-
- function _jestValidate() {
- const data = require('jest-validate');
-
- _jestValidate = function () {
- return data;
- };
-
- return data;
- }
-
- var _utils = require('./utils');
-
- function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : {default: obj};
- }
-
- /**
- * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
- const validReporterTypes = ['array', 'string'];
- const ERROR = `${_utils.BULLET}Reporter Validation Error`;
- /**
- * Reporter Validation Error is thrown if the given arguments
- * within the reporter are not valid.
- *
- * This is a highly specific reporter error and in the future will be
- * merged with jest-validate. Till then, we can make use of it. It works
- * and that's what counts most at this time.
- */
-
- function createReporterError(reporterIndex, reporterValue) {
- const errorMessage =
- ` Reporter at index ${reporterIndex} must be of type:\n` +
- ` ${_chalk().default.bold.green(validReporterTypes.join(' or '))}\n` +
- ` but instead received:\n` +
- ` ${_chalk().default.bold.red(
- (0, _jestGetType().getType)(reporterValue)
- )}`;
- return new (_jestValidate().ValidationError)(
- ERROR,
- errorMessage,
- _utils.DOCUMENTATION_NOTE
- );
- }
-
- function createArrayReporterError(
- arrayReporter,
- reporterIndex,
- valueIndex,
- value,
- expectedType,
- valueName
- ) {
- const errorMessage =
- ` Unexpected value for ${valueName} ` +
- `at index ${valueIndex} of reporter at index ${reporterIndex}\n` +
- ' Expected:\n' +
- ` ${_chalk().default.bold.red(expectedType)}\n` +
- ' Got:\n' +
- ` ${_chalk().default.bold.green((0, _jestGetType().getType)(value))}\n` +
- ` Reporter configuration:\n` +
- ` ${_chalk().default.bold.green(
- JSON.stringify(arrayReporter, null, 2).split('\n').join('\n ')
- )}`;
- return new (_jestValidate().ValidationError)(
- ERROR,
- errorMessage,
- _utils.DOCUMENTATION_NOTE
- );
- }
-
- function validateReporters(reporterConfig) {
- return reporterConfig.every((reporter, index) => {
- if (Array.isArray(reporter)) {
- validateArrayReporter(reporter, index);
- } else if (typeof reporter !== 'string') {
- throw createReporterError(index, reporter);
- }
-
- return true;
- });
- }
-
- function validateArrayReporter(arrayReporter, reporterIndex) {
- const [path, options] = arrayReporter;
-
- if (typeof path !== 'string') {
- throw createArrayReporterError(
- arrayReporter,
- reporterIndex,
- 0,
- path,
- 'string',
- 'Path'
- );
- } else if (typeof options !== 'object') {
- throw createArrayReporterError(
- arrayReporter,
- reporterIndex,
- 1,
- options,
- 'object',
- 'Reporter Configuration'
- );
- }
- }
|