UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

65 lines (64 loc) 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runMigration = runMigration; exports.createMigration = createMigration; const tslib_1 = require("tslib"); const schematics_1 = require("@angular-devkit/schematics"); const testing_1 = require("@angular-devkit/schematics/testing"); const ng_morph_1 = require("ng-morph"); function runMigration(options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e; const { collection, template = '', styles = '', packageJson = '{}', projectJson = '{}', schematicName = 'updateToV5', component = ` import {Component} from '@angular/core'; @Component({ templateUrl: './test.html', }) export class Test {} `, } = options; const host = new testing_1.UnitTestTree(new schematics_1.HostTree()); const runner = new testing_1.SchematicTestRunner('schematics', collection); (0, ng_morph_1.setActiveProject)((0, ng_morph_1.createProject)(host)); host.create('test/app/test.ts', component); host.create('test/app/test.html', template); host.create('test/app/test.less', styles); host.create('package.json', packageJson); host.create('project.json', projectJson); yield runner.runSchematic(schematicName, { 'skip-logs': true }, host); (0, ng_morph_1.saveActiveProject)(); return { component: (_a = host.readContent('test/app/test.ts')) !== null && _a !== void 0 ? _a : '', template: (_b = host.readContent('test/app/test.html')) !== null && _b !== void 0 ? _b : '', styles: (_c = host.readContent('test/app/test.less')) !== null && _c !== void 0 ? _c : '', packageJson: (_d = host.readContent('package.json')) !== null && _d !== void 0 ? _d : '{}', projectJson: (_e = host.readContent('project.json')) !== null && _e !== void 0 ? _e : '{}', }; }); } function createMigration(options) { return function migrate(overrides) { return () => tslib_1.__awaiter(this, void 0, void 0, function* () { const before = Object.assign(Object.assign({}, options), overrides); const after = yield runMigration(Object.assign(Object.assign({}, options), overrides)); if (before.component && before.component !== after.component) { expect(beforeAfterSnapshot(before.component, after.component)).toMatchSnapshot('test.ts'); } if (before.packageJson && before.packageJson !== after.packageJson) { expect(beforeAfterSnapshot(before.packageJson, after.packageJson)).toMatchSnapshot('package.json'); } if (before.projectJson && before.projectJson !== after.projectJson) { expect(beforeAfterSnapshot(before.projectJson, after.projectJson)).toMatchSnapshot('project.json'); } if (before.styles && before.styles !== after.styles) { expect(beforeAfterSnapshot(before.styles, after.styles)).toMatchSnapshot('test.less'); } if (before.template && before.template !== after.template) { expect(beforeAfterSnapshot(before.template, after.template)).toMatchSnapshot('test.html'); } }); }; } function beforeAfterSnapshot(before, after) { return { ['0. Before']: before, ['1. After']: after }; } //# sourceMappingURL=run-migration.js.map