diff --git a/packages/kbn-config-schema/src/byte_size_value/__snapshots__/index.test.ts.snap b/packages/kbn-config-schema/src/byte_size_value/__snapshots__/index.test.ts.snap deleted file mode 100644 index 97e9082401b3d..0000000000000 --- a/packages/kbn-config-schema/src/byte_size_value/__snapshots__/index.test.ts.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#constructor throws if number of bytes is negative 1`] = `"Value in bytes is expected to be a safe positive integer, but provided [-1024]."`; - -exports[`#constructor throws if number of bytes is not safe 1`] = `"Value in bytes is expected to be a safe positive integer, but provided [NaN]."`; - -exports[`#constructor throws if number of bytes is not safe 2`] = `"Value in bytes is expected to be a safe positive integer, but provided [Infinity]."`; - -exports[`#constructor throws if number of bytes is not safe 3`] = `"Value in bytes is expected to be a safe positive integer, but provided [9007199254740992]."`; - -exports[`parsing units throws an error when unsupported unit specified 1`] = `"Failed to parse [1tb] as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."`; diff --git a/packages/kbn-config-schema/src/byte_size_value/index.test.ts b/packages/kbn-config-schema/src/byte_size_value/index.test.ts index 198d95aa0ab4c..59960a4567f60 100644 --- a/packages/kbn-config-schema/src/byte_size_value/index.test.ts +++ b/packages/kbn-config-schema/src/byte_size_value/index.test.ts @@ -42,19 +42,29 @@ describe('parsing units', () => { }); test('throws an error when unsupported unit specified', () => { - expect(() => ByteSizeValue.parse('1tb')).toThrowErrorMatchingSnapshot(); + expect(() => ByteSizeValue.parse('1tb')).toThrowErrorMatchingInlineSnapshot( + `"Failed to parse value as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."` + ); }); }); describe('#constructor', () => { test('throws if number of bytes is negative', () => { - expect(() => new ByteSizeValue(-1024)).toThrowErrorMatchingSnapshot(); + expect(() => new ByteSizeValue(-1024)).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); }); test('throws if number of bytes is not safe', () => { - expect(() => new ByteSizeValue(NaN)).toThrowErrorMatchingSnapshot(); - expect(() => new ByteSizeValue(Infinity)).toThrowErrorMatchingSnapshot(); - expect(() => new ByteSizeValue(Math.pow(2, 53))).toThrowErrorMatchingSnapshot(); + expect(() => new ByteSizeValue(NaN)).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); + expect(() => new ByteSizeValue(Infinity)).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); + expect(() => new ByteSizeValue(Math.pow(2, 53))).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); }); test('accepts 0', () => { diff --git a/packages/kbn-config-schema/src/byte_size_value/index.ts b/packages/kbn-config-schema/src/byte_size_value/index.ts index 48862821bb78d..183a6c30f3839 100644 --- a/packages/kbn-config-schema/src/byte_size_value/index.ts +++ b/packages/kbn-config-schema/src/byte_size_value/index.ts @@ -38,7 +38,7 @@ export class ByteSizeValue { const number = Number(text); if (typeof number !== 'number' || isNaN(number)) { throw new Error( - `Failed to parse [${text}] as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] ` + + `Failed to parse value as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] ` + `(e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer.` ); } @@ -53,9 +53,7 @@ export class ByteSizeValue { constructor(private readonly valueInBytes: number) { if (!Number.isSafeInteger(valueInBytes) || valueInBytes < 0) { - throw new Error( - `Value in bytes is expected to be a safe positive integer, but provided [${valueInBytes}].` - ); + throw new Error(`Value in bytes is expected to be a safe positive integer.`); } } diff --git a/packages/kbn-config-schema/src/duration/index.ts b/packages/kbn-config-schema/src/duration/index.ts index b96b5a3687bbb..282c150e8150a 100644 --- a/packages/kbn-config-schema/src/duration/index.ts +++ b/packages/kbn-config-schema/src/duration/index.ts @@ -28,7 +28,7 @@ function stringToDuration(text: string) { const number = Number(text); if (typeof number !== 'number' || isNaN(number)) { throw new Error( - `Failed to parse [${text}] as time value. Value must be a duration in milliseconds, or follow the format ` + + `Failed to parse value as time value. Value must be a duration in milliseconds, or follow the format ` + `[ms|s|m|h|d|w|M|Y] (e.g. '70ms', '5s', '3d', '1Y'), where the duration is a safe positive integer.` ); } @@ -43,9 +43,7 @@ function stringToDuration(text: string) { function numberToDuration(numberMs: number) { if (!Number.isSafeInteger(numberMs) || numberMs < 0) { - throw new Error( - `Value in milliseconds is expected to be a safe positive integer, but provided [${numberMs}].` - ); + throw new Error(`Value in milliseconds is expected to be a safe positive integer.`); } return momentDuration(numberMs); diff --git a/packages/kbn-config-schema/src/types/__snapshots__/any_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/any_type.test.ts.snap deleted file mode 100644 index 3a40752d52b6e..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/any_type.test.ts.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [any] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [any] but got [undefined]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/boolean_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/boolean_type.test.ts.snap deleted file mode 100644 index 0e5f6de2deea8..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/boolean_type.test.ts.snap +++ /dev/null @@ -1,15 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [boolean] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [boolean] but got [undefined]"`; - -exports[`returns error when not boolean 1`] = `"expected value of type [boolean] but got [number]"`; - -exports[`returns error when not boolean 2`] = `"expected value of type [boolean] but got [Array]"`; - -exports[`returns error when not boolean 3`] = `"expected value of type [boolean] but got [string]"`; - -exports[`returns error when not boolean 4`] = `"expected value of type [boolean] but got [number]"`; - -exports[`returns error when not boolean 5`] = `"expected value of type [boolean] but got [string]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/buffer_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/buffer_type.test.ts.snap deleted file mode 100644 index 96a7ab34dac26..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/buffer_type.test.ts.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [Buffer] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [Buffer] but got [undefined]"`; - -exports[`returns error when not a buffer 1`] = `"expected value of type [Buffer] but got [number]"`; - -exports[`returns error when not a buffer 2`] = `"expected value of type [Buffer] but got [Array]"`; - -exports[`returns error when not a buffer 3`] = `"expected value of type [Buffer] but got [string]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/byte_size_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/byte_size_type.test.ts.snap deleted file mode 100644 index ea2102b1776fb..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/byte_size_type.test.ts.snap +++ /dev/null @@ -1,61 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#defaultValue can be a ByteSizeValue 1`] = ` -ByteSizeValue { - "valueInBytes": 1024, -} -`; - -exports[`#defaultValue can be a number 1`] = ` -ByteSizeValue { - "valueInBytes": 1024, -} -`; - -exports[`#defaultValue can be a string 1`] = ` -ByteSizeValue { - "valueInBytes": 1024, -} -`; - -exports[`#defaultValue can be a string-formatted number 1`] = ` -ByteSizeValue { - "valueInBytes": 1024, -} -`; - -exports[`#max returns error when larger 1`] = `"Value is [1mb] ([1048576b]) but it must be equal to or less than [1kb]"`; - -exports[`#max returns value when smaller 1`] = ` -ByteSizeValue { - "valueInBytes": 1, -} -`; - -exports[`#min returns error when smaller 1`] = `"Value is [1b] ([1b]) but it must be equal to or greater than [1kb]"`; - -exports[`#min returns value when larger 1`] = ` -ByteSizeValue { - "valueInBytes": 1024, -} -`; - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [ByteSize] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [ByteSize] but got [undefined]"`; - -exports[`returns error when not valid string or positive safe integer 1`] = `"Value in bytes is expected to be a safe positive integer, but provided [-123]."`; - -exports[`returns error when not valid string or positive safe integer 2`] = `"Value in bytes is expected to be a safe positive integer, but provided [NaN]."`; - -exports[`returns error when not valid string or positive safe integer 3`] = `"Value in bytes is expected to be a safe positive integer, but provided [Infinity]."`; - -exports[`returns error when not valid string or positive safe integer 4`] = `"Value in bytes is expected to be a safe positive integer, but provided [9007199254740992]."`; - -exports[`returns error when not valid string or positive safe integer 5`] = `"expected value of type [ByteSize] but got [Array]"`; - -exports[`returns error when not valid string or positive safe integer 6`] = `"expected value of type [ByteSize] but got [RegExp]"`; - -exports[`returns error when not valid string or positive safe integer 7`] = `"Failed to parse [123foo] as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."`; - -exports[`returns error when not valid string or positive safe integer 8`] = `"Failed to parse [123 456] as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/conditional_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/conditional_type.test.ts.snap deleted file mode 100644 index b32db114860f5..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/conditional_type.test.ts.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`correctly handles missing references 1`] = `"[value]: expected value of type [string] but got [number]"`; - -exports[`includes namespace into failures 1`] = `"[mega-namespace.value]: expected value of type [string] but got [number]"`; - -exports[`includes namespace into failures 2`] = `"[mega-namespace.value]: expected value of type [number] but got [string]"`; - -exports[`properly handles conditionals within objects 1`] = `"[value]: expected value of type [string] but got [number]"`; - -exports[`properly handles conditionals within objects 2`] = `"[value]: expected value of type [number] but got [string]"`; - -exports[`properly handles schemas with incompatible types 1`] = `"expected value of type [string] but got [boolean]"`; - -exports[`properly handles schemas with incompatible types 2`] = `"expected value of type [boolean] but got [string]"`; - -exports[`properly validates types according chosen schema 1`] = `"value is [a] but it must have a minimum length of [2]."`; - -exports[`properly validates types according chosen schema 2`] = `"value is [ab] but it must have a maximum length of [1]."`; - -exports[`properly validates when compares with "null" literal Schema 1`] = `"value is [a] but it must have a minimum length of [2]."`; - -exports[`properly validates when compares with "null" literal Schema 2`] = `"value is [ab] but it must have a minimum length of [3]."`; - -exports[`properly validates when compares with Schema 1`] = `"value is [a] but it must have a minimum length of [2]."`; - -exports[`properly validates when compares with Schema 2`] = `"value is [ab] but it must have a minimum length of [3]."`; - -exports[`required by default 1`] = `"expected value of type [string] but got [undefined]"`; - -exports[`works with both context and sibling references 1`] = `"[value]: expected value of type [string] but got [number]"`; - -exports[`works with both context and sibling references 2`] = `"[value]: expected value of type [number] but got [string]"`; - -exports[`works within \`oneOf\` 1`] = ` -"types that failed validation: -- [0]: expected value of type [string] but got [number] -- [1]: expected value of type [array] but got [number]" -`; - -exports[`works within \`oneOf\` 2`] = ` -"types that failed validation: -- [0]: expected value of type [string] but got [boolean] -- [1]: expected value of type [array] but got [boolean]" -`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/duration_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/duration_type.test.ts.snap deleted file mode 100644 index c4e4ff652a2d7..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/duration_type.test.ts.snap +++ /dev/null @@ -1,29 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#defaultValue can be a moment.Duration 1`] = `"PT1H"`; - -exports[`#defaultValue can be a number 1`] = `"PT0.6S"`; - -exports[`#defaultValue can be a string 1`] = `"PT1H"`; - -exports[`#defaultValue can be a string-formatted number 1`] = `"PT0.6S"`; - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [moment.Duration] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [moment.Duration] but got [undefined]"`; - -exports[`returns error when not valid string or non-safe positive integer 1`] = `"Value in milliseconds is expected to be a safe positive integer, but provided [-123]."`; - -exports[`returns error when not valid string or non-safe positive integer 2`] = `"Value in milliseconds is expected to be a safe positive integer, but provided [NaN]."`; - -exports[`returns error when not valid string or non-safe positive integer 3`] = `"Value in milliseconds is expected to be a safe positive integer, but provided [Infinity]."`; - -exports[`returns error when not valid string or non-safe positive integer 4`] = `"Value in milliseconds is expected to be a safe positive integer, but provided [9007199254740992]."`; - -exports[`returns error when not valid string or non-safe positive integer 5`] = `"expected value of type [moment.Duration] but got [Array]"`; - -exports[`returns error when not valid string or non-safe positive integer 6`] = `"expected value of type [moment.Duration] but got [RegExp]"`; - -exports[`returns error when not valid string or non-safe positive integer 7`] = `"Failed to parse [123foo] as time value. Value must be a duration in milliseconds, or follow the format [ms|s|m|h|d|w|M|Y] (e.g. '70ms', '5s', '3d', '1Y'), where the duration is a safe positive integer."`; - -exports[`returns error when not valid string or non-safe positive integer 8`] = `"Failed to parse [123 456] as time value. Value must be a duration in milliseconds, or follow the format [ms|s|m|h|d|w|M|Y] (e.g. '70ms', '5s', '3d', '1Y'), where the duration is a safe positive integer."`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/literal_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/literal_type.test.ts.snap deleted file mode 100644 index 14d474b4a516b..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/literal_type.test.ts.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value to equal [test] but got [foo]"`; - -exports[`returns error when not correct 1`] = `"expected value to equal [test] but got [foo]"`; - -exports[`returns error when not correct 2`] = `"expected value to equal [true] but got [false]"`; - -exports[`returns error when not correct 3`] = `"expected value to equal [test] but got [1,2,3]"`; - -exports[`returns error when not correct 4`] = `"expected value to equal [123] but got [abc]"`; - -exports[`returns error when not correct 5`] = `"expected value to equal [null] but got [42]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/maybe_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/maybe_type.test.ts.snap deleted file mode 100644 index fdb172df356a7..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/maybe_type.test.ts.snap +++ /dev/null @@ -1,9 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`fails if null 1`] = `"expected value of type [string] but got [null]"`; - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [string] but got [null]"`; - -exports[`validates basic type 1`] = `"expected value of type [string] but got [number]"`; - -exports[`validates contained type 1`] = `"value is [foo] but it must have a maximum length of [1]."`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/never_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/never_type.test.ts.snap deleted file mode 100644 index 6eea2a7cefc72..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/never_type.test.ts.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`throws on any value set 1`] = `"a value wasn't expected to be present"`; - -exports[`throws on any value set 2`] = `"a value wasn't expected to be present"`; - -exports[`throws on any value set 3`] = `"a value wasn't expected to be present"`; - -exports[`throws on any value set 4`] = `"a value wasn't expected to be present"`; - -exports[`throws on value set as object property 1`] = `"[name]: a value wasn't expected to be present"`; - -exports[`works for conditional types 1`] = `"[name]: a value wasn't expected to be present"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/nullable_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/nullable_type.test.ts.snap deleted file mode 100644 index 96ab664921fdf..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/nullable_type.test.ts.snap +++ /dev/null @@ -1,25 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`includes namespace in failure 1`] = ` -"[foo-namespace]: types that failed validation: -- [foo-namespace.0]: value is [foo] but it must have a maximum length of [1]. -- [foo-namespace.1]: expected value to equal [null] but got [foo]" -`; - -exports[`validates basic type 1`] = ` -"types that failed validation: -- [0]: expected value of type [string] but got [number] -- [1]: expected value to equal [null] but got [666]" -`; - -exports[`validates contained type 1`] = ` -"types that failed validation: -- [0]: value is [foo] but it must have a maximum length of [1]. -- [1]: expected value to equal [null] but got [foo]" -`; - -exports[`validates type errors in object 1`] = ` -"[foo]: types that failed validation: -- [foo.0]: value is [ab] but it must have a maximum length of [1]. -- [foo.1]: expected value to equal [null] but got [ab]" -`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/number_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/number_type.test.ts.snap deleted file mode 100644 index 5d1e5fcf1ef81..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/number_type.test.ts.snap +++ /dev/null @@ -1,17 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#max returns error when larger number 1`] = `"Value is [3] but it must be equal to or lower than [2]."`; - -exports[`#min returns error when smaller number 1`] = `"Value is [3] but it must be equal to or greater than [4]."`; - -exports[`fails if number is \`NaN\` 1`] = `"expected value of type [number] but got [number]"`; - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [number] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [number] but got [undefined]"`; - -exports[`returns error when not number or numeric string 1`] = `"expected value of type [number] but got [string]"`; - -exports[`returns error when not number or numeric string 2`] = `"expected value of type [number] but got [Array]"`; - -exports[`returns error when not number or numeric string 3`] = `"expected value of type [number] but got [RegExp]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/one_of_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/one_of_type.test.ts.snap deleted file mode 100644 index 75dfff456ebe7..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/one_of_type.test.ts.snap +++ /dev/null @@ -1,32 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`fails if not matching literal 1`] = ` -"types that failed validation: -- [0]: expected value to equal [foo] but got [bar]" -`; - -exports[`fails if not matching multiple types 1`] = ` -"types that failed validation: -- [0]: expected value of type [string] but got [boolean] -- [1]: expected value of type [number] but got [boolean]" -`; - -exports[`fails if not matching type 1`] = ` -"types that failed validation: -- [0]: expected value of type [string] but got [boolean]" -`; - -exports[`fails if not matching type 2`] = ` -"types that failed validation: -- [0]: expected value of type [string] but got [number]" -`; - -exports[`handles object with wrong type 1`] = ` -"types that failed validation: -- [0.age]: expected value of type [number] but got [string]" -`; - -exports[`includes namespace in failure 1`] = ` -"[foo-namespace]: types that failed validation: -- [foo-namespace.0.age]: expected value of type [number] but got [string]" -`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/stream_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/stream_type.test.ts.snap deleted file mode 100644 index e813b4f68a09e..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/stream_type.test.ts.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [Stream] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [Buffer] but got [undefined]"`; - -exports[`returns error when not a stream 1`] = `"expected value of type [Stream] but got [number]"`; - -exports[`returns error when not a stream 2`] = `"expected value of type [Stream] but got [Array]"`; - -exports[`returns error when not a stream 3`] = `"expected value of type [Stream] but got [string]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/string_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/string_type.test.ts.snap deleted file mode 100644 index 8e1f63fb66733..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/string_type.test.ts.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#hostname returns error when empty string 1`] = `"any.empty"`; - -exports[`#hostname returns error when value is not a valid hostname 1`] = `"value is [host:name] but it must be a valid hostname (see RFC 1123)."`; - -exports[`#hostname returns error when value is not a valid hostname 2`] = `"value is [localhost:5601] but it must be a valid hostname (see RFC 1123)."`; - -exports[`#hostname returns error when value is not a valid hostname 3`] = `"value is [-] but it must be a valid hostname (see RFC 1123)."`; - -exports[`#hostname returns error when value is not a valid hostname 4`] = `"value is [0:?:0:0:0:0:0:1] but it must be a valid hostname (see RFC 1123)."`; - -exports[`#hostname returns error when value is not a valid hostname 5`] = `"value is [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] but it must be a valid hostname (see RFC 1123)."`; - -exports[`#hostname supports string validation rules 1`] = `"value is [www.example.com] but it must have a maximum length of [3]."`; - -exports[`#maxLength returns error when longer string 1`] = `"value is [foo] but it must have a maximum length of [2]."`; - -exports[`#minLength returns error when empty string 1`] = `"value is [] but it must have a minimum length of [2]."`; - -exports[`#minLength returns error when shorter string 1`] = `"value is [foo] but it must have a minimum length of [4]."`; - -exports[`#validate throw when empty string 1`] = `"validator failure"`; - -exports[`#validate throws when returns string 1`] = `"validator failure"`; - -exports[`includes namespace in failure 1`] = `"[foo-namespace]: expected value of type [string] but got [undefined]"`; - -exports[`is required by default 1`] = `"expected value of type [string] but got [undefined]"`; - -exports[`returns error when not string 1`] = `"expected value of type [string] but got [number]"`; - -exports[`returns error when not string 2`] = `"expected value of type [string] but got [Array]"`; - -exports[`returns error when not string 3`] = `"expected value of type [string] but got [RegExp]"`; diff --git a/packages/kbn-config-schema/src/types/__snapshots__/uri_type.test.ts.snap b/packages/kbn-config-schema/src/types/__snapshots__/uri_type.test.ts.snap deleted file mode 100644 index 81fafdb4a7b33..0000000000000 --- a/packages/kbn-config-schema/src/types/__snapshots__/uri_type.test.ts.snap +++ /dev/null @@ -1,25 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#scheme returns error when shorter string 1`] = `"expected URI with scheme [http|https] but got [ftp://elastic.co]."`; - -exports[`#scheme returns error when shorter string 2`] = `"expected URI with scheme [http|https] but got [file:///kibana.log]."`; - -exports[`#validate throws when returns string 1`] = `"validator failure"`; - -exports[`is required by default 1`] = `"expected value of type [string] but got [undefined]."`; - -exports[`returns error when not string 1`] = `"expected value of type [string] but got [number]."`; - -exports[`returns error when not string 2`] = `"expected value of type [string] but got [Array]."`; - -exports[`returns error when not string 3`] = `"expected value of type [string] but got [RegExp]."`; - -exports[`returns error when value is not a URI 1`] = `"value is [3domain.local] but it must be a valid URI (see RFC 3986)."`; - -exports[`returns error when value is not a URI 2`] = `"value is [http://8010:0:0:0:9:500:300C:200A] but it must be a valid URI (see RFC 3986)."`; - -exports[`returns error when value is not a URI 3`] = `"value is [-] but it must be a valid URI (see RFC 3986)."`; - -exports[`returns error when value is not a URI 4`] = `"value is [https://example.com?baz[]=foo&baz[]=bar] but it must be a valid URI (see RFC 3986)."`; - -exports[`returns error when value is not a URI 5`] = `"value is [http://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] but it must be a valid URI (see RFC 3986)."`; diff --git a/packages/kbn-config-schema/src/types/any_type.test.ts b/packages/kbn-config-schema/src/types/any_type.test.ts index 4d68c860ba13d..30a9a8b71ea12 100644 --- a/packages/kbn-config-schema/src/types/any_type.test.ts +++ b/packages/kbn-config-schema/src/types/any_type.test.ts @@ -28,13 +28,17 @@ test('works for any value', () => { }); test('is required by default', () => { - expect(() => schema.any().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.any().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [any] but got [undefined]"` + ); }); test('includes namespace in failure', () => { expect(() => schema.any().validate(undefined, {}, 'foo-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [any] but got [undefined]"` + ); }); describe('#defaultValue', () => { diff --git a/packages/kbn-config-schema/src/types/array_type.test.ts b/packages/kbn-config-schema/src/types/array_type.test.ts index 66b72096a593d..9f3370de8c265 100644 --- a/packages/kbn-config-schema/src/types/array_type.test.ts +++ b/packages/kbn-config-schema/src/types/array_type.test.ts @@ -39,7 +39,7 @@ test('fails if wrong input type', () => { test('fails if string input cannot be parsed', () => { const type = schema.arrayOf(schema.string()); expect(() => type.validate('test')).toThrowErrorMatchingInlineSnapshot( - `"could not parse array value from [test]"` + `"could not parse array value from json input"` ); }); @@ -53,7 +53,7 @@ test('fails with correct type if parsed input is not an array', () => { test('includes namespace in failure when wrong top-level type', () => { const type = schema.arrayOf(schema.string()); expect(() => type.validate('test', {}, 'foo-namespace')).toThrowErrorMatchingInlineSnapshot( - `"[foo-namespace]: could not parse array value from [test]"` + `"[foo-namespace]: could not parse array value from json input"` ); }); diff --git a/packages/kbn-config-schema/src/types/array_type.ts b/packages/kbn-config-schema/src/types/array_type.ts index a0353e8348ddd..0df0d44a37951 100644 --- a/packages/kbn-config-schema/src/types/array_type.ts +++ b/packages/kbn-config-schema/src/types/array_type.ts @@ -52,7 +52,7 @@ export class ArrayType extends Type { case 'array.sparse': return `sparse array are not allowed`; case 'array.parse': - return `could not parse array value from [${value}]`; + return `could not parse array value from json input`; case 'array.min': return `array size is [${value.length}], but cannot be smaller than [${limit}]`; case 'array.max': diff --git a/packages/kbn-config-schema/src/types/boolean_type.test.ts b/packages/kbn-config-schema/src/types/boolean_type.test.ts index e94999b505437..bffa3e18f93bf 100644 --- a/packages/kbn-config-schema/src/types/boolean_type.test.ts +++ b/packages/kbn-config-schema/src/types/boolean_type.test.ts @@ -35,13 +35,17 @@ test('handles boolean strings', () => { }); test('is required by default', () => { - expect(() => schema.boolean().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.boolean().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [undefined]"` + ); }); test('includes namespace in failure', () => { expect(() => schema.boolean().validate(undefined, {}, 'foo-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [boolean] but got [undefined]"` + ); }); describe('#defaultValue', () => { @@ -55,13 +59,23 @@ describe('#defaultValue', () => { }); test('returns error when not boolean', () => { - expect(() => schema.boolean().validate(123)).toThrowErrorMatchingSnapshot(); + expect(() => schema.boolean().validate(123)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [number]"` + ); - expect(() => schema.boolean().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => schema.boolean().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [Array]"` + ); - expect(() => schema.boolean().validate('abc')).toThrowErrorMatchingSnapshot(); + expect(() => schema.boolean().validate('abc')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [string]"` + ); - expect(() => schema.boolean().validate(0)).toThrowErrorMatchingSnapshot(); + expect(() => schema.boolean().validate(0)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [number]"` + ); - expect(() => schema.boolean().validate('no')).toThrowErrorMatchingSnapshot(); + expect(() => schema.boolean().validate('no')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [string]"` + ); }); diff --git a/packages/kbn-config-schema/src/types/buffer_type.test.ts b/packages/kbn-config-schema/src/types/buffer_type.test.ts index 63d59296aec84..a7b589df0c6d1 100644 --- a/packages/kbn-config-schema/src/types/buffer_type.test.ts +++ b/packages/kbn-config-schema/src/types/buffer_type.test.ts @@ -25,13 +25,17 @@ test('returns value by default', () => { }); test('is required by default', () => { - expect(() => schema.buffer().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.buffer().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Buffer] but got [undefined]"` + ); }); test('includes namespace in failure', () => { expect(() => schema.buffer().validate(undefined, {}, 'foo-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [Buffer] but got [undefined]"` + ); }); describe('#defaultValue', () => { @@ -49,9 +53,15 @@ describe('#defaultValue', () => { }); test('returns error when not a buffer', () => { - expect(() => schema.buffer().validate(123)).toThrowErrorMatchingSnapshot(); + expect(() => schema.buffer().validate(123)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Buffer] but got [number]"` + ); - expect(() => schema.buffer().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => schema.buffer().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Buffer] but got [Array]"` + ); - expect(() => schema.buffer().validate('abc')).toThrowErrorMatchingSnapshot(); + expect(() => schema.buffer().validate('abc')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Buffer] but got [string]"` + ); }); diff --git a/packages/kbn-config-schema/src/types/byte_size_type.test.ts b/packages/kbn-config-schema/src/types/byte_size_type.test.ts index 7c65ec2945b49..a69a7296a6eb8 100644 --- a/packages/kbn-config-schema/src/types/byte_size_type.test.ts +++ b/packages/kbn-config-schema/src/types/byte_size_type.test.ts @@ -35,11 +35,17 @@ test('handles numbers', () => { }); test('is required by default', () => { - expect(() => byteSize().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [ByteSize] but got [undefined]"` + ); }); test('includes namespace in failure', () => { - expect(() => byteSize().validate(undefined, {}, 'foo-namespace')).toThrowErrorMatchingSnapshot(); + expect(() => + byteSize().validate(undefined, {}, 'foo-namespace') + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [ByteSize] but got [undefined]"` + ); }); describe('#defaultValue', () => { @@ -48,7 +54,11 @@ describe('#defaultValue', () => { byteSize({ defaultValue: ByteSizeValue.parse('1kb'), }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 1024, + } + `); }); test('can be a string', () => { @@ -56,7 +66,11 @@ describe('#defaultValue', () => { byteSize({ defaultValue: '1kb', }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 1024, + } + `); }); test('can be a string-formatted number', () => { @@ -64,7 +78,11 @@ describe('#defaultValue', () => { byteSize({ defaultValue: '1024', }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 1024, + } + `); }); test('can be a number', () => { @@ -72,7 +90,11 @@ describe('#defaultValue', () => { byteSize({ defaultValue: 1024, }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 1024, + } + `); }); }); @@ -82,7 +104,11 @@ describe('#min', () => { byteSize({ min: '1b', }).validate('1kb') - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 1024, + } + `); }); test('returns error when smaller', () => { @@ -90,34 +116,56 @@ describe('#min', () => { byteSize({ min: '1kb', }).validate('1b') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"Value must be equal to or greater than [1kb]"`); }); }); describe('#max', () => { test('returns value when smaller', () => { - expect(byteSize({ max: '1kb' }).validate('1b')).toMatchSnapshot(); + expect(byteSize({ max: '1kb' }).validate('1b')).toMatchInlineSnapshot(` + ByteSizeValue { + "valueInBytes": 1, + } + `); }); test('returns error when larger', () => { - expect(() => byteSize({ max: '1kb' }).validate('1mb')).toThrowErrorMatchingSnapshot(); + expect(() => byteSize({ max: '1kb' }).validate('1mb')).toThrowErrorMatchingInlineSnapshot( + `"Value must be equal to or less than [1kb]"` + ); }); }); test('returns error when not valid string or positive safe integer', () => { - expect(() => byteSize().validate(-123)).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate(-123)).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); - expect(() => byteSize().validate(NaN)).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate(NaN)).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); - expect(() => byteSize().validate(Infinity)).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate(Infinity)).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); - expect(() => byteSize().validate(Math.pow(2, 53))).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate(Math.pow(2, 53))).toThrowErrorMatchingInlineSnapshot( + `"Value in bytes is expected to be a safe positive integer."` + ); - expect(() => byteSize().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [ByteSize] but got [Array]"` + ); - expect(() => byteSize().validate(/abc/)).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate(/abc/)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [ByteSize] but got [RegExp]"` + ); - expect(() => byteSize().validate('123foo')).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate('123foo')).toThrowErrorMatchingInlineSnapshot( + `"Failed to parse value as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."` + ); - expect(() => byteSize().validate('123 456')).toThrowErrorMatchingSnapshot(); + expect(() => byteSize().validate('123 456')).toThrowErrorMatchingInlineSnapshot( + `"Failed to parse value as byte value. Value must be either number of bytes, or follow the format [b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."` + ); }); diff --git a/packages/kbn-config-schema/src/types/byte_size_type.ts b/packages/kbn-config-schema/src/types/byte_size_type.ts index 4833de7ecf15f..f7aa12291c7de 100644 --- a/packages/kbn-config-schema/src/types/byte_size_type.ts +++ b/packages/kbn-config-schema/src/types/byte_size_type.ts @@ -61,13 +61,9 @@ export class ByteSizeType extends Type { case 'bytes.parse': return new SchemaTypeError(message, path); case 'bytes.min': - return `Value is [${value.toString()}] ([${value.toString( - 'b' - )}]) but it must be equal to or greater than [${limit.toString()}]`; + return `Value must be equal to or greater than [${limit.toString()}]`; case 'bytes.max': - return `Value is [${value.toString()}] ([${value.toString( - 'b' - )}]) but it must be equal to or less than [${limit.toString()}]`; + return `Value must be equal to or less than [${limit.toString()}]`; } } } diff --git a/packages/kbn-config-schema/src/types/conditional_type.test.ts b/packages/kbn-config-schema/src/types/conditional_type.test.ts index 354854b864755..b7ad431318e85 100644 --- a/packages/kbn-config-schema/src/types/conditional_type.test.ts +++ b/packages/kbn-config-schema/src/types/conditional_type.test.ts @@ -32,7 +32,7 @@ test('required by default', () => { context_value_1: 0, context_value_2: 0, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"expected value of type [string] but got [undefined]"`); }); test('returns default', () => { @@ -90,7 +90,9 @@ test('properly validates types according chosen schema', () => { context_value_1: 0, context_value_2: 0, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [1] but it must have a minimum length of [2]."` + ); expect( type.validate('ab', { @@ -104,7 +106,9 @@ test('properly validates types according chosen schema', () => { context_value_1: 0, context_value_2: 1, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [2] but it must have a maximum length of [1]."` + ); expect( type.validate('a', { @@ -126,7 +130,9 @@ test('properly validates when compares with Schema', () => { type.validate('a', { context_value_1: 0, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [1] but it must have a minimum length of [2]."` + ); expect( type.validate('ab', { @@ -138,7 +144,9 @@ test('properly validates when compares with Schema', () => { type.validate('ab', { context_value_1: 'b', }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [2] but it must have a minimum length of [3]."` + ); expect( type.validate('abc', { @@ -159,7 +167,9 @@ test('properly validates when compares with "null" literal Schema', () => { type.validate('a', { context_value_1: null, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [1] but it must have a minimum length of [2]."` + ); expect( type.validate('ab', { @@ -171,7 +181,9 @@ test('properly validates when compares with "null" literal Schema', () => { type.validate('ab', { context_value_1: 'b', }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [2] but it must have a minimum length of [3]."` + ); expect( type.validate('abc', { @@ -193,7 +205,7 @@ test('properly handles schemas with incompatible types', () => { context_value_1: 0, context_value_2: 0, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"expected value of type [string] but got [boolean]"`); expect( type.validate('a', { @@ -207,7 +219,7 @@ test('properly handles schemas with incompatible types', () => { context_value_1: 0, context_value_2: 1, }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"expected value of type [boolean] but got [string]"`); expect( type.validate(true, { @@ -223,14 +235,18 @@ test('properly handles conditionals within objects', () => { value: schema.conditional(schema.siblingRef('key'), 'number', schema.number(), schema.string()), }); - expect(() => type.validate({ key: 'string', value: 1 })).toThrowErrorMatchingSnapshot(); + expect(() => type.validate({ key: 'string', value: 1 })).toThrowErrorMatchingInlineSnapshot( + `"[value]: expected value of type [string] but got [number]"` + ); expect(type.validate({ key: 'string', value: 'a' })).toEqual({ key: 'string', value: 'a', }); - expect(() => type.validate({ key: 'number', value: 'a' })).toThrowErrorMatchingSnapshot(); + expect(() => type.validate({ key: 'number', value: 'a' })).toThrowErrorMatchingInlineSnapshot( + `"[value]: expected value of type [number] but got [string]"` + ); expect(type.validate({ key: 'number', value: 1 })).toEqual({ key: 'number', @@ -269,7 +285,9 @@ test('works with both context and sibling references', () => { expect(() => type.validate({ key: 'string', value: 1 }, { context_key: 'number' }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[value]: expected value of type [string] but got [number]"` + ); expect(type.validate({ key: 'string', value: 'a' }, { context_key: 'number' })).toEqual({ key: 'string', @@ -278,7 +296,9 @@ test('works with both context and sibling references', () => { expect(() => type.validate({ key: 'number', value: 'a' }, { context_key: 'number' }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[value]: expected value of type [number] but got [string]"` + ); expect(type.validate({ key: 'number', value: 1 }, { context_key: 'number' })).toEqual({ key: 'number', @@ -294,11 +314,15 @@ test('includes namespace into failures', () => { expect(() => type.validate({ key: 'string', value: 1 }, {}, 'mega-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[mega-namespace.value]: expected value of type [string] but got [number]"` + ); expect(() => type.validate({ key: 'number', value: 'a' }, {}, 'mega-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[mega-namespace.value]: expected value of type [number] but got [string]"` + ); }); test('correctly handles missing references', () => { @@ -311,7 +335,9 @@ test('correctly handles missing references', () => { ), }); - expect(() => type.validate({ value: 1 })).toThrowErrorMatchingSnapshot(); + expect(() => type.validate({ value: 1 })).toThrowErrorMatchingInlineSnapshot( + `"[value]: expected value of type [string] but got [number]"` + ); expect(type.validate({ value: 'a' })).toEqual({ value: 'a' }); }); @@ -332,8 +358,16 @@ test('works within `oneOf`', () => { expect(type.validate(true, { type: 'boolean' })).toEqual(true); expect(type.validate(['a', 'b'], { type: 'array' })).toEqual(['a', 'b']); - expect(() => type.validate(1, { type: 'string' })).toThrowErrorMatchingSnapshot(); - expect(() => type.validate(true, { type: 'string' })).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(1, { type: 'string' })).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [string] but got [number] +- [1]: expected value of type [array] but got [number]" +`); + expect(() => type.validate(true, { type: 'string' })).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [string] but got [boolean] +- [1]: expected value of type [array] but got [boolean]" +`); }); describe('#validate', () => { diff --git a/packages/kbn-config-schema/src/types/duration_type.test.ts b/packages/kbn-config-schema/src/types/duration_type.test.ts index 57e917dc99b2b..2a0458f1419cc 100644 --- a/packages/kbn-config-schema/src/types/duration_type.test.ts +++ b/packages/kbn-config-schema/src/types/duration_type.test.ts @@ -35,11 +35,17 @@ test('handles number', () => { }); test('is required by default', () => { - expect(() => duration().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [moment.Duration] but got [undefined]"` + ); }); test('includes namespace in failure', () => { - expect(() => duration().validate(undefined, {}, 'foo-namespace')).toThrowErrorMatchingSnapshot(); + expect(() => + duration().validate(undefined, {}, 'foo-namespace') + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [moment.Duration] but got [undefined]"` + ); }); describe('#defaultValue', () => { @@ -48,7 +54,7 @@ describe('#defaultValue', () => { duration({ defaultValue: momentDuration(1, 'hour'), }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(`"PT1H"`); }); test('can be a string', () => { @@ -56,7 +62,7 @@ describe('#defaultValue', () => { duration({ defaultValue: '1h', }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(`"PT1H"`); }); test('can be a string-formatted number', () => { @@ -64,7 +70,7 @@ describe('#defaultValue', () => { duration({ defaultValue: '600', }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(`"PT0.6S"`); }); test('can be a number', () => { @@ -72,7 +78,7 @@ describe('#defaultValue', () => { duration({ defaultValue: 600, }).validate(undefined) - ).toMatchSnapshot(); + ).toMatchInlineSnapshot(`"PT0.6S"`); }); test('can be a function that returns compatible type', () => { @@ -103,12 +109,12 @@ describe('#defaultValue', () => { fromContext: duration({ defaultValue: contextRef('val') }), }).validate({}, { val: momentDuration(700, 'ms') }) ).toMatchInlineSnapshot(` -Object { - "fromContext": "PT0.7S", - "source": "PT0.6S", - "target": "PT0.6S", -} -`); + Object { + "fromContext": "PT0.7S", + "source": "PT0.6S", + "target": "PT0.6S", + } + `); expect( object({ @@ -117,12 +123,12 @@ Object { fromContext: duration({ defaultValue: contextRef('val') }), }).validate({}, { val: momentDuration(2, 'hour') }) ).toMatchInlineSnapshot(` -Object { - "fromContext": "PT2H", - "source": "PT1H", - "target": "PT1H", -} -`); + Object { + "fromContext": "PT2H", + "source": "PT1H", + "target": "PT1H", + } + `); expect( object({ @@ -131,29 +137,45 @@ Object { fromContext: duration({ defaultValue: contextRef('val') }), }).validate({}, { val: momentDuration(2, 'hour') }) ).toMatchInlineSnapshot(` -Object { - "fromContext": "PT2H", - "source": "PT1H", - "target": "PT1H", -} -`); + Object { + "fromContext": "PT2H", + "source": "PT1H", + "target": "PT1H", + } + `); }); }); test('returns error when not valid string or non-safe positive integer', () => { - expect(() => duration().validate(-123)).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate(-123)).toThrowErrorMatchingInlineSnapshot( + `"Value in milliseconds is expected to be a safe positive integer."` + ); - expect(() => duration().validate(NaN)).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate(NaN)).toThrowErrorMatchingInlineSnapshot( + `"Value in milliseconds is expected to be a safe positive integer."` + ); - expect(() => duration().validate(Infinity)).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate(Infinity)).toThrowErrorMatchingInlineSnapshot( + `"Value in milliseconds is expected to be a safe positive integer."` + ); - expect(() => duration().validate(Math.pow(2, 53))).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate(Math.pow(2, 53))).toThrowErrorMatchingInlineSnapshot( + `"Value in milliseconds is expected to be a safe positive integer."` + ); - expect(() => duration().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [moment.Duration] but got [Array]"` + ); - expect(() => duration().validate(/abc/)).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate(/abc/)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [moment.Duration] but got [RegExp]"` + ); - expect(() => duration().validate('123foo')).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate('123foo')).toThrowErrorMatchingInlineSnapshot( + `"Failed to parse value as time value. Value must be a duration in milliseconds, or follow the format [ms|s|m|h|d|w|M|Y] (e.g. '70ms', '5s', '3d', '1Y'), where the duration is a safe positive integer."` + ); - expect(() => duration().validate('123 456')).toThrowErrorMatchingSnapshot(); + expect(() => duration().validate('123 456')).toThrowErrorMatchingInlineSnapshot( + `"Failed to parse value as time value. Value must be a duration in milliseconds, or follow the format [ms|s|m|h|d|w|M|Y] (e.g. '70ms', '5s', '3d', '1Y'), where the duration is a safe positive integer."` + ); }); diff --git a/packages/kbn-config-schema/src/types/literal_type.test.ts b/packages/kbn-config-schema/src/types/literal_type.test.ts index a5ddff3152368..abcf5bb2a3b2d 100644 --- a/packages/kbn-config-schema/src/types/literal_type.test.ts +++ b/packages/kbn-config-schema/src/types/literal_type.test.ts @@ -38,17 +38,29 @@ test('handles null', () => { }); test('returns error when not correct', () => { - expect(() => literal('test').validate('foo')).toThrowErrorMatchingSnapshot(); + expect(() => literal('test').validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"expected value to equal [test]"` + ); - expect(() => literal(true).validate(false)).toThrowErrorMatchingSnapshot(); + expect(() => literal(true).validate(false)).toThrowErrorMatchingInlineSnapshot( + `"expected value to equal [true]"` + ); - expect(() => literal('test').validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => literal('test').validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value to equal [test]"` + ); - expect(() => literal(123).validate('abc')).toThrowErrorMatchingSnapshot(); + expect(() => literal(123).validate('abc')).toThrowErrorMatchingInlineSnapshot( + `"expected value to equal [123]"` + ); - expect(() => literal(null).validate(42)).toThrowErrorMatchingSnapshot(); + expect(() => literal(null).validate(42)).toThrowErrorMatchingInlineSnapshot( + `"expected value to equal [null]"` + ); }); test('includes namespace in failure', () => { - expect(() => literal('test').validate('foo', {}, 'foo-namespace')).toThrowErrorMatchingSnapshot(); + expect(() => + literal('test').validate('foo', {}, 'foo-namespace') + ).toThrowErrorMatchingInlineSnapshot(`"[foo-namespace]: expected value to equal [test]"`); }); diff --git a/packages/kbn-config-schema/src/types/literal_type.ts b/packages/kbn-config-schema/src/types/literal_type.ts index b5ddaa2f68d4f..5ba0b417683bd 100644 --- a/packages/kbn-config-schema/src/types/literal_type.ts +++ b/packages/kbn-config-schema/src/types/literal_type.ts @@ -29,7 +29,7 @@ export class LiteralType extends Type { switch (type) { case 'any.required': case 'any.allowOnly': - return `expected value to equal [${expectedValue}] but got [${value}]`; + return `expected value to equal [${expectedValue}]`; } } } diff --git a/packages/kbn-config-schema/src/types/map_of_type.test.ts b/packages/kbn-config-schema/src/types/map_of_type.test.ts index 3cb3d2d0b6862..b015f51bdc8ad 100644 --- a/packages/kbn-config-schema/src/types/map_of_type.test.ts +++ b/packages/kbn-config-schema/src/types/map_of_type.test.ts @@ -40,7 +40,7 @@ test('properly parse the value if input is a string', () => { test('fails if string input cannot be parsed', () => { const type = schema.mapOf(schema.string(), schema.string()); expect(() => type.validate(`invalidjson`)).toThrowErrorMatchingInlineSnapshot( - `"could not parse map value from [invalidjson]"` + `"could not parse map value from json input"` ); }); @@ -169,7 +169,7 @@ test('error preserves full path', () => { expect(() => type.validate({ grandParentKey: { parentKey: { a: 'some-value' } } }) ).toThrowErrorMatchingInlineSnapshot( - `"[grandParentKey.parentKey.key(\\"a\\")]: value is [a] but it must have a minimum length of [2]."` + `"[grandParentKey.parentKey.key(\\"a\\")]: value has length [1] but it must have a minimum length of [2]."` ); expect(() => diff --git a/packages/kbn-config-schema/src/types/map_type.ts b/packages/kbn-config-schema/src/types/map_type.ts index 1c0c473f98ec1..231c3726ae9d5 100644 --- a/packages/kbn-config-schema/src/types/map_type.ts +++ b/packages/kbn-config-schema/src/types/map_type.ts @@ -49,7 +49,7 @@ export class MapOfType extends Type> { case 'map.base': return `expected value of type [Map] or [object] but got [${typeDetect(value)}]`; case 'map.parse': - return `could not parse map value from [${value}]`; + return `could not parse map value from json input`; case 'map.key': case 'map.value': const childPathWithIndex = path.slice(); diff --git a/packages/kbn-config-schema/src/types/maybe_type.test.ts b/packages/kbn-config-schema/src/types/maybe_type.test.ts index c35fa18593520..2a1278f5e801c 100644 --- a/packages/kbn-config-schema/src/types/maybe_type.test.ts +++ b/packages/kbn-config-schema/src/types/maybe_type.test.ts @@ -42,23 +42,31 @@ test('returns undefined even if contained type has a default value', () => { test('validates contained type', () => { const type = schema.maybe(schema.string({ maxLength: 1 })); - expect(() => type.validate('foo')).toThrowErrorMatchingSnapshot(); + expect(() => type.validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"value has length [3] but it must have a maximum length of [1]."` + ); }); test('validates basic type', () => { const type = schema.maybe(schema.string()); - expect(() => type.validate(666)).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(666)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); }); test('fails if null', () => { const type = schema.maybe(schema.string()); - expect(() => type.validate(null)).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(null)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [null]"` + ); }); test('includes namespace in failure', () => { const type = schema.maybe(schema.string()); - expect(() => type.validate(null, {}, 'foo-namespace')).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(null, {}, 'foo-namespace')).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [string] but got [null]"` + ); }); describe('maybe + object', () => { diff --git a/packages/kbn-config-schema/src/types/never_type.test.ts b/packages/kbn-config-schema/src/types/never_type.test.ts index 46f0b47f56ad6..2e5bc0e8c672d 100644 --- a/packages/kbn-config-schema/src/types/never_type.test.ts +++ b/packages/kbn-config-schema/src/types/never_type.test.ts @@ -22,10 +22,18 @@ import { schema } from '..'; test('throws on any value set', () => { const type = schema.never(); - expect(() => type.validate(1)).toThrowErrorMatchingSnapshot(); - expect(() => type.validate('a')).toThrowErrorMatchingSnapshot(); - expect(() => type.validate(null)).toThrowErrorMatchingSnapshot(); - expect(() => type.validate({})).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(1)).toThrowErrorMatchingInlineSnapshot( + `"a value wasn't expected to be present"` + ); + expect(() => type.validate('a')).toThrowErrorMatchingInlineSnapshot( + `"a value wasn't expected to be present"` + ); + expect(() => type.validate(null)).toThrowErrorMatchingInlineSnapshot( + `"a value wasn't expected to be present"` + ); + expect(() => type.validate({})).toThrowErrorMatchingInlineSnapshot( + `"a value wasn't expected to be present"` + ); expect(() => type.validate(undefined)).not.toThrow(); }); @@ -37,7 +45,7 @@ test('throws on value set as object property', () => { expect(() => type.validate({ name: 'name', status: 'in progress' }) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"[name]: a value wasn't expected to be present"`); expect(() => type.validate({ status: 'in progress' })).not.toThrow(); expect(() => type.validate({ name: undefined, status: 'in progress' })).not.toThrow(); @@ -71,5 +79,5 @@ test('works for conditional types', () => { context_value_2: 1, } ) - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"[name]: a value wasn't expected to be present"`); }); diff --git a/packages/kbn-config-schema/src/types/nullable_type.test.ts b/packages/kbn-config-schema/src/types/nullable_type.test.ts index ed04202950a2c..fb9d544a3eb0e 100644 --- a/packages/kbn-config-schema/src/types/nullable_type.test.ts +++ b/packages/kbn-config-schema/src/types/nullable_type.test.ts @@ -94,13 +94,21 @@ test('returns null even if contained type has a default value', () => { test('validates contained type', () => { const type = schema.nullable(schema.string({ maxLength: 1 })); - expect(() => type.validate('foo')).toThrowErrorMatchingSnapshot(); + expect(() => type.validate('foo')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: value has length [3] but it must have a maximum length of [1]. +- [1]: expected value to equal [null]" +`); }); test('validates basic type', () => { const type = schema.nullable(schema.string()); - expect(() => type.validate(666)).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(666)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [string] but got [number] +- [1]: expected value to equal [null]" +`); }); test('validates type in object', () => { @@ -121,11 +129,19 @@ test('validates type errors in object', () => { bar: schema.nullable(schema.boolean()), }); - expect(() => type.validate({ foo: 'ab' })).toThrowErrorMatchingSnapshot(); + expect(() => type.validate({ foo: 'ab' })).toThrowErrorMatchingInlineSnapshot(` +"[foo]: types that failed validation: +- [foo.0]: value has length [2] but it must have a maximum length of [1]. +- [foo.1]: expected value to equal [null]" +`); }); test('includes namespace in failure', () => { const type = schema.nullable(schema.string({ maxLength: 1 })); - expect(() => type.validate('foo', {}, 'foo-namespace')).toThrowErrorMatchingSnapshot(); + expect(() => type.validate('foo', {}, 'foo-namespace')).toThrowErrorMatchingInlineSnapshot(` +"[foo-namespace]: types that failed validation: +- [foo-namespace.0]: value has length [3] but it must have a maximum length of [1]. +- [foo-namespace.1]: expected value to equal [null]" +`); }); diff --git a/packages/kbn-config-schema/src/types/number_type.test.ts b/packages/kbn-config-schema/src/types/number_type.test.ts index b85d5113563eb..cfcb0e99afbd5 100644 --- a/packages/kbn-config-schema/src/types/number_type.test.ts +++ b/packages/kbn-config-schema/src/types/number_type.test.ts @@ -32,17 +32,23 @@ test('handles numeric strings with floats', () => { }); test('fails if number is `NaN`', () => { - expect(() => schema.number().validate(NaN)).toThrowErrorMatchingSnapshot(); + expect(() => schema.number().validate(NaN)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [number] but got [number]"` + ); }); test('is required by default', () => { - expect(() => schema.number().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.number().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [number] but got [undefined]"` + ); }); test('includes namespace in failure', () => { expect(() => schema.number().validate(undefined, {}, 'foo-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [number] but got [undefined]"` + ); }); describe('#min', () => { @@ -51,7 +57,9 @@ describe('#min', () => { }); test('returns error when smaller number', () => { - expect(() => schema.number({ min: 4 }).validate(3)).toThrowErrorMatchingSnapshot(); + expect(() => schema.number({ min: 4 }).validate(3)).toThrowErrorMatchingInlineSnapshot( + `"Value must be equal to or greater than [4]."` + ); }); }); @@ -61,7 +69,9 @@ describe('#max', () => { }); test('returns error when larger number', () => { - expect(() => schema.number({ max: 2 }).validate(3)).toThrowErrorMatchingSnapshot(); + expect(() => schema.number({ max: 2 }).validate(3)).toThrowErrorMatchingInlineSnapshot( + `"Value must be equal to or lower than [2]."` + ); }); }); @@ -76,9 +86,15 @@ describe('#defaultValue', () => { }); test('returns error when not number or numeric string', () => { - expect(() => schema.number().validate('test')).toThrowErrorMatchingSnapshot(); + expect(() => schema.number().validate('test')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [number] but got [string]"` + ); - expect(() => schema.number().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => schema.number().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [number] but got [Array]"` + ); - expect(() => schema.number().validate(/abc/)).toThrowErrorMatchingSnapshot(); + expect(() => schema.number().validate(/abc/)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [number] but got [RegExp]"` + ); }); diff --git a/packages/kbn-config-schema/src/types/number_type.ts b/packages/kbn-config-schema/src/types/number_type.ts index ada4d1909c917..81ca4449122a3 100644 --- a/packages/kbn-config-schema/src/types/number_type.ts +++ b/packages/kbn-config-schema/src/types/number_type.ts @@ -46,9 +46,9 @@ export class NumberType extends Type { case 'number.base': return `expected value of type [number] but got [${typeDetect(value)}]`; case 'number.min': - return `Value is [${value}] but it must be equal to or greater than [${limit}].`; + return `Value must be equal to or greater than [${limit}].`; case 'number.max': - return `Value is [${value}] but it must be equal to or lower than [${limit}].`; + return `Value must be equal to or lower than [${limit}].`; } } } diff --git a/packages/kbn-config-schema/src/types/object_type.test.ts b/packages/kbn-config-schema/src/types/object_type.test.ts index 64739d7a4c4da..29e341983fde9 100644 --- a/packages/kbn-config-schema/src/types/object_type.test.ts +++ b/packages/kbn-config-schema/src/types/object_type.test.ts @@ -49,7 +49,7 @@ test('fails if string input cannot be parsed', () => { name: schema.string(), }); expect(() => type.validate(`invalidjson`)).toThrowErrorMatchingInlineSnapshot( - `"could not parse object value from [invalidjson]"` + `"could not parse object value from json input"` ); }); @@ -181,7 +181,7 @@ test('called with wrong type', () => { const type = schema.object({}); expect(() => type.validate('foo')).toThrowErrorMatchingInlineSnapshot( - `"could not parse object value from [foo]"` + `"could not parse object value from json input"` ); expect(() => type.validate(123)).toThrowErrorMatchingInlineSnapshot( `"expected a plain object value, but found [number] instead."` diff --git a/packages/kbn-config-schema/src/types/object_type.ts b/packages/kbn-config-schema/src/types/object_type.ts index 4f3d68a6bac97..f34acd0d2ce65 100644 --- a/packages/kbn-config-schema/src/types/object_type.ts +++ b/packages/kbn-config-schema/src/types/object_type.ts @@ -62,7 +62,7 @@ export class ObjectType

