UNPKG

@nstudio/angular

Version:

Angular Plugin for xplat

122 lines (121 loc) 6.83 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 xplat_utils_1 = require("@nstudio/xplat-utils"); const testing_1 = require("@nstudio/xplat/testing"); const testing_2 = require("../../utils/testing"); describe('app', () => { let appTree; const defaultOptions = { name: 'foo', skipFormat: true, }; beforeEach(() => { appTree = schematics_1.Tree.empty(); appTree = (0, testing_1.createEmptyWorkspace)(appTree); }); it('should create all files for web app', () => __awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); const tree = yield (0, testing_2.runSchematic)('app', options, appTree); const files = tree.files; // console.log(files); expect(tree.exists('/apps/web-foo/tsconfig.json')).toBeTruthy(); expect(tree.exists('/apps/web-foo/src/main.ts')).toBeTruthy(); expect(tree.exists('/apps/web-foo/src/app/app.module.ts')).toBeTruthy(); expect(tree.exists('/apps/web-foo/src/app/app.component.html')).toBeTruthy(); expect(tree.exists('/apps/web-foo/src/app/core/core.module.ts')).toBeTruthy(); expect(tree.exists('/package.json')).toBeTruthy(); // should gen xplat structure by default expect(tree.exists('/libs/xplat/web/core/src/lib/index.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/features/src/lib/index.ts')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/scss/src/_index.scss')).toBeTruthy(); expect(tree.exists('/libs/xplat/web/scss/src/package.json')).toBeTruthy(); // let checkPath = 'angular.json' // let checkFile = tree.readContent(checkPath) // console.log(checkPath, checkFile) })); it('should create all files for web app using groupByName', () => __awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); options.groupByName = true; const tree = yield (0, testing_2.runSchematic)('app', options, appTree); const files = tree.files; // console.log(files); expect(files.indexOf('/apps/foo-web/tsconfig.json')).toBeGreaterThanOrEqual(0); let checkPath = (0, xplat_utils_1.getRootTsConfigPath)(); let checkFile = tree.readContent(checkPath); // console.log('tsconfig.base:', checkFile); expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0); expect(files.indexOf('/tsconfig.base.json')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/apps/foo-web/src/main.ts')).toBeGreaterThanOrEqual(0); expect(files.indexOf('/apps/foo-web/src/app/app.module.ts')).toBeGreaterThanOrEqual(0); checkPath = '/apps/foo-web/src/app/app.component.html'; expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0); checkPath = '/package.json'; expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0); })); it('should create all files for web app in directory', () => __awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); options.directory = 'frontend'; const tree = yield (0, testing_2.runSchematic)('app', options, appTree); const files = tree.files; // console.log(files); expect(tree.exists('/apps/frontend/web-foo/tsconfig.json')).toBeTruthy(); expect(tree.exists('/apps/frontend/web-foo/src/main.ts')).toBeTruthy(); expect(tree.exists('/apps/frontend/web-foo/src/app/app.module.ts')).toBeTruthy(); })); it('should create all files for web app in directory and ignore platform naming when directory is a platform', () => __awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); options.directory = 'web'; const tree = yield (0, testing_2.runSchematic)('app', options, appTree); const files = tree.files; // console.log(files); expect(tree.exists('/apps/web/foo/tsconfig.json')).toBeTruthy(); expect(tree.exists('/apps/web/foo/src/main.ts')).toBeTruthy(); expect(tree.exists('/apps/web/foo/src/app/app.module.ts')).toBeTruthy(); })); // it('should create app with --framework flag Ionic', async () => { // const options: Schema = { ...defaultOptions }; // const tree = await runSchematic('app', options, appTree); // const files = tree.files; // // console.log(files); // expect( // files.indexOf('/apps/ionic-foo/package.json') // ).toBeGreaterThanOrEqual(0); // const checkPath = '/package.json'; // expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0); // }); // it('should create app with --framework flag for NativeScript', async () => { // const options: Schema = { ...defaultOptions }; // options.framework = Framework.NativeScript; // const tree = await runSchematic('app', options, appTree); // const files = tree.files; // // console.log(files); // expect( // files.indexOf('/apps/nativescript-foo/package.json') // ).toBeGreaterThanOrEqual(0); // const checkPath = '/package.json'; // expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0); // }); describe('useXplat false', () => { it('should geneate app with no connections to xplat architecture', () => __awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); options.useXplat = false; // console.log('appTree:', appTree); const tree = yield (0, testing_2.runSchematic)('app', options, appTree); // const files = tree.files; // console.log(files); expect(tree.exists('/apps/web-foo/src/app/app.component.html')).toBeTruthy(); expect(tree.exists('/apps/web-foo/src/app/core/core.module.ts')).toBeFalsy(); expect(tree.exists('/libs/xplat/web/src/lib/index.ts')).toBeFalsy(); })); }); });