UNPKG

@nstudio/angular

Version:

Angular Plugin for xplat

154 lines (153 loc) 9.09 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('pipe schematic', () => { let appTree; const defaultOptions = { name: 'truncate', }; beforeEach(() => { appTree = schematics_1.Tree.empty(); appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, null, 'angular'); }); it('should create pipe in libs by default for use across any platform and apps', () => __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); let options = Object.assign({}, defaultOptions); tree = yield (0, testing_2.runSchematic)('pipe', options, tree); // let files = tree.files; // console.log(files.slice(91,files.length)); // component expect(tree.exists('/libs/xplat/features/src/lib/ui/pipes/truncate.pipe.ts')).toBeTruthy(); // file content let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/features/src/lib/ui/pipes/truncate.pipe.ts'); // console.log(content); expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0); expect(content.indexOf(`name: 'truncate'`)).toBeGreaterThanOrEqual(0); let modulePath = '/libs/xplat/features/src/lib/ui/ui.module.ts'; let moduleContent = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(moduleContent); expect(moduleContent.indexOf(`...UI_PIPES`)).toBeGreaterThanOrEqual(0); options = Object.assign(Object.assign({}, defaultOptions), { feature: 'foo' }); tree = yield (0, testing_2.runSchematic)('pipe', options, tree); // files = tree.files; // console.log(files.slice(91,files.length)); // component expect(tree.exists('/libs/xplat/features/src/lib/foo/pipes/truncate.pipe.ts')).toBeTruthy(); // file content content = (0, testing_1.getFileContent)(tree, '/libs/xplat/features/src/lib/foo/pipes/truncate.pipe.ts'); // console.log(content); expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0); expect(content.indexOf(`name: 'truncate'`)).toBeGreaterThanOrEqual(0); modulePath = '/libs/xplat/features/src/lib/foo/foo.module.ts'; moduleContent = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(moduleContent); expect(moduleContent.indexOf(`...FOO_PIPES`)).toBeGreaterThanOrEqual(0); })); it('should create pipe in libs and handle camel case properly', () => __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); let options = Object.assign(Object.assign({}, defaultOptions), { name: 'test-with-dashes' }); tree = yield (0, testing_2.runSchematic)('pipe', options, tree); const files = tree.files; // console.log(files.slice(91,files.length)); // component expect(tree.exists('/libs/xplat/features/src/lib/ui/pipes/test-with-dashes.pipe.ts')).toBeTruthy(); // file content let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/features/src/lib/ui/pipes/test-with-dashes.pipe.ts'); // console.log(content); expect(content.indexOf(`@Pipe({`)).toBeGreaterThanOrEqual(0); expect(content.indexOf(`name: 'testWithDashes'`)).toBeGreaterThanOrEqual(0); })); it('should THROW if feature module does not exist in libs', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); let tree; const options = Object.assign({}, defaultOptions); options.feature = 'register'; yield expect((0, testing_2.runSchematic)('pipe', options, appTree)).rejects.toThrow(`libs/xplat/features/src/lib/register/register.module.ts does not exist. Create the feature module first. For example: nx g @nstudio/angular:feature register`); })); it('should create pipe 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: 'truncate', feature: 'foo', projects: 'nativescript-viewer,web-viewer', }; tree = yield (0, testing_2.runSchematic)('pipe', options, tree); const files = tree.files; // console.log(files. slice(91,files.length)); // pipe should not be setup to share expect(tree.exists('/libs/xplat/features/src/lib/ui/pipes/truncate.pipe.ts')).toBeFalsy(); expect(tree.exists('/libs/xplat/nativescript/features/src/lib/foo/pipes/truncate.pipe.ts')).toBeFalsy(); expect(tree.exists('/libs/xplat/web/features/src/lib/foo/pipes/truncate.pipe.ts')).toBeFalsy(); // pipe should be project specific expect(tree.exists('/apps/nativescript-viewer/src/features/foo/pipes/truncate.pipe.ts')).toBeTruthy(); expect(tree.exists('/apps/web-viewer/src/app/features/foo/pipes/truncate.pipe.ts')).toBeTruthy(); // file content let pipeIndexPath = '/apps/nativescript-viewer/src/features/foo/pipes/index.ts'; let pipeIndex = (0, testing_1.getFileContent)(tree, pipeIndexPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); // component symbol should be at end of components collection expect(pipeIndex.indexOf(`TruncatePipe`)).toBeGreaterThanOrEqual(0); let modulePath = '/apps/nativescript-viewer/src/features/foo/foo.module.ts'; let moduleContent = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(moduleContent); expect(moduleContent.indexOf(`...FOO_PIPES`)).toBeGreaterThanOrEqual(0); pipeIndexPath = '/apps/web-viewer/src/app/features/foo/pipes/index.ts'; pipeIndex = (0, testing_1.getFileContent)(tree, pipeIndexPath); // console.log(barrelPath + ':'); // console.log(barrelIndex); expect(pipeIndex.indexOf(`TruncatePipe`)).toBeGreaterThanOrEqual(0); modulePath = '/apps/web-viewer/src/app/features/foo/foo.module.ts'; moduleContent = (0, testing_1.getFileContent)(tree, modulePath); // console.log(modulePath + ':'); // console.log(moduleContent); expect(moduleContent.indexOf(`...FOO_PIPES`)).toBeGreaterThanOrEqual(0); })); it('should THROW if feature module does not exist in shared code', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); let tree; const options = { name: 'truncate', feature: 'register', platforms: 'nativescript,web', }; yield expect((0, testing_2.runSchematic)('pipe', options, appTree)).rejects.toThrow(`libs/xplat/nativescript/features/src/lib/register/register.module.ts does not exist. Create the feature module first. For example: nx g @nstudio/angular:feature register --platforms=nativescript --onlyModule`); })); it('should THROW if feature module does not exist in projects', () => __awaiter(void 0, void 0, void 0, function* () { // console.log('appTree:', appTree); let tree; const options = { name: 'truncate', feature: 'register', projects: 'nativescript-viewer,web-viewer', }; yield expect((0, testing_2.runSchematic)('pipe', options, appTree)).rejects.toThrow(`apps/nativescript-viewer/src/features/register/register.module.ts does not exist. Create the feature module first. For example: nx g @nstudio/angular:feature register --projects=nativescript-viewer --onlyModule`); })); });