@yolkai/nx-workspace
Version:
166 lines (165 loc) • 7.25 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(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("../../utils/testing");
const testing_2 = require("@angular-devkit/schematics/testing");
describe('workspace', () => {
let appTree;
beforeEach(() => {
appTree = new testing_2.UnitTestTree(schematics_1.Tree.empty());
});
it('should error if no package.json is present', () => __awaiter(this, void 0, void 0, function* () {
try {
yield testing_1.runSchematic('ng-add', { name: 'myApp' }, appTree);
fail('should throw');
}
catch (e) {
expect(e.message).toContain('Cannot find package.json');
}
}));
it('should error if no e2e/protractor.conf.js is present', () => __awaiter(this, void 0, void 0, function* () {
appTree.create('/package.json', JSON.stringify({}));
appTree.create('/angular.json', JSON.stringify({
projects: {
proj1: {
architect: {
e2e: {
options: {
protractorConfig: 'e2e/protractor.conf.js'
}
}
}
}
}
}));
try {
yield testing_1.runSchematic('ng-add', { name: 'proj1' }, appTree);
}
catch (e) {
expect(e.message).toContain('An e2e project was specified but e2e/protractor.conf.js could not be found.');
}
}));
it('should error if no angular.json is present', () => __awaiter(this, void 0, void 0, function* () {
try {
appTree.create('/package.json', JSON.stringify({}));
appTree.create('/e2e/protractor.conf.js', '');
yield testing_1.runSchematic('ng-add', { name: 'myApp' }, appTree);
}
catch (e) {
expect(e.message).toContain('Cannot find angular.json');
}
}));
it('should error if the angular.json specifies more than one app', () => __awaiter(this, void 0, void 0, function* () {
appTree.create('/package.json', JSON.stringify({}));
appTree.create('/e2e/protractor.conf.js', '');
appTree.create('/angular.json', JSON.stringify({
projects: {
proj1: {},
'proj1-e2e': {},
proj2: {},
'proj2-e2e': {}
}
}));
try {
yield testing_1.runSchematic('ng-add', { name: 'myApp' }, appTree);
}
catch (e) {
expect(e.message).toContain('Can only convert projects with one app');
}
}));
it('should work without nested tsconfig files', () => __awaiter(this, void 0, void 0, function* () {
appTree.create('/package.json', JSON.stringify({}));
appTree.create('/angular.json', JSON.stringify({
version: 1,
defaultProject: 'myApp',
projects: {
myApp: {
root: '',
sourceRoot: 'src',
architect: {
build: {
options: {
tsConfig: 'tsconfig.app.json'
},
configurations: {}
},
test: {
options: {
tsConfig: 'tsconfig.spec.json'
}
},
lint: {
options: {
tsConfig: 'tsconfig.app.json'
}
},
e2e: {
options: {
protractorConfig: 'e2e/protractor.conf.js'
}
}
}
}
}
}));
appTree.create('/tsconfig.app.json', '{"extends": "../tsconfig.json", "compilerOptions": {}}');
appTree.create('/tsconfig.spec.json', '{"extends": "../tsconfig.json", "compilerOptions": {}}');
appTree.create('/tsconfig.json', '{"compilerOptions": {}}');
appTree.create('/tslint.json', '{"rules": {}}');
appTree.create('/e2e/protractor.conf.js', '// content');
appTree.create('/src/app/app.module.ts', '// content');
const tree = yield testing_1.runSchematic('ng-add', { name: 'myApp' }, appTree);
expect(tree.exists('/apps/myApp/tsconfig.app.json')).toBe(true);
}));
it('should work with nested (sub-dir) tsconfig files', () => __awaiter(this, void 0, void 0, function* () {
appTree.create('/package.json', JSON.stringify({}));
appTree.create('/angular.json', JSON.stringify({
version: 1,
defaultProject: 'myApp',
projects: {
myApp: {
sourceRoot: 'src',
architect: {
build: {
options: {
tsConfig: 'src/tsconfig.app.json'
},
configurations: {}
},
test: {
options: {
tsConfig: 'src/tsconfig.spec.json'
}
},
lint: {
options: {
tsConfig: 'src/tsconfig.app.json'
}
},
e2e: {
options: {
protractorConfig: 'e2e/protractor.conf.js'
}
}
}
}
}
}));
appTree.create('/src/tsconfig.app.json', '{"extends": "../tsconfig.json", "compilerOptions": {}}');
appTree.create('/src/tsconfig.spec.json', '{"extends": "../tsconfig.json", "compilerOptions": {}}');
appTree.create('/tsconfig.json', '{"compilerOptions": {}}');
appTree.create('/tslint.json', '{"rules": {}}');
appTree.create('/e2e/protractor.conf.js', '// content');
appTree.create('/src/app/app.module.ts', '// content');
const tree = yield testing_1.runSchematic('ng-add', { name: 'myApp' }, appTree);
expect(tree.exists('/apps/myApp/tsconfig.app.json')).toBe(true);
}));
});