source: trip-planner-front/node_modules/@angular-devkit/architect/testing/testing-architect-host.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.2 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.TestingArchitectHost = void 0;
30const src_1 = require("../src");
31class TestingArchitectHost {
32 /**
33 * Can provide a backend host, in case of integration tests.
34 * @param workspaceRoot The workspace root to use.
35 * @param currentDirectory The current directory to use.
36 * @param _backendHost A host to defer calls that aren't resolved here.
37 */
38 constructor(workspaceRoot = '', currentDirectory = workspaceRoot, _backendHost = null) {
39 this.workspaceRoot = workspaceRoot;
40 this.currentDirectory = currentDirectory;
41 this._backendHost = _backendHost;
42 this._builderImportMap = new Map();
43 this._builderMap = new Map();
44 this._targetMap = new Map();
45 }
46 addBuilder(builderName, builder, description = 'Testing only builder.', optionSchema = { type: 'object' }) {
47 this._builderImportMap.set(builderName, builder);
48 this._builderMap.set(builderName, { builderName, description, optionSchema });
49 }
50 async addBuilderFromPackage(packageName) {
51 const packageJson = await Promise.resolve().then(() => __importStar(require(packageName + '/package.json')));
52 if (!('builders' in packageJson)) {
53 throw new Error('Invalid package.json, builders key not found.');
54 }
55 if (!packageJson.name) {
56 throw new Error('Invalid package name');
57 }
58 const builderJsonPath = packageName + '/' + packageJson['builders'];
59 const builderJson = await Promise.resolve().then(() => __importStar(require(builderJsonPath)));
60 const builders = builderJson['builders'];
61 if (!builders) {
62 throw new Error('Invalid builders.json, builders key not found.');
63 }
64 for (const builderName of Object.keys(builders)) {
65 const b = builders[builderName];
66 // TODO: remove this check as v1 is not supported anymore.
67 if (!b.implementation) {
68 continue;
69 }
70 const handler = (await Promise.resolve().then(() => __importStar(require(builderJsonPath + '/../' + b.implementation)))).default;
71 const optionsSchema = await Promise.resolve().then(() => __importStar(require(builderJsonPath + '/../' + b.schema)));
72 this.addBuilder(`${packageJson.name}:${builderName}`, handler, b.description, optionsSchema);
73 }
74 }
75 addTarget(target, builderName, options = {}) {
76 this._targetMap.set(src_1.targetStringFromTarget(target), { builderName, options });
77 }
78 async getBuilderNameForTarget(target) {
79 const name = src_1.targetStringFromTarget(target);
80 const maybeTarget = this._targetMap.get(name);
81 if (!maybeTarget) {
82 return this._backendHost && this._backendHost.getBuilderNameForTarget(target);
83 }
84 return maybeTarget.builderName;
85 }
86 /**
87 * Resolve a builder. This needs to return a string which will be used in a dynamic `import()`
88 * clause. This should throw if no builder can be found. The dynamic import will throw if
89 * it is unsupported.
90 * @param builderName The name of the builder to be used.
91 * @returns All the info needed for the builder itself.
92 */
93 async resolveBuilder(builderName) {
94 return (this._builderMap.get(builderName) ||
95 (this._backendHost && this._backendHost.resolveBuilder(builderName)));
96 }
97 async getCurrentDirectory() {
98 return this.currentDirectory;
99 }
100 async getWorkspaceRoot() {
101 return this.workspaceRoot;
102 }
103 async getOptionsForTarget(target) {
104 const name = src_1.targetStringFromTarget(target);
105 const maybeTarget = this._targetMap.get(name);
106 if (!maybeTarget) {
107 return this._backendHost && this._backendHost.getOptionsForTarget(target);
108 }
109 return maybeTarget.options;
110 }
111 async getProjectMetadata(target) {
112 return this._backendHost && this._backendHost.getProjectMetadata(target);
113 }
114 async loadBuilder(info) {
115 return (this._builderImportMap.get(info.builderName) ||
116 (this._backendHost && this._backendHost.loadBuilder(info)));
117 }
118}
119exports.TestingArchitectHost = TestingArchitectHost;
Note: See TracBrowser for help on using the repository browser.