-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathsetup.ts
77 lines (69 loc) · 2.13 KB
/
setup.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @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.io/license
*/
import { json } from '@angular-devkit/core';
import { readFileSync } from 'fs';
import { BuilderHarness } from '../../../testing/builder-harness';
import { buildWebpackBrowser } from '../../browser';
import { Schema as BrowserSchema } from '../../browser/schema';
import {
BASE_OPTIONS as BROWSER_BASE_OPTIONS,
BROWSER_BUILDER_INFO,
} from '../../browser/tests/setup';
import { Schema } from '../schema';
export { describeBuilder } from '../../../testing';
export const DEV_SERVER_BUILDER_INFO = Object.freeze({
name: '@angular-devkit/build-angular:dev-server',
schemaPath: __dirname + '/../schema.json',
});
/**
* Contains all required dev-server builder fields.
* The port is also set to zero to ensure a free port is used for each test which
* supports parallel test execution.
*/
export const BASE_OPTIONS = Object.freeze<Schema>({
browserTarget: 'test:build',
port: 0,
});
/**
* Maximum time for single build/rebuild
* This accounts for CI variability.
*/
export const BUILD_TIMEOUT = 25_000;
/**
* Cached browser builder option schema
*/
let browserSchema: json.schema.JsonSchema | undefined = undefined;
/**
* Adds a `build` target to a builder test harness for the browser builder with the base options
* used by the browser builder tests.
*
* @param harness The builder harness to use when setting up the browser builder target
* @param extraOptions The additional options that should be used when executing the target.
*/
export function setupBrowserTarget<T>(
harness: BuilderHarness<T>,
extraOptions?: Partial<BrowserSchema>,
): void {
if (!browserSchema) {
browserSchema = JSON.parse(
readFileSync(BROWSER_BUILDER_INFO.schemaPath, 'utf8'),
) as json.schema.JsonSchema;
}
harness.withBuilderTarget(
'build',
buildWebpackBrowser,
{
...BROWSER_BASE_OPTIONS,
...extraOptions,
},
{
builderName: BROWSER_BUILDER_INFO.name,
optionSchema: browserSchema,
},
);
}