-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration validation and refactor unknown identifiers
- Loading branch information
Showing
7 changed files
with
566 additions
and
128 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
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,45 @@ | ||
import { validate, getDefaultConfig } from '../configurationSchema.js'; | ||
|
||
it('should export defaults as an object', () => { | ||
const config = getDefaultConfig(); | ||
|
||
expect(config.aliases).toEqual({}); | ||
}); | ||
|
||
it('should validate successfully', () => { | ||
const result = validate({ | ||
aliases: { | ||
_: 'third-party-libs/underscore', | ||
}, | ||
}); | ||
expect(result.error).toEqual(false); | ||
expect(result.messages).toEqual([]); | ||
}); | ||
|
||
it('should notify about unknown identifiers, and remove them', () => { | ||
const data = { | ||
thisAintRight: 'better fail', | ||
}; | ||
const result = validate(data); | ||
expect(result.error).toEqual(true); | ||
expect(result.messages[0]).toEqual('Unknown configuration: `thisAintRight`'); | ||
expect(data.hasOwnProperty('thisAintRight')).toBe(false); | ||
}); | ||
|
||
it('should handle functions', () => { | ||
const result = validate({ | ||
aliases: () => ({ _: 'third-party-libs/underscore' }), | ||
}); | ||
expect(result.error).toEqual(false); | ||
}); | ||
|
||
it('should notify about invalid identifiers, and remove them', () => { | ||
const data = { | ||
aliases: 123, | ||
}; | ||
const result = validate(data); | ||
expect(result.error).toEqual(true); | ||
expect(result.messages.length).toEqual(1); | ||
expect(result.messages[0]).toEqual('Invalid configuration: `aliases`'); | ||
expect(data.hasOwnProperty('aliases')).toBe(false); | ||
}); |
Oops, something went wrong.