Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: full coverage schema options validation #8

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ new TerserPlugin({

### `extractComments`

Type: `Boolean|String|RegExp|Function<(node, comment) -> Boolean|Object>`
Type: `Boolean|String|RegExp|Function<(node, comment) -> Boolean|Object>|Object`
Default: `false`

Whether comments shall be extracted to a separate file, (see [details](https://github.com/webpack/webpack/commit/71933e979e51c533b432658d5e37917f9e71595a)).
Expand Down Expand Up @@ -362,7 +362,7 @@ new TerserPlugin({

##### `filename`

Type: `Regex|Function<(string) -> String>`
Type: `String|Function<(string) -> String>`
Default: `${file}.LICENSE`

The file where the extracted comments will be stored.
Expand Down
150 changes: 142 additions & 8 deletions src/options.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,91 @@
{
"type": "object",
"additionalProperties": false,
"definitions": {
"file-conditions": {
"anyOf": [
{
"instanceof": "RegExp"
},
{
"type": "string"
}
]
}
},
"properties": {
"test": {},
"include": {},
"exclude": {},
"test": {
"anyOf": [
{
"$ref": "#/definitions/file-conditions"
},
{
"items": {
"anyOf": [
{
"$ref": "#/definitions/file-conditions"
}
]
},
"type": "array"
}
]
},
"include": {
"anyOf": [
{
"$ref": "#/definitions/file-conditions"
},
{
"items": {
"anyOf": [
{
"$ref": "#/definitions/file-conditions"
}
]
},
"type": "array"
}
]
},
"exclude": {
"anyOf": [
{
"$ref": "#/definitions/file-conditions"
},
{
"items": {
"anyOf": [
{
"$ref": "#/definitions/file-conditions"
}
]
},
"type": "array"
}
]
},
"cache": {
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
"anyOf": [
{
"type": "boolean"
},
{
"type": "string"
}
]
},
"cacheKeys": {
"instanceof": "Function"
},
"parallel": {
"oneOf": [{ "type": "boolean" }, { "type": "integer" }]
"anyOf": [
{
"type": "boolean"
},
{
"type": "integer"
}
]
},
"sourceMap": {
"type": "boolean"
Expand All @@ -23,10 +97,70 @@
"additionalProperties": true,
"type": "object"
},
"extractComments": {},
"extractComments": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string"
},
{
"instanceof": "RegExp"
},
{
"instanceof": "Function"
},
{
"additionalProperties": false,
"properties": {
"condition": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string"
},
{
"instanceof": "RegExp"
},
{
"instanceof": "Function"
}
]
},
"filename": {
"anyOf": [
{
"type": "string"
},
{
"instanceof": "Function"
}
]
},
"banner": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "string"
},
{
"instanceof": "Function"
}
]
}
},
"type": "object"
}
]
},
"warningsFilter": {
"instanceof": "Function"
}
},
"additionalProperties": false
"type": "object"
}
164 changes: 155 additions & 9 deletions test/__snapshots__/validation.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,200 @@
exports[`validation 1`] = `
"Terser Plugin Invalid Options

options should NOT have additional properties
options.test should pass \\"instanceof\\" keyword validation
options.test should be string
options.test should match some schema in anyOf
options.test should be array
options.test should match some schema in anyOf
"
`;

exports[`validation 2`] = `
"Terser Plugin Invalid Options

options.test should pass \\"instanceof\\" keyword validation
options.test should be string
options.test should match some schema in anyOf
options.test.0 should pass \\"instanceof\\" keyword validation
options.test.0 should be string
options.test.0 should match some schema in anyOf
options.test.0 should match some schema in anyOf
options.test should match some schema in anyOf
"
`;

exports[`validation 3`] = `
"Terser Plugin Invalid Options

options.include should pass \\"instanceof\\" keyword validation
options.include should be string
options.include should match some schema in anyOf
options.include should be array
options.include should match some schema in anyOf
"
`;

