UNPKG

@nstudio/angular

Version:

Angular Plugin for xplat

196 lines (195 loc) 12.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const testing_1 = require("@nstudio/xplat/testing"); const testing_2 = require("../../utils/testing"); describe('component schematic', () => { let appTree; const defaultOptions = { name: 'signup', feature: 'foo', platforms: 'nativescript,web', createBase: true, }; beforeEach(() => { appTree = schematics_1.Tree.empty(); appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, false, 'angular'); }); it('should create component for specified platforms', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); let tree = yield (0, testing_2.runSchematic)('feature', { name: 'foo', platforms: 'nativescript,web', }, appTree); const options = Object.assign({}, defaultOptions); tree = yield (0, testing_2.runSchematic)('component', options, tree); const files = tree.files; // console.log(files.slice(91,files.length)); // component expect(tree.exists('/libs/xplat/features/src/lib/foo/base/signup.base-component.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/components/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/components/signup/signup.component.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/components/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/components/signup/signup.component.ts')).toBeTruthy(); // ensure base index was modified let barrelPath = '/libs/xplat/features/src/lib/foo/base/index.ts'; let barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(barrelIndex.indexOf(`./signup.base-component`)).toBeGreaterThanOrEqual(0); // file content barrelPath = '/libs/xplat/nativescript/features/src/lib/foo/components/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(barrelIndex.indexOf(`SignupComponent];`)).toBeGreaterThanOrEqual(0); expect(barrelIndex.indexOf(`./signup/signup.component`)).toBeGreaterThanOrEqual(0); barrelPath = '/libs/xplat/web/features/src/lib/foo/components/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(barrelIndex.indexOf(`SignupComponent];`)).toBeGreaterThanOrEqual(0); })); it('should create component for specified platforms with framework name when no default is set', () => __awaiter(void 0, void 0, void 0, function* () { appTree = schematics_1.Tree.empty(); appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree); // console.log('appTree:', appTree); let tree = yield (0, testing_2.runSchematic)('feature', { name: 'foo', platforms: 'nativescript,web', }, appTree); const options = Object.assign({}, defaultOptions); tree = yield (0, testing_2.runSchematic)('component', options, tree); const files = tree.files; // console.log(files);//.slice(91,files.length)); // component expect(tree.exists('/libs/xplat/features/src/lib/foo/base/signup.base-component.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/nativescript-angular/features/src/lib/foo/components/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/libs/xplat/nativescript-angular/features/src/lib/foo/components/signup/signup.component.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/web-angular/features/src/lib/foo/components/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/libs/xplat/web-angular/features/src/lib/foo/components/signup/signup.component.ts')).toBeTruthy(); })); it('should create component for specified platforms with subFolder option', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); let tree = yield (0, testing_2.runSchematic)('feature', { name: 'foo', platforms: 'nativescript,web', }, appTree); const options = Object.assign({}, defaultOptions); options.subFolder = 'registration'; tree = yield (0, testing_2.runSchematic)('component', options, tree); const files = tree.files; // console.log(files.slice(91,files.length)); // component expect(tree.exists('/libs/xplat/features/src/lib/foo/base/registration/signup.base-component.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/components/registration/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/components/registration/signup/signup.component.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/components/registration/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/components/registration/signup/signup.component.ts')).toBeTruthy(); // ensure base index was modified let barrelPath = '/libs/xplat/features/src/lib/foo/base/registration/index.ts'; let barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(barrelIndex.indexOf(`./signup.base-component`)).toBeTruthy(); barrelPath = '/libs/xplat/features/src/lib/foo/base/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(barrelIndex.indexOf(`./registration`)).toBeGreaterThanOrEqual(0); // file content barrelPath = '/libs/xplat/nativescript/features/src/lib/foo/components/registration/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(barrelIndex.indexOf(`SignupComponent];`)).toBeGreaterThanOrEqual(0); barrelPath = '/libs/xplat/web/features/src/lib/foo/components/registration/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(barrelIndex.indexOf(`./signup/signup.component`)).toBeGreaterThanOrEqual(0); // file content barrelPath = '/libs/xplat/nativescript/features/src/lib/foo/components/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(barrelIndex.indexOf(`REGISTRATION_COMPONENTS`)).toBeGreaterThanOrEqual(0); barrelPath = '/libs/xplat/web/features/src/lib/foo/components/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(barrelIndex.indexOf(`REGISTRATION_COMPONENTS`)).toBeGreaterThanOrEqual(0); })); it('should create component for specified projects only', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); let tree = yield (0, testing_2.runSchematic)('feature', { name: 'foo', projects: 'nativescript-viewer,web-viewer', onlyProject: true, }, appTree); const options = { name: 'signup', feature: 'foo', projects: 'nativescript-viewer,web-viewer', }; tree = yield (0, testing_2.runSchematic)('component', options, tree); const files = tree.files; // console.log(files. slice(91,files.length)); // component should not be setup to share expect(tree.exists('/libs/xplat/features/src/lib/foo/base/signup.base-component.ts')).toBeFalsy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/components/signup/signup.component.html')).toBeFalsy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/components/signup/signup.component.ts')).toBeFalsy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/components/signup/signup.component.html')).toBeFalsy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/components/signup/signup.component.ts')).toBeFalsy(); // component should be project specific expect(tree.exists('/apps/nativescript-viewer/src/features/foo/components/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/apps/nativescript-viewer/src/features/foo/components/signup/signup.component.ts')).toBeTruthy(); expect(tree.exists('/apps/web-viewer/src/app/features/foo/components/signup/signup.component.html')).toBeTruthy(); expect(tree.exists('/apps/web-viewer/src/app/features/foo/components/signup/signup.component.ts')).toBeTruthy(); // file content let barrelPath = '/apps/nativescript-viewer/src/features/foo/components/index.ts'; let barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(barrelIndex.indexOf(`SignupComponent];`)).toBeGreaterThanOrEqual(0); // let modulePath = '/apps/nativescript-viewer/src/features/foo/foo.module.ts'; // let content = getFileContent(tree, modulePath); // console.log(modulePath + ':'); // console.log(content); // // component symbol should be at end of components collection // expect(content.indexOf(`./signup/signup.component.ts`)).toBeGreaterThanOrEqual(0); barrelPath = '/apps/web-viewer/src/app/features/foo/components/index.ts'; barrelIndex = (0, testing_1.getFileContent)(tree, barrelPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(barrelIndex.indexOf(`SignupComponent];`)).toBeGreaterThanOrEqual(0); })); it('should THROW if feature module does not exist in projects', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); const options = { name: 'signup', feature: 'foo', projects: 'nativescript-viewer,web-viewer', }; yield expect((0, testing_2.runSchematic)('component', options, appTree)).rejects.toThrow(`apps/nativescript-viewer/src/features/foo/foo.module.ts does not exist. Create the feature module first. For example: nx g @nstudio/angular:feature foo --projects=nativescript-viewer --onlyModule`); })); });