@nstudio/angular
Version:
Angular Plugin for xplat
146 lines (145 loc) • 8.41 kB
JavaScript
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('service schematic', () => {
let appTree;
const defaultOptions = {
name: 'auth',
};
beforeEach(() => {
appTree = schematics_1.Tree.empty();
appTree = (0, testing_1.createXplatWithNativeScriptWeb)(appTree, null, 'angular');
});
it('should create service 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);
const options = Object.assign({}, defaultOptions);
tree = yield (0, testing_2.runSchematic)('service', options, tree);
// console.log(files.slice(91,files.length));
expect(tree.exists('/libs/xplat/core/src/lib/services/auth.service.ts')).toBeTruthy();
// file content
let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/core/src/lib/services/auth.service.ts');
// console.log(content);
expect(content.indexOf(`@Injectable({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`AuthService`)).toBeGreaterThanOrEqual(0);
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/core/src/lib/services/index.ts');
// console.log(content);
expect(content.indexOf(`./auth.service`)).toBeGreaterThanOrEqual(0);
let modulePath = '/libs/xplat/core/src/lib/core.module.ts';
let moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`AuthService`)).toBe(-1);
}));
it('should create service 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: 'auth',
feature: 'foo',
projects: 'nativescript-viewer,web-viewer',
};
tree = yield (0, testing_2.runSchematic)('service', options, tree);
const files = tree.files;
// console.log(files. slice(91,files.length));
// service should not be setup to share
expect(files.indexOf('/libs/xplat/features/src/lib/foo/services/auth.service.ts')).toBe(-1);
expect(files.indexOf('/libs/xplat/nativescript/features/src/lib/foo/services/auth.service.ts')).toBe(-1);
expect(files.indexOf('/libs/xplat/web/features/src/lib/foo/services/auth.service.ts')).toBe(-1);
// service should be project specific
expect(files.indexOf('/apps/nativescript-viewer/src/features/foo/services/auth.service.ts')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/apps/web-viewer/src/app/features/foo/services/auth.service.ts')).toBeGreaterThanOrEqual(0);
// file content
let indexPath = '/apps/nativescript-viewer/src/features/foo/services/index.ts';
let index = (0, testing_1.getFileContent)(tree, indexPath);
// console.log(barrelPath + ':');
// console.log(barrelIndex);
// symbol should be at end of components collection
expect(index.indexOf(`./auth.service`)).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(`./services`)).toBe(-1);
indexPath = '/apps/web-viewer/src/app/features/foo/services/index.ts';
index = (0, testing_1.getFileContent)(tree, indexPath);
// console.log(barrelPath + ':');
// console.log(barrelIndex);
expect(index.indexOf(`./auth.service`)).toBeGreaterThanOrEqual(0);
}));
it('should create service for specified platform with targeted feature only', () => __awaiter(void 0, void 0, void 0, function* () {
// console.log('appTree:', appTree);
let tree = yield (0, testing_2.runSchematic)('feature', {
name: 'foo',
platforms: 'nativescript',
}, appTree);
const options = {
name: 'auth',
feature: 'foo',
platforms: 'nativescript',
};
tree = yield (0, testing_2.runSchematic)('service', options, tree);
const files = tree.files;
// console.log(files.slice(91,files.length));
expect(files.indexOf('/libs/xplat/nativescript/features/src/lib/foo/services/auth.service.ts')).toBeGreaterThanOrEqual(0);
// should NOT add for other platform
expect(files.indexOf('/libs/xplat/web/features/src/lib/foo/services/auth.service.ts')).toBe(-1);
// file content
let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/nativescript/features/src/lib/foo/services/auth.service.ts');
// console.log(content);
expect(content.indexOf(`@Injectable({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`AuthService`)).toBeGreaterThanOrEqual(0);
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/nativescript/features/src/lib/foo/services/index.ts');
// console.log(content);
expect(content.indexOf(`./auth.service`)).toBeGreaterThanOrEqual(0);
let modulePath = '/libs/xplat/nativescript/features/src/lib/foo/foo.module.ts';
let moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`AuthService`)).toBe(-1);
}));
it('should create service for specified platform only and by default add to core for that platform', () => __awaiter(void 0, void 0, void 0, function* () {
// console.log('appTree:', appTree);
const options = {
name: 'auth',
platforms: 'nativescript',
};
let tree = yield (0, testing_2.runSchematic)('service', options, appTree);
const files = tree.files;
// console.log(files.slice(91,files.length));
expect(files.indexOf('/libs/xplat/nativescript/core/src/lib/services/auth.service.ts')).toBeGreaterThanOrEqual(0);
// should NOT add for other platform
expect(files.indexOf('/libs/xplat/web/core/src/lib/services/auth.service.ts')).toBe(-1);
// file content
let content = (0, testing_1.getFileContent)(tree, '/libs/xplat/nativescript/core/src/lib/services/auth.service.ts');
// console.log(content);
expect(content.indexOf(`@Injectable({`)).toBeGreaterThanOrEqual(0);
expect(content.indexOf(`AuthService`)).toBeGreaterThanOrEqual(0);
content = (0, testing_1.getFileContent)(tree, '/libs/xplat/nativescript/core/src/lib/services/index.ts');
// console.log(content);
expect(content.indexOf(`./auth.service`)).toBeGreaterThanOrEqual(0);
let modulePath = '/libs/xplat/nativescript/core/src/lib/core.module.ts';
let moduleContent = (0, testing_1.getFileContent)(tree, modulePath);
// console.log(modulePath + ':');
// console.log(moduleContent);
expect(moduleContent.indexOf(`AuthService`)).toBe(-1);
}));
});
;