This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved validation error messages (#339)
- Loading branch information
1 parent
d016daa
commit 705eed4
Showing
10 changed files
with
1,201 additions
and
891 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
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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
module.exports = { | ||
ignore: ['package-lock.json', 'CHANGELOG.md'], | ||
linters: { | ||
'*.js': ['prettier --write', 'eslint --fix', 'git add'], | ||
'*.{json,md,yml,css}': ['prettier --write', 'git add'], | ||
}, | ||
'*.js': ['prettier --write', 'eslint --fix', 'git add'], | ||
'*.{json,md,yml,css}': ['prettier --write', 'git add'], | ||
}; |
Large diffs are not rendered by default.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`validate options 1`] = ` | ||
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. | ||
- options.name should be one of these: | ||
string | function | ||
-> The filename template for the target file(s) (https://github.com/webpack-contrib/file-loader#name). | ||
Details: | ||
* options.name should be a string. | ||
* options.name should be an instance of function." | ||
`; | ||
|
||
exports[`validate options 2`] = ` | ||
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. | ||
- options.outputPath should be one of these: | ||
string | function | ||
-> A filesystem path where the target file(s) will be placed (https://github.com/webpack-contrib/file-loader#outputpath). | ||
Details: | ||
* options.outputPath should be a string. | ||
* options.outputPath should be an instance of function." | ||
`; | ||
|
||
exports[`validate options 3`] = ` | ||
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. | ||
- options.publicPath should be one of these: | ||
string | function | ||
-> A custom public path for the target file(s) (https://github.com/webpack-contrib/file-loader#publicpath). | ||
Details: | ||
* options.publicPath should be a string. | ||
* options.publicPath should be an instance of function." | ||
`; | ||
|
||
exports[`validate options 4`] = ` | ||
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. | ||
- options.context should be a string. | ||
-> A custom file context (https://github.com/webpack-contrib/file-loader#context)." | ||
`; | ||
|
||
exports[`validate options 5`] = ` | ||
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. | ||
- options.emitFile should be a boolean. | ||
-> Enables/Disables emit files (https://github.com/webpack-contrib/file-loader#emitfile)." | ||
`; | ||
|
||
exports[`validate options 6`] = ` | ||
"Invalid options object. File Loader has been initialised using an options object that does not match the API schema. | ||
- options.regExp should be one of these: | ||
string | RegExp | ||
-> A Regular Expression to one or many parts of the target file path. The capture groups can be reused in the name property using [N] placeholder (https://github.com/webpack-contrib/file-loader#regexp). | ||
Details: | ||
* options.regExp should be a string. | ||
* options.regExp should be an instance of RegExp." | ||
`; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import loader from '../src'; | ||
|
||
it('validate options', () => { | ||
const validate = (options) => | ||
loader.call( | ||
Object.assign( | ||
{}, | ||
{ | ||
resourcePath: 'image.png', | ||
query: options, | ||
emitFile: () => {}, | ||
} | ||
), | ||
'a { color: red; }' | ||
); | ||
|
||
expect(() => validate()).not.toThrow(); | ||
|
||
// The `file-loader` loader can be used as `fallback` loader and options can contain not only `file-loader` options | ||
// so we use `additionalProperties: false` to avoid problems. | ||
expect(() => validate({ limit: 8192 })).not.toThrow(); | ||
|
||
expect(() => validate({ name: '[path][name].[ext]' })).not.toThrow(); | ||
expect(() => | ||
validate({ | ||
name: () => '[hash].[ext]', | ||
}) | ||
).not.toThrow(); | ||
expect(() => validate({ name: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ outputPath: 'assets' })).not.toThrow(); | ||
expect(() => | ||
validate({ | ||
outputPath: () => 'assets', | ||
}) | ||
).not.toThrow(); | ||
expect(() => validate({ outputPath: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ publicPath: 'assets' })).not.toThrow(); | ||
expect(() => | ||
validate({ | ||
publicPath: () => 'assets', | ||
}) | ||
).not.toThrow(); | ||
expect(() => validate({ publicPath: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ context: 'assets' })).not.toThrow(); | ||
expect(() => validate({ context: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ emitFile: true })).not.toThrow(); | ||
expect(() => validate({ emitFile: false })).not.toThrow(); | ||
expect(() => validate({ emitFile: 'true' })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ regExp: /image\.png/ })).not.toThrow(); | ||
expect(() => validate({ regExp: 'image\\.png' })).not.toThrow(); | ||
expect(() => validate({ regExp: true })).toThrowErrorMatchingSnapshot(); | ||
|
||
expect(() => validate({ unknown: 'unknown' })).not.toThrow(); | ||
}); |