1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.errorMessage = void 0;
|
7 | function _chalk() {
|
8 | const data = _interopRequireDefault(require('chalk'));
|
9 | _chalk = function () {
|
10 | return data;
|
11 | };
|
12 | return data;
|
13 | }
|
14 | function _jestGetType() {
|
15 | const data = require('jest-get-type');
|
16 | _jestGetType = function () {
|
17 | return data;
|
18 | };
|
19 | return data;
|
20 | }
|
21 | var _condition = require('./condition');
|
22 | var _utils = require('./utils');
|
23 | function _interopRequireDefault(obj) {
|
24 | return obj && obj.__esModule ? obj : {default: obj};
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const errorMessage = (option, received, defaultValue, options, path) => {
|
34 | const conditions = (0, _condition.getValues)(defaultValue);
|
35 | const validTypes = Array.from(
|
36 | new Set(conditions.map(_jestGetType().getType))
|
37 | );
|
38 | const message = ` Option ${_chalk().default.bold(
|
39 | `"${path && path.length > 0 ? `${path.join('.')}.` : ''}${option}"`
|
40 | )} must be of type:
|
41 | ${validTypes.map(e => _chalk().default.bold.green(e)).join(' or ')}
|
42 | but instead received:
|
43 | ${_chalk().default.bold.red((0, _jestGetType().getType)(received))}
|
44 |
|
45 | Example:
|
46 | ${formatExamples(option, conditions)}`;
|
47 | const comment = options.comment;
|
48 | const name = (options.title && options.title.error) || _utils.ERROR;
|
49 | throw new _utils.ValidationError(name, message, comment);
|
50 | };
|
51 | exports.errorMessage = errorMessage;
|
52 | function formatExamples(option, examples) {
|
53 | return examples.map(
|
54 | e => ` {
|
55 | ${_chalk().default.bold(`"${option}"`)}: ${_chalk().default.bold(
|
56 | (0, _utils.formatPrettyObject)(e)
|
57 | )}
|
58 | }`
|
59 | ).join(`
|
60 |
|
61 | or
|
62 |
|
63 | `);
|
64 | }
|