-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): validate style value before proceeding with app/lib/compo…
…nent generate (#1725)
- Loading branch information
Showing
5 changed files
with
52 additions
and
6 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,22 @@ | ||
import { assertValidStyle } from './assertion'; | ||
|
||
describe('assertValidStyle', () => { | ||
it('should accept style option values from app, lib, component schematics', () => { | ||
const schemas = [ | ||
require('../schematics/application/schema.json'), | ||
require('../schematics/component/schema.json'), | ||
require('../schematics/library/schema.json') | ||
]; | ||
|
||
schemas.forEach(schema => { | ||
const values = schema.properties.style['x-prompt'].items; | ||
expect(() => | ||
values.forEach(value => assertValidStyle(value)).not.toThrow() | ||
); | ||
}); | ||
}); | ||
|
||
it('should throw for invalid values', () => { | ||
expect(() => assertValidStyle('bad')).toThrow(/Unsupported/); | ||
}); | ||
}); |
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,17 @@ | ||
const VALID_STYLES = [ | ||
'css', | ||
'scss', | ||
'less', | ||
'styl', | ||
'styled-components', | ||
'@emotion/styled' | ||
]; | ||
export function assertValidStyle(style: string): void { | ||
if (VALID_STYLES.indexOf(style) === -1) { | ||
throw new Error( | ||
`Unsupported style option found: ${style}. Valid values are: "${VALID_STYLES.join( | ||
'", "' | ||
)}"` | ||
); | ||
} | ||
} |