exports[`validation 4`] = `
"Terser Plugin Invalid Options

options.include should pass \\"instanceof\\" keyword validation
options.include should be string
options.include should match some schema in anyOf
options.include.0 should pass \\"instanceof\\" keyword validation
options.include.0 should be string
options.include.0 should match some schema in anyOf
options.include.0 should match some schema in anyOf
options.include should match some schema in anyOf
"
`;

exports[`validation 5`] = `
"Terser Plugin Invalid Options

options.exclude should pass \\"instanceof\\" keyword validation
options.exclude should be string
options.exclude should match some schema in anyOf
options.exclude should be array
options.exclude should match some schema in anyOf
"
`;

exports[`validation 6`] = `
"Terser Plugin Invalid Options

options.exclude should pass \\"instanceof\\" keyword validation
options.exclude should be string
options.exclude should match some schema in anyOf
options.exclude.0 should pass \\"instanceof\\" keyword validation
options.exclude.0 should be string
options.exclude.0 should match some schema in anyOf
options.exclude.0 should match some schema in anyOf
options.exclude should match some schema in anyOf
"
`;

exports[`validation 7`] = `
"Terser Plugin Invalid Options

options.cache should be boolean
options.cache should be string
options.cache should match exactly one schema in oneOf
options.cache should match some schema in anyOf
"
`;

exports[`validation 3`] = `
exports[`validation 8`] = `
"Terser Plugin Invalid Options

options.cacheKeys should pass \\"instanceof\\" keyword validation
"
`;

exports[`validation 9`] = `
"Terser Plugin Invalid Options

options.parallel should be boolean
options.parallel should be integer
options.parallel should match exactly one schema in oneOf
options.parallel should match some schema in anyOf
"
`;

exports[`validation 4`] = `
exports[`validation 10`] = `
"Terser Plugin Invalid Options

options.parallel should be boolean
options.parallel should be integer
options.parallel should match exactly one schema in oneOf
options.parallel should match some schema in anyOf
"
`;

exports[`validation 5`] = `
exports[`validation 11`] = `
"Terser Plugin Invalid Options

options.sourceMap should be boolean
"
`;

exports[`validation 6`] = `
exports[`validation 12`] = `
"Terser Plugin Invalid Options

options.minify should pass \\"instanceof\\" keyword validation
"
`;

exports[`validation 13`] = `
"Terser Plugin Invalid Options

options.terserOptions should be object
"
`;

exports[`validation 7`] = `
exports[`validation 14`] = `
"Terser Plugin Invalid Options

options.extractComments should be boolean
options.extractComments should be string
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments.condition should be boolean
options.extractComments.condition should be string
options.extractComments.condition should pass \\"instanceof\\" keyword validation
options.extractComments.condition should pass \\"instanceof\\" keyword validation
options.extractComments.condition should match some schema in anyOf
options.extractComments should match some schema in anyOf
"
`;

exports[`validation 15`] = `
"Terser Plugin Invalid Options

options.extractComments should be boolean
options.extractComments should be string
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments.filename should be string
options.extractComments.filename should pass \\"instanceof\\" keyword validation
options.extractComments.filename should match some schema in anyOf
options.extractComments should match some schema in anyOf
"
`;

exports[`validation 16`] = `
"Terser Plugin Invalid Options

options.extractComments should be boolean
options.extractComments should be string
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments.banner should be boolean
options.extractComments.banner should be string
options.extractComments.banner should pass \\"instanceof\\" keyword validation
options.extractComments.banner should match some schema in anyOf
options.extractComments should match some schema in anyOf
"
`;

exports[`validation 17`] = `
"Terser Plugin Invalid Options

options.extractComments should be boolean
options.extractComments should be string
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments should pass \\"instanceof\\" keyword validation
options.extractComments should NOT have additional properties
options.extractComments should match some schema in anyOf
"
`;

exports[`validation 18`] = `
"Terser Plugin Invalid Options

options.warningsFilter should pass \\"instanceof\\" keyword validation
"
`;

exports[`validation 19`] = `
"Terser Plugin Invalid Options

options should NOT have additional properties
"
`;
Loading