From 8b13bc3a55ae5c55c7360c76be4d00a5ed297a27 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 9 Dec 2019 16:48:33 +0300 Subject: [PATCH] refactor: improve schema --- src/options.json | 12 ++++++++- .../validate-options.test.js.snap | 22 ++++++++++++++++ test/validate-options.test.js | 25 ++++++++++++++++++- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/options.json b/src/options.json index cc3109ac..32c36b89 100644 --- a/src/options.json +++ b/src/options.json @@ -37,7 +37,17 @@ "type": "boolean" }, "ignore": { - "type": "array" + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "object" + } + ] + } }, "flatten": { "type": "boolean" diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap index b5f2747d..f67994ef 100644 --- a/test/__snapshots__/validate-options.test.js.snap +++ b/test/__snapshots__/validate-options.test.js.snap @@ -45,6 +45,28 @@ options.0 should match some schema in anyOf " `; +exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","ignore":["test.txt",true]}]" value 1`] = ` +"CopyPlugin Invalid Options + +options.0 should be string +options.0.ignore.1 should be string +options.0.ignore.1 should be object +options.0.ignore.1 should match some schema in anyOf +options.0 should match some schema in anyOf +" +`; + +exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","ignore":[true]}]" value 1`] = ` +"CopyPlugin Invalid Options + +options.0 should be string +options.0.ignore.0 should be string +options.0.ignore.0 should be object +options.0.ignore.0 should match some schema in anyOf +options.0 should match some schema in anyOf +" +`; + exports[`validate options should throw an error on the "patterns" option with "[{"from":"test.txt","to":"dir","context":"context","ignore":true}]" value 1`] = ` "CopyPlugin Invalid Options diff --git a/test/validate-options.test.js b/test/validate-options.test.js index 0afaaa0e..696a8e2a 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -55,7 +55,14 @@ describe('validate options', () => { toType: 'file', test: /test/, force: true, - ignore: ['ignore-1', 'ignore-2'], + ignore: [ + 'ignore-1', + 'ignore-2', + { + dot: false, + glob: '**/*', + }, + ], flatten: true, cache: true, transform: () => {}, @@ -179,6 +186,22 @@ describe('validate options', () => { ignore: true, }, ], + [ + { + from: 'test.txt', + to: 'dir', + context: 'context', + ignore: [true], + }, + ], + [ + { + from: 'test.txt', + to: 'dir', + context: 'context', + ignore: ['test.txt', true], + }, + ], [ { from: 'test.txt',