"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/angular_devkit/core/src/json/schema/registry_spec.ts" between
angular-cli-12.0.3.tar.gz and angular-cli-12.0.4.tar.gz

About: Angular CLI is a command line interface for Angular.

registry_spec.ts  (angular-cli-12.0.3):registry_spec.ts  (angular-cli-12.0.4)
skipping to change at line 12 skipping to change at line 12
* @license * @license
* Copyright Google LLC All Rights Reserved. * Copyright Google LLC All Rights Reserved.
* *
* Use of this source code is governed by an MIT-style license that can be * Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
import { map, mergeMap } from 'rxjs/operators'; import { map, mergeMap } from 'rxjs/operators';
import { SchemaFormat } from './interface'; import { SchemaFormat } from './interface';
import { CoreSchemaRegistry } from './registry'; import { CoreSchemaRegistry, SchemaValidationException } from './registry';
import { addUndefinedDefaults } from './transforms'; import { addUndefinedDefaults } from './transforms';
describe('CoreSchemaRegistry', () => { describe('CoreSchemaRegistry', () => {
it('works asynchronously', (done) => { it('works asynchronously', (done) => {
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
registry.addPostTransform(addUndefinedDefaults); registry.addPostTransform(addUndefinedDefaults);
const data: any = {}; const data: any = {};
registry registry
.compile({ .compile({
properties: { properties: {
bool: { type: 'boolean' }, bool: { type: 'boolean' },
str: { type: 'string', default: 'someString' }, str: { type: 'string', default: 'someString' },
obj: { obj: {
properties: { properties: {
num: { type: 'number' }, num: { type: 'number' },
other: { type: 'number', default: 0 }, other: { type: 'number', default: 0 },
}, },
}, },
tslint: { tslint: {
$ref: 'https://json.schemastore.org/tslint#', $ref: 'https://json.schemastore.org/npm-link-up#',
}, },
}, },
}) })
.pipe( .pipe(
mergeMap((validator) => validator(data)), mergeMap((validator) => validator(data)),
map((result) => { map((result) => {
expect(result.success).toBe(true); expect(result.success).toBe(true);
expect(data.obj.num).toBeUndefined(); expect(data.obj.num).toBeUndefined();
expect(data.tslint).not.toBeUndefined(); expect(data.tslint).not.toBeUndefined();
}), }),
skipping to change at line 133 skipping to change at line 133
properties: { properties: {
num: { type: 'number' }, num: { type: 'number' },
}, },
additionalProperties: false, additionalProperties: false,
}) })
.pipe( .pipe(
mergeMap((validator) => validator(data)), mergeMap((validator) => validator(data)),
map((result) => { map((result) => {
expect(result.success).toBe(false); expect(result.success).toBe(false);
expect(result.errors && result.errors[0].message).toContain( expect(result.errors && result.errors[0].message).toContain(
'should NOT have additional properties', 'must NOT have additional properties',
);
}),
)
.toPromise()
.then(done, done.fail);
});
it('fails on invalid enum value', (done) => {
const registry = new CoreSchemaRegistry();
registry.addPostTransform(addUndefinedDefaults);
const data = { packageManager: 'foo' };
registry
.compile({
properties: {
packageManager: { type: 'string', enum: ['npm', 'yarn', 'pnpm', 'cnpm'
] },
},
additionalProperties: false,
})
.pipe(
mergeMap((validator) => validator(data)),
map((result) => {
expect(result.success).toBe(false);
expect(new SchemaValidationException(result.errors).message).toContain
(
`Data path "/packageManager" must be equal to one of the allowed val
ues. Allowed values are: "npm", "yarn", "pnpm", "cnpm".`,
); );
}), }),
) )
.toPromise() .toPromise()
.then(done, done.fail); .then(done, done.fail);
}); });
it('fails on invalid additionalProperties async', (done) => { it('fails on invalid additionalProperties async', (done) => {
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
registry.addPostTransform(addUndefinedDefaults); registry.addPostTransform(addUndefinedDefaults);
skipping to change at line 158 skipping to change at line 183
$async: true, $async: true,
properties: { properties: {
num: { type: 'number' }, num: { type: 'number' },
}, },
additionalProperties: false, additionalProperties: false,
}) })
.pipe( .pipe(
mergeMap((validator) => validator(data)), mergeMap((validator) => validator(data)),
map((result) => { map((result) => {
expect(result.success).toBe(false); expect(result.success).toBe(false);
expect(result.errors && result.errors[0].message).toContain( expect(result.errors?.[0].message).toContain('must NOT have additional
'should NOT have additional properties', properties');
); expect(result.errors?.[0].keyword).toBe('additionalProperties');
expect(result.errors && result.errors[0].keyword).toBe('additionalProp
erties');
}), }),
) )
.toPromise() .toPromise()
.then(done, done.fail); .then(done, done.fail);
}); });
it('supports sync format', (done) => { it('supports sync format', (done) => {
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
const data = { str: 'hotdog' }; const data = { str: 'hotdog' };
const format = { const format = {
skipping to change at line 227 skipping to change at line 250
.pipe( .pipe(
mergeMap((validator) => validator(data)), mergeMap((validator) => validator(data)),
map((result) => { map((result) => {
expect(result.success).toBe(true); expect(result.success).toBe(true);
}), }),
) )
.toPromise() .toPromise()
.then(done, done.fail); .then(done, done.fail);
}); });
it('shows dataPath and message on error', (done) => { it('shows dataPath and message on error', async () => {
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
const data = { hotdot: 'hotdog', banana: 'banana' }; const data = { hotdot: 'hotdog', banana: 'banana' };
const format: SchemaFormat = { const format: SchemaFormat = {
name: 'is-hotdog', name: 'is-hotdog',
formatter: { formatter: {
async: false, async: false,
validate: (str: string) => str === 'hotdog', validate: (str: string) => str === 'hotdog',
}, },
}; };
registry.addFormat(format); registry.addFormat(format);
registry await registry
.compile({ .compile({
properties: { properties: {
hotdot: { type: 'string', format: 'is-hotdog' }, hotdot: { type: 'string', format: 'is-hotdog' },
banana: { type: 'string', format: 'is-hotdog' }, banana: { type: 'string', format: 'is-hotdog' },
}, },
}) })
.pipe( .pipe(
mergeMap((validator) => validator(data)), mergeMap((validator) => validator(data)),
map((result) => { map((result) => {
expect(result.success).toBe(false); expect(result.success).toBe(false);
expect(result.errors && result.errors[0]).toBeTruthy(); expect(result.errors && result.errors[0]).toBeTruthy();
expect(result.errors && result.errors[0].keyword).toBe('format'); expect(result.errors && result.errors[0].keyword).toBe('format');
expect(result.errors && result.errors[0].instancePath).toBe('.banana') ; expect(result.errors && result.errors[0].instancePath).toBe('/banana') ;
expect(result.errors && (result.errors[0].params as any).format).toBe( 'is-hotdog'); expect(result.errors && (result.errors[0].params as any).format).toBe( 'is-hotdog');
}), }),
) )
.toPromise() .toPromise();
.then(done, done.fail);
}); });
it('supports smart defaults', (done) => { it('supports smart defaults', (done) => {
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
const data: any = { const data: any = {
arr: [{}], arr: [{}],
}; };
registry.addSmartDefaultProvider('test', (schema) => { registry.addSmartDefaultProvider('test', (schema) => {
expect(schema).toEqual({ expect(schema).toEqual({
 End of changes. 8 change blocks. 
13 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)