Skip to content

Commit

Permalink
fix: throw error on sparse arrays (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Aug 7, 2019
1 parent ff781d7 commit b85ac38
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validate.js
Expand Up @@ -24,7 +24,7 @@ function validate(schema, options, configuration = {}) {
let errors = [];

if (Array.isArray(options)) {
errors = options.map((nestedOptions) =>
errors = Array.from(options).map((nestedOptions) =>
validateObject(schema, nestedOptions)
);

Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/index.test.js.snap
Expand Up @@ -639,6 +639,12 @@ exports[`Validation should fail validation for formatMinimum 1`] = `
- configuration.formatMinimumKeyword should be >= \\"2016-02-06\\"."
`;
exports[`Validation should fail validation for holey array 1`] = `
"Invalid configuration object. Object has been initialised using a configuration object that does not match the API schema.
- configuration[1] should be an object:
object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, mode?, module?, name?, node?, optimization?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions?, minLengthOne?, minLengthTwo?, integerType?, nullType?, allOfRef?, customObject?, objectType?, anyOfKeyword?, nestedArrayWithoutItems?, nestedObjectWithoutItems?, arrayType?, arrayType2?, multipleTypes?, zeroMaxItems?, multipleContains?, multipleContains2?, exclusiveMinimumKeyword?, exclusiveMaximumKeyword?, uniqueItemsKeyword?, minPropertiesKeyword?, maxPropertiesKeyword?, requiredKeyword?, requiredKeywordWithAdditionalProperties?, enumKeyword?, formatMinimumKeyword?, formatMaximumKeyword?, formatExclusiveMinimumKeyword?, formatExclusiveMaximumKeyword?, formatMinMaxExclusiveMinKeyword?, formatMinMaxExclusiveMaxKeyword?, minItemsKeyword?, maxItemsKeyword?, itemsKeyword?, itemsKeyword2?, additionalItemsKeyword?, additionalItemsKeyword2?, additionalItemsKeyword3?, additionalItemsKeyword4?, propertiesKeyword?, patternPropertiesKeyword?, patternPropertiesKeyword2?, arrayWithOnlyNumber?, onlyRequired?, dependenciesKeyword?, dependenciesKeyword2?, patternRequiredKeyword?, patternRequiredKeyword2?, onlyProperties?, onlyProperties2?, onlyItems?, onlyItems2?, onlyAdditionalItems?, booleanType?, additionalPropertiesKeyword?, additionalPropertiesKeyword2?, propertyNamesKeyword?, constKeyword?, constKeyword2?, ifThenElseKeyword?, ifThenElseKeyword2?, stringKeyword?, arrayKeyword?, arrayKeyword2?, arrayKeyword3?, arrayKeyword4?, arrayKeyword5?, arrayKeyword6?, arrayKeyword7?, arrayKeyword8?, arrayKeyword9?, arrayKeyword10?, arrayKeyword11?, arrayKeyword12?, arrayKeyword13?, arrayKeyword14?, arrayKeyword15?, arrayKeyword16?, arrayKeyword17?, arrayKeyword18?, arrayKeyword19?, recursion?, extending?, longString?, integerWithMinimum?, integerWithExclusiveMinimum?, integerWithExclusiveMaximum?, numberWithMinimum?, multipleOfProp?, stringWithMinAndMaxLength?, strictFormat?, strictFormat2?, uniqueItemsProp?, numberAndDescription?, oneOfnumberAndDescriptionAndArray?, maxPropertiesAndMinProperties?, objectTest?, objectTest2?, objectTest3?, objectTest4?, objectTest5?, objectTest6?, objectTest7?, objectTest8?, objectTest9?, stringWithEmptyPattern?, likeArray?, arrayWithEmptyItemsAndEmptyAdditionalItemsAndEmptyContains?, numberWithoutType?, numberWithoutType2?, stringWithoutType?, arrayWithoutType?, additionalItemsFalse?, requiredWithoutType?, dependenciesWithoutType?, propertyNamesWithoutType?, patternRequiredWithoutType?, additionalPropertiesWithoutType?, maxPropertiesWithoutType?, justAnObject?, arrayWithAbsolutePath?, allOfKeyword?, enumWithDescription?, constWithDescription?, itemsTrue?, emptyConst?, oneConst?, constWithEmptyString?, refAndAnyOf?, additionalPropertiesInsideOneOf?, additionalPropertiesInsideOneOf2?, singleContainsItems?, objectWithPropertyDependency?, objectWithPropertyDependency2?, objectWithPropertyDependency3?, objectWithPropertyDependency4?, oneOfWithIf?, constWithArrayNotation?, constWithObjectNotation?, additionalItemsWithoutType?, additionalItemsWithoutType2?, additionalItemsWithoutType3?, containsAndAdditionalItems?, containsInsideItem?, emptyObject?, nonEmptyObject?, nonEmptyObject2? }"
`;
exports[`Validation should fail validation for if/then/else #2 1`] = `
"Invalid configuration object. Object has been initialised using a configuration object that does not match the API schema.
- configuration.ifThenElseKeyword should match \\"then\\" schema:
Expand Down
15 changes: 15 additions & 0 deletions test/index.test.js
Expand Up @@ -2165,4 +2165,19 @@ describe('Validation', () => {
},
(msg) => expect(msg).toMatchSnapshot()
);

createFailedTestCase(
'holey array',
// eslint-disable-next-line no-sparse-arrays
[
{
mode: 'production',
},
,
{
mode: 'development',
},
],
(msg) => expect(msg).toMatchSnapshot()
);
});

0 comments on commit b85ac38

Please sign in to comment.