extends Type> case 'object.base': return `expected a plain object value, but found [${typeDetect(value)}] instead.`; case 'object.parse': - return `could not parse object value from [${value}]`; + return `could not parse object value from json input`; case 'object.allowUnknown': return `definition for this key is missing`; case 'object.child': diff --git a/packages/kbn-config-schema/src/types/one_of_type.test.ts b/packages/kbn-config-schema/src/types/one_of_type.test.ts index c9da1a6cd8494..deb87a485cdfe 100644 --- a/packages/kbn-config-schema/src/types/one_of_type.test.ts +++ b/packages/kbn-config-schema/src/types/one_of_type.test.ts @@ -75,13 +75,20 @@ test('handles object', () => { test('handles object with wrong type', () => { const type = schema.oneOf([schema.object({ age: schema.number() })]); - expect(() => type.validate({ age: 'foo' })).toThrowErrorMatchingSnapshot(); + expect(() => type.validate({ age: 'foo' })).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0.age]: expected value of type [number] but got [string]" +`); }); test('includes namespace in failure', () => { const type = schema.oneOf([schema.object({ age: schema.number() })]); - expect(() => type.validate({ age: 'foo' }, {}, 'foo-namespace')).toThrowErrorMatchingSnapshot(); + expect(() => type.validate({ age: 'foo' }, {}, 'foo-namespace')) + .toThrowErrorMatchingInlineSnapshot(` +"[foo-namespace]: types that failed validation: +- [foo-namespace.0.age]: expected value of type [number] but got [string]" +`); }); test('handles multiple objects with same key', () => { @@ -110,20 +117,33 @@ test('handles maybe', () => { test('fails if not matching type', () => { const type = schema.oneOf([schema.string()]); - expect(() => type.validate(false)).toThrowErrorMatchingSnapshot(); - expect(() => type.validate(123)).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(false)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [string] but got [boolean]" +`); + expect(() => type.validate(123)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [string] but got [number]" +`); }); test('fails if not matching multiple types', () => { const type = schema.oneOf([schema.string(), schema.number()]); - expect(() => type.validate(false)).toThrowErrorMatchingSnapshot(); + expect(() => type.validate(false)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [string] but got [boolean] +- [1]: expected value of type [number] but got [boolean]" +`); }); test('fails if not matching literal', () => { const type = schema.oneOf([schema.literal('foo')]); - expect(() => type.validate('bar')).toThrowErrorMatchingSnapshot(); + expect(() => type.validate('bar')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value to equal [foo]" +`); }); test('fails if nested union type fail', () => { @@ -138,7 +158,7 @@ test('fails if nested union type fail', () => { - [0]: expected value of type [boolean] but got [string] - [1]: types that failed validation: - [0]: types that failed validation: - - [0]: could not parse object value from [aaa] + - [0]: could not parse object value from json input - [1]: expected value of type [number] but got [string]" `); }); diff --git a/packages/kbn-config-schema/src/types/record_of_type.test.ts b/packages/kbn-config-schema/src/types/record_of_type.test.ts index f3ab1925597b5..ef15e7b0f6ad6 100644 --- a/packages/kbn-config-schema/src/types/record_of_type.test.ts +++ b/packages/kbn-config-schema/src/types/record_of_type.test.ts @@ -73,8 +73,8 @@ test('fails when not receiving expected key type', () => { expect(() => type.validate(value)).toThrowErrorMatchingInlineSnapshot(` "[key(\\"name\\")]: types that failed validation: -- [0]: expected value to equal [nickName] but got [name] -- [1]: expected value to equal [lastName] but got [name]" +- [0]: expected value to equal [nickName] +- [1]: expected value to equal [lastName]" `); }); @@ -88,8 +88,8 @@ test('fails after parsing when not receiving expected key type', () => { expect(() => type.validate(value)).toThrowErrorMatchingInlineSnapshot(` "[key(\\"name\\")]: types that failed validation: -- [0]: expected value to equal [nickName] but got [name] -- [1]: expected value to equal [lastName] but got [name]" +- [0]: expected value to equal [nickName] +- [1]: expected value to equal [lastName]" `); }); @@ -118,7 +118,7 @@ test('includes namespace in failure when wrong key type', () => { }; expect(() => type.validate(value, {}, 'foo-namespace')).toThrowErrorMatchingInlineSnapshot( - `"[foo-namespace.key(\\"name\\")]: value is [name] but it must have a minimum length of [10]."` + `"[foo-namespace.key(\\"name\\")]: value has length [4] but it must have a minimum length of [10]."` ); }); @@ -169,7 +169,7 @@ test('error preserves full path', () => { expect(() => type.validate({ grandParentKey: { parentKey: { a: 'some-value' } } }) ).toThrowErrorMatchingInlineSnapshot( - `"[grandParentKey.parentKey.key(\\"a\\")]: value is [a] but it must have a minimum length of [2]."` + `"[grandParentKey.parentKey.key(\\"a\\")]: value has length [1] but it must have a minimum length of [2]."` ); expect(() => diff --git a/packages/kbn-config-schema/src/types/record_type.ts b/packages/kbn-config-schema/src/types/record_type.ts index b795c83acdadb..c6d4b4d71b4f1 100644 --- a/packages/kbn-config-schema/src/types/record_type.ts +++ b/packages/kbn-config-schema/src/types/record_type.ts @@ -41,7 +41,7 @@ export class RecordOfType extends Type> { case 'record.base': return `expected value of type [object] but got [${typeDetect(value)}]`; case 'record.parse': - return `could not parse record value from [${value}]`; + return `could not parse record value from json input`; case 'record.key': case 'record.value': const childPathWithIndex = path.slice(); diff --git a/packages/kbn-config-schema/src/types/stream_type.test.ts b/packages/kbn-config-schema/src/types/stream_type.test.ts index 011fa6373df33..2e6f31ad09b34 100644 --- a/packages/kbn-config-schema/src/types/stream_type.test.ts +++ b/packages/kbn-config-schema/src/types/stream_type.test.ts @@ -41,13 +41,17 @@ test('Passthrough is valid', () => { }); test('is required by default', () => { - expect(() => schema.buffer().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.buffer().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Buffer] but got [undefined]"` + ); }); test('includes namespace in failure', () => { expect(() => schema.stream().validate(undefined, {}, 'foo-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [Stream] but got [undefined]"` + ); }); describe('#defaultValue', () => { @@ -63,9 +67,15 @@ describe('#defaultValue', () => { }); test('returns error when not a stream', () => { - expect(() => schema.stream().validate(123)).toThrowErrorMatchingSnapshot(); + expect(() => schema.stream().validate(123)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Stream] but got [number]"` + ); - expect(() => schema.stream().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => schema.stream().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Stream] but got [Array]"` + ); - expect(() => schema.stream().validate('abc')).toThrowErrorMatchingSnapshot(); + expect(() => schema.stream().validate('abc')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [Stream] but got [string]"` + ); }); diff --git a/packages/kbn-config-schema/src/types/string_type.test.ts b/packages/kbn-config-schema/src/types/string_type.test.ts index d599ea65c5ae2..c1d853fe82b82 100644 --- a/packages/kbn-config-schema/src/types/string_type.test.ts +++ b/packages/kbn-config-schema/src/types/string_type.test.ts @@ -28,13 +28,17 @@ test('allows empty strings', () => { }); test('is required by default', () => { - expect(() => schema.string().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.string().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [undefined]"` + ); }); test('includes namespace in failure', () => { expect(() => schema.string().validate(undefined, {}, 'foo-namespace') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"[foo-namespace]: expected value of type [string] but got [undefined]"` + ); }); describe('#minLength', () => { @@ -43,11 +47,17 @@ describe('#minLength', () => { }); test('returns error when shorter string', () => { - expect(() => schema.string({ minLength: 4 }).validate('foo')).toThrowErrorMatchingSnapshot(); + expect(() => + schema.string({ minLength: 4 }).validate('foo') + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [3] but it must have a minimum length of [4]."` + ); }); test('returns error when empty string', () => { - expect(() => schema.string({ minLength: 2 }).validate('')).toThrowErrorMatchingSnapshot(); + expect(() => schema.string({ minLength: 2 }).validate('')).toThrowErrorMatchingInlineSnapshot( + `"value has length [0] but it must have a minimum length of [2]."` + ); }); }); @@ -57,7 +67,11 @@ describe('#maxLength', () => { }); test('returns error when longer string', () => { - expect(() => schema.string({ maxLength: 2 }).validate('foo')).toThrowErrorMatchingSnapshot(); + expect(() => + schema.string({ maxLength: 2 }).validate('foo') + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [3] but it must have a maximum length of [2]."` + ); }); }); @@ -84,23 +98,37 @@ describe('#hostname', () => { test('returns error when value is not a valid hostname', () => { const hostNameSchema = schema.string({ hostname: true }); - expect(() => hostNameSchema.validate('host:name')).toThrowErrorMatchingSnapshot(); - expect(() => hostNameSchema.validate('localhost:5601')).toThrowErrorMatchingSnapshot(); - expect(() => hostNameSchema.validate('-')).toThrowErrorMatchingSnapshot(); - expect(() => hostNameSchema.validate('0:?:0:0:0:0:0:1')).toThrowErrorMatchingSnapshot(); + expect(() => hostNameSchema.validate('host:name')).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid hostname (see RFC 1123)."` + ); + expect(() => hostNameSchema.validate('localhost:5601')).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid hostname (see RFC 1123)."` + ); + expect(() => hostNameSchema.validate('-')).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid hostname (see RFC 1123)."` + ); + expect(() => hostNameSchema.validate('0:?:0:0:0:0:0:1')).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid hostname (see RFC 1123)."` + ); const tooLongHostName = 'a'.repeat(256); - expect(() => hostNameSchema.validate(tooLongHostName)).toThrowErrorMatchingSnapshot(); + expect(() => hostNameSchema.validate(tooLongHostName)).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid hostname (see RFC 1123)."` + ); }); test('returns error when empty string', () => { - expect(() => schema.string({ hostname: true }).validate('')).toThrowErrorMatchingSnapshot(); + expect(() => schema.string({ hostname: true }).validate('')).toThrowErrorMatchingInlineSnapshot( + `"any.empty"` + ); }); test('supports string validation rules', () => { expect(() => schema.string({ hostname: true, maxLength: 3 }).validate('www.example.com') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot( + `"value has length [15] but it must have a maximum length of [3]."` + ); }); }); @@ -146,20 +174,30 @@ describe('#validate', () => { test('throws when returns string', () => { const validate = () => 'validator failure'; - expect(() => schema.string({ validate }).validate('foo')).toThrowErrorMatchingSnapshot(); + expect(() => schema.string({ validate }).validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"validator failure"` + ); }); test('throw when empty string', () => { const validate = () => 'validator failure'; - expect(() => schema.string({ validate }).validate('')).toThrowErrorMatchingSnapshot(); + expect(() => schema.string({ validate }).validate('')).toThrowErrorMatchingInlineSnapshot( + `"validator failure"` + ); }); }); test('returns error when not string', () => { - expect(() => schema.string().validate(123)).toThrowErrorMatchingSnapshot(); + expect(() => schema.string().validate(123)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); - expect(() => schema.string().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => schema.string().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [Array]"` + ); - expect(() => schema.string().validate(/abc/)).toThrowErrorMatchingSnapshot(); + expect(() => schema.string().validate(/abc/)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [RegExp]"` + ); }); diff --git a/packages/kbn-config-schema/src/types/string_type.ts b/packages/kbn-config-schema/src/types/string_type.ts index 6d5fa93c0299c..7f49440b8d7e2 100644 --- a/packages/kbn-config-schema/src/types/string_type.ts +++ b/packages/kbn-config-schema/src/types/string_type.ts @@ -45,7 +45,7 @@ export class StringType extends Type { if (options.minLength !== undefined) { schema = schema.custom(value => { if (value.length < options.minLength!) { - return `value is [${value}] but it must have a minimum length of [${options.minLength}].`; + return `value has length [${value.length}] but it must have a minimum length of [${options.minLength}].`; } }); } @@ -53,7 +53,7 @@ export class StringType extends Type { if (options.maxLength !== undefined) { schema = schema.custom(value => { if (value.length > options.maxLength!) { - return `value is [${value}] but it must have a maximum length of [${options.maxLength}].`; + return `value has length [${value.length}] but it must have a maximum length of [${options.maxLength}].`; } }); } @@ -66,7 +66,7 @@ export class StringType extends Type { case 'any.required': return `expected value of type [string] but got [${typeDetect(value)}]`; case 'string.hostname': - return `value is [${value}] but it must be a valid hostname (see RFC 1123).`; + return `value must be a valid hostname (see RFC 1123).`; } } } diff --git a/packages/kbn-config-schema/src/types/uri_type.test.ts b/packages/kbn-config-schema/src/types/uri_type.test.ts index 1345b47a63c1f..72e5ca6f7171e 100644 --- a/packages/kbn-config-schema/src/types/uri_type.test.ts +++ b/packages/kbn-config-schema/src/types/uri_type.test.ts @@ -20,7 +20,9 @@ import { schema } from '..'; test('is required by default', () => { - expect(() => schema.uri().validate(undefined)).toThrowErrorMatchingSnapshot(); + expect(() => schema.uri().validate(undefined)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [undefined]."` + ); }); test('returns value for valid URI as per RFC3986', () => { @@ -54,17 +56,23 @@ test('returns value for valid URI as per RFC3986', () => { test('returns error when value is not a URI', () => { const uriSchema = schema.uri(); - expect(() => uriSchema.validate('3domain.local')).toThrowErrorMatchingSnapshot(); + expect(() => uriSchema.validate('3domain.local')).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid URI (see RFC 3986)."` + ); expect(() => uriSchema.validate('http://8010:0:0:0:9:500:300C:200A') - ).toThrowErrorMatchingSnapshot(); - expect(() => uriSchema.validate('-')).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"value must be a valid URI (see RFC 3986)."`); + expect(() => uriSchema.validate('-')).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid URI (see RFC 3986)."` + ); expect(() => uriSchema.validate('https://example.com?baz[]=foo&baz[]=bar') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"value must be a valid URI (see RFC 3986)."`); const tooLongUri = `http://${'a'.repeat(256)}`; - expect(() => uriSchema.validate(tooLongUri)).toThrowErrorMatchingSnapshot(); + expect(() => uriSchema.validate(tooLongUri)).toThrowErrorMatchingInlineSnapshot( + `"value must be a valid URI (see RFC 3986)."` + ); }); describe('#scheme', () => { @@ -78,8 +86,12 @@ describe('#scheme', () => { test('returns error when shorter string', () => { const uriSchema = schema.uri({ scheme: ['http', 'https'] }); - expect(() => uriSchema.validate('ftp://elastic.co')).toThrowErrorMatchingSnapshot(); - expect(() => uriSchema.validate('file:///kibana.log')).toThrowErrorMatchingSnapshot(); + expect(() => uriSchema.validate('ftp://elastic.co')).toThrowErrorMatchingInlineSnapshot( + `"expected URI with scheme [http|https]."` + ); + expect(() => uriSchema.validate('file:///kibana.log')).toThrowErrorMatchingInlineSnapshot( + `"expected URI with scheme [http|https]."` + ); }); }); @@ -131,14 +143,20 @@ describe('#validate', () => { expect(() => schema.uri({ validate }).validate('http://kibana.local') - ).toThrowErrorMatchingSnapshot(); + ).toThrowErrorMatchingInlineSnapshot(`"validator failure"`); }); }); test('returns error when not string', () => { - expect(() => schema.uri().validate(123)).toThrowErrorMatchingSnapshot(); + expect(() => schema.uri().validate(123)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]."` + ); - expect(() => schema.uri().validate([1, 2, 3])).toThrowErrorMatchingSnapshot(); + expect(() => schema.uri().validate([1, 2, 3])).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [Array]."` + ); - expect(() => schema.uri().validate(/abc/)).toThrowErrorMatchingSnapshot(); + expect(() => schema.uri().validate(/abc/)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [RegExp]."` + ); }); diff --git a/packages/kbn-config-schema/src/types/uri_type.ts b/packages/kbn-config-schema/src/types/uri_type.ts index df1ce9e869d3b..f365ed35e3579 100644 --- a/packages/kbn-config-schema/src/types/uri_type.ts +++ b/packages/kbn-config-schema/src/types/uri_type.ts @@ -36,9 +36,9 @@ export class URIType extends Type { case 'string.base': return `expected value of type [string] but got [${typeDetect(value)}].`; case 'string.uriCustomScheme': - return `expected URI with scheme [${scheme}] but got [${value}].`; + return `expected URI with scheme [${scheme}].`; case 'string.uri': - return `value is [${value}] but it must be a valid URI (see RFC 3986).`; + return `value must be a valid URI (see RFC 3986).`; } } } diff --git a/src/core/server/http/__snapshots__/http_config.test.ts.snap b/src/core/server/http/__snapshots__/http_config.test.ts.snap index 28933a035c870..07c153a7a8a20 100644 --- a/src/core/server/http/__snapshots__/http_config.test.ts.snap +++ b/src/core/server/http/__snapshots__/http_config.test.ts.snap @@ -87,7 +87,7 @@ exports[`throws if basepath is missing prepended slash 1`] = `"[basePath]: must exports[`throws if basepath is not specified, but rewriteBasePath is set 1`] = `"cannot use [rewriteBasePath] when [basePath] is not specified"`; -exports[`throws if invalid hostname 1`] = `"[host]: value is [asdf$%^] but it must be a valid hostname (see RFC 1123)."`; +exports[`throws if invalid hostname 1`] = `"[host]: value must be a valid hostname (see RFC 1123)."`; exports[`with TLS throws if TLS is enabled but \`redirectHttpFromPort\` is equal to \`port\` 1`] = `"Kibana does not accept http traffic to [port] when ssl is enabled (only https is allowed), so [ssl.redirectHttpFromPort] cannot be configured to the same value. Both are [1234]."`; @@ -100,7 +100,7 @@ Array [ ] `; -exports[`with compression throws if invalid referrer whitelist 1`] = `"[compression.referrerWhitelist.0]: value is [asdf$%^] but it must be a valid hostname (see RFC 1123)."`; +exports[`with compression throws if invalid referrer whitelist 1`] = `"[compression.referrerWhitelist.0]: value must be a valid hostname (see RFC 1123)."`; exports[`with compression throws if invalid referrer whitelist 2`] = `"[compression.referrerWhitelist]: array size is [0], but cannot be smaller than [1]"`; diff --git a/src/core/server/http/ssl_config.test.ts b/src/core/server/http/ssl_config.test.ts index 738f86f7a69eb..3980b9c247fa3 100644 --- a/src/core/server/http/ssl_config.test.ts +++ b/src/core/server/http/ssl_config.test.ts @@ -293,16 +293,16 @@ describe('#sslSchema', () => { expect(() => sslSchema.validate(singleUnknownProtocol)).toThrowErrorMatchingInlineSnapshot(` "[supportedProtocols.0]: types that failed validation: -- [supportedProtocols.0.0]: expected value to equal [TLSv1] but got [SOMEv100500] -- [supportedProtocols.0.1]: expected value to equal [TLSv1.1] but got [SOMEv100500] -- [supportedProtocols.0.2]: expected value to equal [TLSv1.2] but got [SOMEv100500]" +- [supportedProtocols.0.0]: expected value to equal [TLSv1] +- [supportedProtocols.0.1]: expected value to equal [TLSv1.1] +- [supportedProtocols.0.2]: expected value to equal [TLSv1.2]" `); expect(() => sslSchema.validate(allKnownWithOneUnknownProtocols)) .toThrowErrorMatchingInlineSnapshot(` "[supportedProtocols.3]: types that failed validation: -- [supportedProtocols.3.0]: expected value to equal [TLSv1] but got [SOMEv100500] -- [supportedProtocols.3.1]: expected value to equal [TLSv1.1] but got [SOMEv100500] -- [supportedProtocols.3.2]: expected value to equal [TLSv1.2] but got [SOMEv100500]" +- [supportedProtocols.3.0]: expected value to equal [TLSv1] +- [supportedProtocols.3.1]: expected value to equal [TLSv1.1] +- [supportedProtocols.3.2]: expected value to equal [TLSv1.2]" `); }); }); diff --git a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js b/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js index 10a5de2c2aa77..2b687a70a6461 100644 --- a/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js +++ b/test/api_integration/apis/index_patterns/fields_for_time_pattern_route/query_params.js @@ -93,7 +93,7 @@ export default function({ getService }) { .expect(400) .then(resp => { expect(resp.body.message).to.contain( - '[request query.look_back]: Value is [0] but it must be equal to or greater than [1].' + '[request query.look_back]: Value must be equal to or greater than [1].' ); })); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts b/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts index 646ea168b52a5..0be1983477256 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts @@ -76,7 +76,7 @@ describe('config validation', () => { }).toThrowErrorMatchingInlineSnapshot(` "error validating action type config: [index]: types that failed validation: - [index.0]: expected value of type [string] but got [number] -- [index.1]: expected value to equal [null] but got [666]" +- [index.1]: expected value to equal [null]" `); }); }); @@ -150,7 +150,7 @@ describe('params validation', () => { expect(() => { validateParams(actionType, { documents: ['should be an object'] }); }).toThrowErrorMatchingInlineSnapshot( - `"error validating action params: [documents.0]: could not parse record value from [should be an object]"` + `"error validating action params: [documents.0]: could not parse record value from json input"` ); }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts index ab860e4c3bbba..caa183d665e09 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts @@ -137,9 +137,9 @@ describe('validateParams()', () => { validateParams(actionType, { eventAction: 'ackynollage' }); }).toThrowErrorMatchingInlineSnapshot(` "error validating action params: [eventAction]: types that failed validation: -- [eventAction.0]: expected value to equal [trigger] but got [ackynollage] -- [eventAction.1]: expected value to equal [resolve] but got [ackynollage] -- [eventAction.2]: expected value to equal [acknowledge] but got [ackynollage]" +- [eventAction.0]: expected value to equal [trigger] +- [eventAction.1]: expected value to equal [resolve] +- [eventAction.2]: expected value to equal [acknowledge]" `); }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/server_log.test.ts b/x-pack/plugins/actions/server/builtin_action_types/server_log.test.ts index 6a4482f362c2b..bb806f8ae36fc 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/server_log.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/server_log.test.ts @@ -63,24 +63,24 @@ describe('validateParams()', () => { validateParams(actionType, { message: 'x', level: 2 }); }).toThrowErrorMatchingInlineSnapshot(` "error validating action params: [level]: types that failed validation: -- [level.0]: expected value to equal [trace] but got [2] -- [level.1]: expected value to equal [debug] but got [2] -- [level.2]: expected value to equal [info] but got [2] -- [level.3]: expected value to equal [warn] but got [2] -- [level.4]: expected value to equal [error] but got [2] -- [level.5]: expected value to equal [fatal] but got [2]" +- [level.0]: expected value to equal [trace] +- [level.1]: expected value to equal [debug] +- [level.2]: expected value to equal [info] +- [level.3]: expected value to equal [warn] +- [level.4]: expected value to equal [error] +- [level.5]: expected value to equal [fatal]" `); expect(() => { validateParams(actionType, { message: 'x', level: 'foo' }); }).toThrowErrorMatchingInlineSnapshot(` "error validating action params: [level]: types that failed validation: -- [level.0]: expected value to equal [trace] but got [foo] -- [level.1]: expected value to equal [debug] but got [foo] -- [level.2]: expected value to equal [info] but got [foo] -- [level.3]: expected value to equal [warn] but got [foo] -- [level.4]: expected value to equal [error] but got [foo] -- [level.5]: expected value to equal [fatal] but got [foo]" +- [level.0]: expected value to equal [trace] +- [level.1]: expected value to equal [debug] +- [level.2]: expected value to equal [info] +- [level.3]: expected value to equal [warn] +- [level.4]: expected value to equal [error] +- [level.5]: expected value to equal [fatal]" `); }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts b/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts index e553e5c83712a..d8f75de781841 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts @@ -104,8 +104,8 @@ describe('config validation', () => { validateConfig(actionType, config); }).toThrowErrorMatchingInlineSnapshot(` "error validating action type config: [method]: types that failed validation: -- [method.0]: expected value to equal [post] but got [https] -- [method.1]: expected value to equal [put] but got [https]" +- [method.0]: expected value to equal [post] +- [method.1]: expected value to equal [put]" `); }); @@ -141,8 +141,8 @@ describe('config validation', () => { validateConfig(actionType, config); }).toThrowErrorMatchingInlineSnapshot(` "error validating action type config: [headers]: types that failed validation: -- [headers.0]: could not parse record value from [application/json] -- [headers.1]: expected value to equal [null] but got [application/json]" +- [headers.0]: could not parse record value from json input +- [headers.1]: expected value to equal [null]" `); }); diff --git a/x-pack/plugins/alerting_builtins/server/alert_types/index_threshold/lib/core_query_types.test.ts b/x-pack/plugins/alerting_builtins/server/alert_types/index_threshold/lib/core_query_types.test.ts index d67d29cacde42..109785b835bdf 100644 --- a/x-pack/plugins/alerting_builtins/server/alert_types/index_threshold/lib/core_query_types.test.ts +++ b/x-pack/plugins/alerting_builtins/server/alert_types/index_threshold/lib/core_query_types.test.ts @@ -64,15 +64,15 @@ export function runTests(schema: ObjectType, defaultTypeParams: Record { expect(() => ConfigSchema.validate({ encryptionKey: 'foo' }) ).toThrowErrorMatchingInlineSnapshot( - `"[encryptionKey]: value is [foo] but it must have a minimum length of [32]."` + `"[encryptionKey]: value has length [3] but it must have a minimum length of [32]."` ); expect(() => ConfigSchema.validate({ encryptionKey: 'foo' }, { dist: true }) ).toThrowErrorMatchingInlineSnapshot( - `"[encryptionKey]: value is [foo] but it must have a minimum length of [32]."` + `"[encryptionKey]: value has length [3] but it must have a minimum length of [32]."` ); }); }); diff --git a/x-pack/plugins/security/server/config.test.ts b/x-pack/plugins/security/server/config.test.ts index b93770470c964..8532622906ffe 100644 --- a/x-pack/plugins/security/server/config.test.ts +++ b/x-pack/plugins/security/server/config.test.ts @@ -106,13 +106,13 @@ describe('config schema', () => { expect(() => ConfigSchema.validate({ encryptionKey: 'foo' }) ).toThrowErrorMatchingInlineSnapshot( - `"[encryptionKey]: value is [foo] but it must have a minimum length of [32]."` + `"[encryptionKey]: value has length [3] but it must have a minimum length of [32]."` ); expect(() => ConfigSchema.validate({ encryptionKey: 'foo' }, { dist: true }) ).toThrowErrorMatchingInlineSnapshot( - `"[encryptionKey]: value is [foo] but it must have a minimum length of [32]."` + `"[encryptionKey]: value has length [3] but it must have a minimum length of [32]."` ); }); @@ -134,15 +134,15 @@ describe('config schema', () => { expect(() => ConfigSchema.validate({ public: { protocol: 'ftp' } })) .toThrowErrorMatchingInlineSnapshot(` "[public.protocol]: types that failed validation: -- [public.protocol.0]: expected value to equal [http] but got [ftp] -- [public.protocol.1]: expected value to equal [https] but got [ftp]" +- [public.protocol.0]: expected value to equal [http] +- [public.protocol.1]: expected value to equal [https]" `); expect(() => ConfigSchema.validate({ public: { protocol: 'some-protocol' } })) .toThrowErrorMatchingInlineSnapshot(` "[public.protocol]: types that failed validation: -- [public.protocol.0]: expected value to equal [http] but got [some-protocol] -- [public.protocol.1]: expected value to equal [https] but got [some-protocol]" +- [public.protocol.0]: expected value to equal [http] +- [public.protocol.1]: expected value to equal [https]" `); }); @@ -170,13 +170,13 @@ describe('config schema', () => { expect(() => ConfigSchema.validate({ public: { hostname: 'http://elastic.co' } }) ).toThrowErrorMatchingInlineSnapshot( - `"[public.hostname]: value is [http://elastic.co] but it must be a valid hostname (see RFC 1123)."` + `"[public.hostname]: value must be a valid hostname (see RFC 1123)."` ); expect(() => ConfigSchema.validate({ public: { hostname: 'localhost:5601' } }) ).toThrowErrorMatchingInlineSnapshot( - `"[public.hostname]: value is [localhost:5601] but it must be a valid hostname (see RFC 1123)."` + `"[public.hostname]: value must be a valid hostname (see RFC 1123)."` ); }); @@ -202,13 +202,13 @@ describe('config schema', () => { expect(() => ConfigSchema.validate({ public: { port: -1 } }) ).toThrowErrorMatchingInlineSnapshot( - `"[public.port]: Value is [-1] but it must be equal to or greater than [0]."` + `"[public.port]: Value must be equal to or greater than [0]."` ); expect(() => ConfigSchema.validate({ public: { port: 65536 } }) ).toThrowErrorMatchingInlineSnapshot( - `"[public.port]: Value is [65536] but it must be equal to or lower than [65535]."` + `"[public.port]: Value must be equal to or lower than [65535]."` ); expect(() => diff --git a/x-pack/plugins/security/server/routes/authentication/basic.test.ts b/x-pack/plugins/security/server/routes/authentication/basic.test.ts index 694d0fca97a2c..cd3b871671551 100644 --- a/x-pack/plugins/security/server/routes/authentication/basic.test.ts +++ b/x-pack/plugins/security/server/routes/authentication/basic.test.ts @@ -85,17 +85,17 @@ describe('Basic authentication routes', () => { expect(() => bodyValidator.validate({ username: '', password: '' }) ).toThrowErrorMatchingInlineSnapshot( - `"[username]: value is [] but it must have a minimum length of [1]."` + `"[username]: value has length [0] but it must have a minimum length of [1]."` ); expect(() => bodyValidator.validate({ username: 'user', password: '' }) ).toThrowErrorMatchingInlineSnapshot( - `"[password]: value is [] but it must have a minimum length of [1]."` + `"[password]: value has length [0] but it must have a minimum length of [1]."` ); expect(() => bodyValidator.validate({ username: '', password: 'password' }) ).toThrowErrorMatchingInlineSnapshot( - `"[username]: value is [] but it must have a minimum length of [1]."` + `"[username]: value has length [0] but it must have a minimum length of [1]."` ); }); diff --git a/x-pack/plugins/security/server/routes/authorization/roles/model/put_payload.test.ts b/x-pack/plugins/security/server/routes/authorization/roles/model/put_payload.test.ts index e9ba5c41c3988..acde73dcd8190 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/model/put_payload.test.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/model/put_payload.test.ts @@ -104,7 +104,7 @@ describe('Put payload schema', () => { }) ).toThrowErrorMatchingInlineSnapshot(` "[kibana.0.spaces]: types that failed validation: -- [kibana.0.spaces.0.0]: expected value to equal [*] but got [foo-*] +- [kibana.0.spaces.0.0]: expected value to equal [*] - [kibana.0.spaces.1.0]: must be lower case, a-z, 0-9, '_', and '-' are allowed" `); }); @@ -116,7 +116,7 @@ describe('Put payload schema', () => { }) ).toThrowErrorMatchingInlineSnapshot(` "[kibana.0.spaces]: types that failed validation: -- [kibana.0.spaces.0.1]: expected value to equal [*] but got [foo-space] +- [kibana.0.spaces.0.1]: expected value to equal [*] - [kibana.0.spaces.1.0]: must be lower case, a-z, 0-9, '_', and '-' are allowed" `); }); diff --git a/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts b/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts index d19debe692460..62b49f0c4e7f0 100644 --- a/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts +++ b/x-pack/plugins/security/server/routes/authorization/roles/put.test.ts @@ -124,7 +124,7 @@ describe('PUT role', () => { expect(() => requestParamsSchema.validate({ name: '' }, {}, 'request params') ).toThrowErrorMatchingInlineSnapshot( - `"[request params.name]: value is [] but it must have a minimum length of [1]."` + `"[request params.name]: value has length [0] but it must have a minimum length of [1]."` ); }); @@ -132,7 +132,7 @@ describe('PUT role', () => { expect(() => requestParamsSchema.validate({ name: 'a'.repeat(1025) }, {}, 'request params') ).toThrowErrorMatchingInlineSnapshot( - `"[request params.name]: value is [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] but it must have a maximum length of [1024]."` + `"[request params.name]: value has length [1025] but it must have a maximum length of [1024]."` ); }); }); diff --git a/x-pack/plugins/security/server/routes/users/change_password.test.ts b/x-pack/plugins/security/server/routes/users/change_password.test.ts index b40a4e406205c..c2db34dc3c33c 100644 --- a/x-pack/plugins/security/server/routes/users/change_password.test.ts +++ b/x-pack/plugins/security/server/routes/users/change_password.test.ts @@ -82,12 +82,12 @@ describe('Change password', () => { `"[username]: expected value of type [string] but got [undefined]"` ); expect(() => paramsSchema.validate({ username: '' })).toThrowErrorMatchingInlineSnapshot( - `"[username]: value is [] but it must have a minimum length of [1]."` + `"[username]: value has length [0] but it must have a minimum length of [1]."` ); expect(() => paramsSchema.validate({ username: 'a'.repeat(1025) }) ).toThrowErrorMatchingInlineSnapshot( - `"[username]: value is [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] but it must have a maximum length of [1024]."` + `"[username]: value has length [1025] but it must have a maximum length of [1024]."` ); const bodySchema = (routeConfig.validate as any).body as ObjectType; @@ -95,12 +95,12 @@ describe('Change password', () => { `"[newPassword]: expected value of type [string] but got [undefined]"` ); expect(() => bodySchema.validate({ newPassword: '' })).toThrowErrorMatchingInlineSnapshot( - `"[newPassword]: value is [] but it must have a minimum length of [1]."` + `"[newPassword]: value has length [0] but it must have a minimum length of [1]."` ); expect(() => bodySchema.validate({ newPassword: '123456', password: '' }) ).toThrowErrorMatchingInlineSnapshot( - `"[password]: value is [] but it must have a minimum length of [1]."` + `"[password]: value has length [0] but it must have a minimum length of [1]."` ); }); diff --git a/x-pack/plugins/spaces/server/lib/space_schema.test.ts b/x-pack/plugins/spaces/server/lib/space_schema.test.ts index 6330fcef19e8d..3a4bc080f5a9b 100644 --- a/x-pack/plugins/spaces/server/lib/space_schema.test.ts +++ b/x-pack/plugins/spaces/server/lib/space_schema.test.ts @@ -93,7 +93,7 @@ describe('#disabledFeatures', () => { disabledFeatures: 'foo', }) ).toThrowErrorMatchingInlineSnapshot( - `"[disabledFeatures]: could not parse array value from [foo]"` + `"[disabledFeatures]: could not parse array value from json input"` ); }); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/es_index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/es_index.ts index aacf0b8f87ed0..1aa0f8e2c9f16 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/es_index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/es_index.ts @@ -111,7 +111,7 @@ export default function indexTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - 'error validating action type config: [index]: types that failed validation:\n- [index.0]: expected value of type [string] but got [number]\n- [index.1]: expected value to equal [null] but got [666]', + 'error validating action type config: [index]: types that failed validation:\n- [index.0]: expected value of type [string] but got [number]\n- [index.1]: expected value to equal [null]', }); }); }); diff --git a/x-pack/test/api_integration/apis/endpoint/alerts.ts b/x-pack/test/api_integration/apis/endpoint/alerts.ts index 45ae2b5438e18..1890b6f5d557d 100644 --- a/x-pack/test/api_integration/apis/endpoint/alerts.ts +++ b/x-pack/test/api_integration/apis/endpoint/alerts.ts @@ -70,7 +70,7 @@ export default function({ getService }: FtrProviderContext) { .get('/api/endpoint/alerts?page_size=0') .set('kbn-xsrf', 'xxx') .expect(400); - expect(body.message).to.contain('Value is [0] but it must be equal to or greater than [1]'); + expect(body.message).to.contain('Value must be equal to or greater than [1]'); }); it('alerts api should return links to the next and previous pages using cursor-based pagination', async () => { diff --git a/x-pack/test/api_integration/apis/endpoint/metadata.ts b/x-pack/test/api_integration/apis/endpoint/metadata.ts index 4b0cc8d93a395..516891d84dc91 100644 --- a/x-pack/test/api_integration/apis/endpoint/metadata.ts +++ b/x-pack/test/api_integration/apis/endpoint/metadata.ts @@ -100,7 +100,7 @@ export default function({ getService }: FtrProviderContext) { ], }) .expect(400); - expect(body.message).to.contain('Value is [0] but it must be equal to or greater than [1]'); + expect(body.message).to.contain('Value must be equal to or greater than [1]'); }); it('metadata api should return page based on filters passed.', async () => { diff --git a/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js b/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js index e1a435e000fae..cbf44e07ac40a 100644 --- a/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js +++ b/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js @@ -78,7 +78,7 @@ export default function({ getService }) { uri = `${BASE_URI}?${stringify(params, { sort: false })}`; ({ body } = await supertest.get(uri).expect(400)); expect(body.message).to.contain( - '[request query.meta_fields]: could not parse array value from [stringValue]' + '[request query.meta_fields]: could not parse array value from json input' ); });