Skip to content

Commit c26a386

Browse files
committed
test: optimize json-schema_spec.ts by parsing the schema once in beforeAll instead of beforeEach
This reduces the parsing times.
1 parent f51b816 commit c26a386

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/angular/cli/src/command-builder/utilities/json-schema_spec.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { JsonObject, schema } from '@angular-devkit/core';
1010
import yargs from 'yargs';
1111

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

1414
describe('parseJsonSchemaToOptions', () => {
1515
describe('without required fields in schema', () => {
@@ -21,10 +21,9 @@ describe('parseJsonSchemaToOptions', () => {
2121
};
2222

2323
let localYargs: yargs.Argv<unknown>;
24-
beforeEach(async () => {
25-
// Create a fresh yargs for each call. The yargs object is stateful and
26-
// calling .parse multiple times on the same instance isn't safe.
27-
localYargs = yargs().exitProcess(false).strict().fail(false).wrap(1_000);
24+
let options: Option[];
25+
26+
beforeAll(async () => {
2827
const jsonSchema = {
2928
'type': 'object',
3029
'properties': {
@@ -118,12 +117,20 @@ describe('parseJsonSchemaToOptions', () => {
118117
},
119118
},
120119
};
120+
121121
const registry = new schema.CoreSchemaRegistry();
122-
const options = await parseJsonSchemaToOptions(
122+
options = await parseJsonSchemaToOptions(
123123
registry,
124124
jsonSchema as unknown as JsonObject,
125125
false,
126126
);
127+
});
128+
129+
beforeEach(async () => {
130+
// Create a fresh yargs for each call. The yargs object is stateful and
131+
// calling .parse multiple times on the same instance isn't safe.
132+
localYargs = yargs().exitProcess(false).strict().fail(false).wrap(1_000);
133+
127134
addSchemaOptionsToCommand(localYargs, options, true);
128135
});
129136

0 commit comments

Comments
 (0)