-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validate loader options (#737)
- Loading branch information
1 parent
9c5028b
commit 7b543fc
Showing
8 changed files
with
190 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"implementation": { | ||
"description": "The implementation of the sass to be used (https://github.com/webpack-contrib/sass-loader#implementation)." | ||
}, | ||
"sassOptions": { | ||
"description": "Options for `node-sass` or `sass` (`Dart Sass`) implementation. (https://github.com/webpack-contrib/sass-loader#implementation).", | ||
"anyOf": [ | ||
{ | ||
"type": "object", | ||
"additionalProperties": true | ||
}, | ||
{ | ||
"instanceof": "Function" | ||
} | ||
] | ||
}, | ||
"prependData": { | ||
"description": "Prepends `Sass`/`SCSS` code before the actual entry file (https://github.com/webpack-contrib/sass-loader#prependdata).", | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"instanceof": "Function" | ||
} | ||
] | ||
}, | ||
"sourceMap": { | ||
"description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/sass-loader#sourcemap).", | ||
"type": "boolean" | ||
}, | ||
"webpackImporter": { | ||
"description": "Enables/Disables default `webpack` importer (https://github.com/webpack-contrib/sass-loader#webpackimporter).", | ||
"type": "boolean" | ||
} | ||
}, | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`validate options 1`] = ` | ||
"Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema. | ||
- options.sassOptions should be one of these: | ||
object { … } | function | ||
-> Options for \`node-sass\` or \`sass\` (\`Dart Sass\`) implementation. (https://github.com/webpack-contrib/sass-loader#implementation). | ||
Details: | ||
* options.sassOptions should be an object: | ||
object { … } | ||
* options.sassOptions should be an instance of function." | ||
`; | ||
|
||
exports[`validate options 2`] = ` | ||
"Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema. | ||
- options.prependData should be one of these: | ||
string | function | ||
-> Prepends \`Sass\`/\`SCSS\` code before the actual entry file (https://github.com/webpack-contrib/sass-loader#prependdata). | ||
Details: | ||
* options.prependData should be a string. | ||
* options.prependData should be an instance of function." | ||
`; | ||
|
||
exports[`validate options 3`] = ` | ||
"Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema. | ||
- options.webpackImporter should be a boolean. | ||
-> Enables/Disables default \`webpack\` importer (https://github.com/webpack-contrib/sass-loader#webpackimporter)." | ||
`; | ||
|
||
exports[`validate options 4`] = ` | ||
"Invalid options object. Sass Loader has been initialised using an options object that does not match the API schema. | ||
- options has an unknown property 'unknown'. These properties are valid: | ||
object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import loader from '../src/cjs'; | ||
|
||
it('validate options', () => { | ||
const validate = (options) => | ||
loader.call( | ||
Object.assign( | ||
{}, | ||
{ | ||
query: options, | ||
loaders: [], | ||
resourcePath: 'file.scss', | ||
getResolve: () => () => {}, | ||
async: () => (error) => { | ||
if (error) { | ||
throw error; | ||
} | ||
}, | ||
} | ||
), | ||
'a { color: red; }' | ||
); | ||
|
||
// eslint-disable-next-line global-require | ||
// expect(() => validate({ implementation: require('node-sass') })).not.toThrow(); | ||
// eslint-disable-next-line global-require | ||
// expect(() => validate({ implementation: require('sass') })).not.toThrow(); | ||
// expect(() => validate({ implementation: true })).not.toThrow(); | ||
|
||
expect(() => validate({ sassOptions: {} })).not.toThrow(); | ||
expect(() => | ||
validate({ | ||
sassOptions: () => { | ||
return {}; | ||
}, | ||
}) | ||
).not.toThrow(); | ||
expect(() => validate({ sassOptions: () => {} })).not.toThrow(); | ||
expect(() => validate({ sassOptions: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ prependData: '$color: red;' })).not.toThrow(); | ||
expect(() => validate({ prependData: () => '$color: red;' })).not.toThrow(); | ||
expect(() => validate({ prependData: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ webpackImporter: true })).not.toThrow(); | ||
expect(() => validate({ webpackImporter: false })).not.toThrow(); | ||
expect(() => | ||
validate({ webpackImporter: 'unknown' }) | ||
).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ unknown: 'unknown' })).toThrowErrorMatchingSnapshot(); | ||
}); |