forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjasmine-helpers.ts
More file actions
43 lines (38 loc) · 1.51 KB
/
jasmine-helpers.ts
File metadata and controls
43 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { BuilderHandlerFn } from '@angular-devkit/architect';
import { json } from '@angular-devkit/core';
import { readFileSync } from 'node:fs';
import { JasmineBuilderHarness, host, setupApplicationTarget } from './setup';
const optionSchemaCache = new Map<string, json.schema.JsonSchema>();
let counter = 0;
export function describeServeBuilder<T>(
builderHandler: BuilderHandlerFn<T & json.JsonObject>,
options: { name?: string; schemaPath: string },
specDefinitions: (
harness: JasmineBuilderHarness<T>,
setupTarget: typeof setupApplicationTarget,
isViteRun: true,
) => void,
): void {
let optionSchema = optionSchemaCache.get(options.schemaPath);
if (optionSchema === undefined) {
optionSchema = JSON.parse(readFileSync(options.schemaPath, 'utf8')) as json.schema.JsonSchema;
optionSchemaCache.set(options.schemaPath, optionSchema);
}
const harness = new JasmineBuilderHarness<T>(builderHandler, host, {
builderName: options.name,
optionSchema,
});
// The counter is needed to avoid duplicate describe names as they are not allowed.
describe((options.name || builderHandler.name) + ` (${counter++})`, () => {
beforeEach(() => host.initialize().toPromise());
afterEach(() => host.restore().toPromise());
specDefinitions(harness, setupApplicationTarget, true);
});
}