source: trip-planner-front/node_modules/@angular-devkit/schematics/testing/schematic-test-runner.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[6a3a178]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 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.SchematicTestRunner = exports.UnitTestTree = void 0;
11const core_1 = require("@angular-devkit/core");
12const rxjs_1 = require("rxjs");
13const operators_1 = require("rxjs/operators");
14const src_1 = require("../src");
15const call_1 = require("../src/rules/call");
16const node_1 = require("../tasks/node");
17const tools_1 = require("../tools");
18class UnitTestTree extends src_1.DelegateTree {
19 get files() {
20 const result = [];
21 this.visit((path) => result.push(path));
22 return result;
23 }
24 readContent(path) {
25 const buffer = this.read(path);
26 if (buffer === null) {
27 return '';
28 }
29 return buffer.toString();
30 }
31}
32exports.UnitTestTree = UnitTestTree;
33class SchematicTestRunner {
34 constructor(_collectionName, collectionPath) {
35 this._collectionName = _collectionName;
36 this._engineHost = new tools_1.NodeModulesTestEngineHost();
37 this._engine = new src_1.SchematicEngine(this._engineHost);
38 this._engineHost.registerCollection(_collectionName, collectionPath);
39 this._logger = new core_1.logging.Logger('test');
40 const registry = new core_1.schema.CoreSchemaRegistry(src_1.formats.standardFormats);
41 registry.addPostTransform(core_1.schema.transforms.addUndefinedDefaults);
42 this._engineHost.registerOptionsTransform(tools_1.validateOptionsWithSchema(registry));
43 this._engineHost.registerTaskExecutor(node_1.BuiltinTaskExecutor.NodePackage);
44 this._engineHost.registerTaskExecutor(node_1.BuiltinTaskExecutor.RepositoryInitializer);
45 this._engineHost.registerTaskExecutor(node_1.BuiltinTaskExecutor.RunSchematic);
46 this._engineHost.registerTaskExecutor(node_1.BuiltinTaskExecutor.TslintFix);
47 this._collection = this._engine.createCollection(this._collectionName);
48 }
49 get engine() {
50 return this._engine;
51 }
52 get logger() {
53 return this._logger;
54 }
55 get tasks() {
56 return [...this._engineHost.tasks];
57 }
58 registerCollection(collectionName, collectionPath) {
59 this._engineHost.registerCollection(collectionName, collectionPath);
60 }
61 runSchematicAsync(schematicName, opts, tree) {
62 const schematic = this._collection.createSchematic(schematicName, true);
63 const host = rxjs_1.of(tree || new src_1.HostTree());
64 this._engineHost.clearTasks();
65 return schematic
66 .call(opts || {}, host, { logger: this._logger })
67 .pipe(operators_1.map((tree) => new UnitTestTree(tree)));
68 }
69 runExternalSchematicAsync(collectionName, schematicName, opts, tree) {
70 const externalCollection = this._engine.createCollection(collectionName);
71 const schematic = externalCollection.createSchematic(schematicName, true);
72 const host = rxjs_1.of(tree || new src_1.HostTree());
73 this._engineHost.clearTasks();
74 return schematic
75 .call(opts || {}, host, { logger: this._logger })
76 .pipe(operators_1.map((tree) => new UnitTestTree(tree)));
77 }
78 callRule(rule, tree, parentContext) {
79 const context = this._engine.createContext({}, parentContext);
80 return call_1.callRule(rule, rxjs_1.of(tree), context);
81 }
82}
83exports.SchematicTestRunner = SchematicTestRunner;
Note: See TracBrowser for help on using the repository browser.