Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { JsonObject, schema } from '@angular-devkit/core';
import yargs from 'yargs';

import { addSchemaOptionsToCommand, parseJsonSchemaToOptions } from './json-schema';
import { Option, addSchemaOptionsToCommand, parseJsonSchemaToOptions } from './json-schema';

describe('parseJsonSchemaToOptions', () => {
describe('without required fields in schema', () => {
Expand All @@ -21,10 +21,9 @@ describe('parseJsonSchemaToOptions', () => {
};

let localYargs: yargs.Argv<unknown>;
beforeEach(async () => {
// Create a fresh yargs for each call. The yargs object is stateful and
// calling .parse multiple times on the same instance isn't safe.
localYargs = yargs().exitProcess(false).strict().fail(false).wrap(1_000);
let options: Option[];

beforeAll(async () => {
const jsonSchema = {
'type': 'object',
'properties': {
Expand Down Expand Up @@ -118,12 +117,20 @@ describe('parseJsonSchemaToOptions', () => {
},
},
};

const registry = new schema.CoreSchemaRegistry();
const options = await parseJsonSchemaToOptions(
options = await parseJsonSchemaToOptions(
registry,
jsonSchema as unknown as JsonObject,
false,
);
});

beforeEach(async () => {
// Create a fresh yargs for each call. The yargs object is stateful and
// calling .parse multiple times on the same instance isn't safe.
localYargs = yargs().exitProcess(false).strict().fail(false).wrap(1_000);

addSchemaOptionsToCommand(localYargs, options, true);
});

Expand All @@ -138,7 +145,15 @@ describe('parseJsonSchemaToOptions', () => {
});

describe('type=array, enum', () => {
it('parses valid option value', async () => {
it('parses valid option value when specified once', async () => {
expect(await parse(['--arrayWithChoices', 'always', 'never'])).toEqual(
jasmine.objectContaining({
'arrayWithChoices': ['always', 'never'],
}),
);
});

it('parses valid option value when specified multiple times', async () => {
expect(
await parse(['--arrayWithChoices', 'always', '--arrayWithChoices', 'never']),
).toEqual(
Expand All @@ -160,7 +175,15 @@ describe('parseJsonSchemaToOptions', () => {
});

describe('type=array, enum in oneOf', () => {
it('parses valid option value', async () => {
it('parses valid option value when specified once', async () => {
expect(await parse(['--arrayWithChoicesInOneOf', 'default', 'verbose'])).toEqual(
jasmine.objectContaining({
'arrayWithChoicesInOneOf': ['default', 'verbose'],
}),
);
});

it('parses valid option value when specified multiple times', async () => {
expect(
await parse([
'--arrayWithChoicesInOneOf',
Expand All @@ -183,7 +206,15 @@ describe('parseJsonSchemaToOptions', () => {
});

describe('type=array, anyOf', () => {
it('parses valid option value', async () => {
it('parses valid option value when specified once', async () => {
expect(await parse(['--arrayWithComplexAnyOf', 'default', 'something-else'])).toEqual(
jasmine.objectContaining({
'arrayWithComplexAnyOf': ['default', 'something-else'],
}),
);
});

it('parses valid option value when specified multiple times', async () => {
expect(
await parse([
'--arrayWithComplexAnyOf',
Expand Down