@nrwl/schematics
Version:
450 lines (449 loc) • 19.5 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("@angular-devkit/schematics/testing");
const workspace_1 = require("@nrwl/workspace");
const path = require("path");
const workspace_2 = require("@nrwl/workspace");
describe('Update 7.2.0', () => {
let initialTree;
let schematicRunner;
beforeEach(() => {
initialTree = schematics_1.Tree.empty();
createJson('package.json', {
scripts: {}
});
createJson('tsconfig.json', {});
createJson('angular.json', {
projects: {
app1: {
root: 'apps/app1',
architect: {
build: {
builder: '@angular-devkit/build-angular:browser',
options: {
tsConfig: 'apps/app1/tsconfig.app.json'
}
},
test: {
builder: '@angular-devkit/build-angular:karma',
options: {
tsConfig: 'apps/app1/tsconfig.spec.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
'apps/app1/tsconfig.app.json',
'apps/app1/tsconfig.spec.json'
]
}
}
}
},
'app1-e2e': {
root: 'apps/app1-e2e',
architect: {
e2e: {
builder: '@angular-devkit/build-angular:protractor',
options: {
tsConfig: 'apps/app1-e2e/tsconfig.e2e.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: 'apps/app1-e2e/tsconfig.e2e.json'
}
}
}
},
app2: {
root: 'apps/app2',
architect: {
build: {
builder: '@angular-devkit/build-angular:browser',
options: {
tsConfig: 'apps/app2/tsconfig.app.json'
}
},
test: {
builder: '@nrwl/schematics:jest',
options: {
tsConfig: 'apps/app2/tsconfig.spec.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
'apps/app2/tsconfig.app.json',
'apps/app2/tsconfig.spec.json'
]
}
}
}
},
'app2-e2e': {
root: 'apps/app2-e2e',
architect: {
e2e: {
builder: '@nrwl/builders:cypress',
options: {
tsConfig: 'apps/app2-e2e/tsconfig.e2e.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: 'apps/app2-e2e/tsconfig.e2e.json'
}
}
}
},
'node-app': {
root: 'apps/node-app',
architect: {
build: {
builder: '@nrwl/builders:node-build',
options: {
tsConfig: 'apps/node-app/tsconfig.app.json'
}
},
test: {
builder: '@nrwl/schematics:jest',
options: {
tsConfig: 'apps/node-app/tsconfig.spec.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
'apps/node-app/tsconfig.app.json',
'apps/node-app/tsconfig.spec.json'
]
}
}
}
},
'weird-app': {
root: 'apps/weird/app',
architect: {
build: {
builder: '@nrwl/builders:node-build',
options: {
tsConfig: 'apps/weird/app/src/tsconfig.app.json'
}
},
test: {
builder: '@nrwl/schematics:jest',
options: {
tsConfig: 'apps/weird/app/src/tsconfig.spec.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
'apps/weird/app/src/tsconfig.app.json',
'apps/weird/app/src/tsconfig.spec.json'
]
}
}
}
},
lib1: {
root: 'libs/lib1',
architect: {
test: {
builder: '@angular-devkit/build-angular:karma',
options: {
tsConfig: 'libs/lib1/tsconfig.spec.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
'libs/lib1/tsconfig.lib.json',
'libs/lib1/tsconfig.spec.json'
]
}
}
}
},
lib2: {
root: 'libs/lib2',
architect: {
test: {
builder: '@angular-devkit/build-angular:jest',
options: {
tsConfig: 'libs/lib2/tsconfig.spec.json'
}
},
lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: [
'libs/lib2/tsconfig.lib.json',
'libs/lib2/tsconfig.spec.json'
]
}
}
}
}
}
});
createJson('apps/app1/tsconfig.app.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jquery']
}
});
createJson('apps/app1/tsconfig.spec.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jasmine', 'node', 'sinon']
}
});
createJson('apps/app1-e2e/tsconfig.e2e.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jasmine', 'jasminewd2', 'node']
}
});
createJson('apps/app2/tsconfig.app.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: []
}
});
createJson('apps/app2/tsconfig.spec.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jest', 'node']
}
});
createJson('apps/app2-e2e/tsconfig.e2e.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['cypress', 'node']
}
});
createJson('apps/node-app/tsconfig.app.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['node']
}
});
createJson('apps/node-app/tsconfig.spec.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jest', 'node']
}
});
createJson('apps/weird/app/src/tsconfig.app.json', {
extends: '../../../tsconfig.json',
compilerOptions: {}
});
createJson('apps/weird/app/src/tsconfig.spec.json', {
extends: '../../../tsconfig.json',
compilerOptions: {}
});
createJson('libs/lib1/tsconfig.lib.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: []
}
});
createJson('libs/lib1/tsconfig.spec.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jasmine', 'node']
}
});
createJson('libs/lib2/tsconfig.lib.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: []
}
});
createJson('libs/lib2/tsconfig.spec.json', {
extends: '../../tsconfig.json',
compilerOptions: {
types: ['jest', 'node']
}
});
function createJson(path, value) {
initialTree.create(path, workspace_1.serializeJson(value));
}
schematicRunner = new testing_1.SchematicTestRunner('@nrwl/schematics', path.join(__dirname, '../migrations.json'));
});
it('should create tsconfigs for existing projects', () => __awaiter(this, void 0, void 0, function* () {
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
expect(result.files).toContain('/tsconfig.json');
expect(result.files).toContain('/apps/app1/tsconfig.json');
expect(result.files).toContain('/apps/app1-e2e/tsconfig.json');
expect(result.files).toContain('/apps/app2/tsconfig.json');
expect(result.files).toContain('/apps/app2-e2e/tsconfig.json');
expect(result.files).toContain('/apps/node-app/tsconfig.json');
expect(result.files).toContain('/apps/weird/app/tsconfig.json');
expect(result.files).toContain('/libs/lib1/tsconfig.json');
expect(result.files).toContain('/libs/lib2/tsconfig.json');
[
'/apps/app1/tsconfig.json',
'/apps/app1-e2e/tsconfig.json',
'/apps/app2/tsconfig.json',
'/apps/app2-e2e/tsconfig.json',
'/apps/node-app/tsconfig.json',
'/libs/lib1/tsconfig.json',
'/libs/lib2/tsconfig.json'
].forEach(tsConfig => {
const value = workspace_2.readJsonInTree(result, tsConfig);
expect(value.extends).toEqual('../../tsconfig.json');
});
expect(workspace_2.readJsonInTree(result, 'apps/weird/app/tsconfig.json').extends).toEqual('../../../tsconfig.json');
}));
it('should fix cypress lint configs', () => __awaiter(this, void 0, void 0, function* () {
initialTree = yield schematicRunner
.callRule(workspace_2.updateJsonInTree('angular.json', json => {
json.projects['app2-e2e'].architect.lint.options.tsConfig =
'e2e/tsconfig.e2e.json';
return json;
}), initialTree)
.toPromise();
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
expect(workspace_2.readJsonInTree(result, 'angular.json').projects['app2-e2e'].architect.lint
.options.tsConfig).toEqual('apps/app2-e2e/tsconfig.e2e.json');
[
'/apps/app1/tsconfig.app.json',
'/apps/app1/tsconfig.spec.json',
'/apps/app1-e2e/tsconfig.e2e.json',
'/apps/app2/tsconfig.app.json',
'/apps/app2/tsconfig.spec.json',
'/apps/app2-e2e/tsconfig.e2e.json',
'/apps/node-app/tsconfig.app.json',
'/apps/node-app/tsconfig.spec.json',
'/libs/lib1/tsconfig.lib.json',
'/libs/lib1/tsconfig.spec.json',
'/libs/lib2/tsconfig.lib.json',
'/libs/lib2/tsconfig.spec.json'
].forEach(tsConfig => {
const value = workspace_2.readJsonInTree(result, tsConfig);
expect(value.extends).toEqual('./tsconfig.json');
});
}));
it('should not fail for non-existing tsconfigs', () => __awaiter(this, void 0, void 0, function* () {
initialTree = yield schematicRunner
.callRule(workspace_2.updateJsonInTree('angular.json', json => {
json.projects['app2'].architect.lint.options.tsConfig =
'apps/nonexistent/tsconfig.app.json';
return json;
}), initialTree)
.toPromise();
yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
}));
it('should edit existing tsconfigs to extend the new one', () => __awaiter(this, void 0, void 0, function* () {
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
[
'/apps/app1/tsconfig.app.json',
'/apps/app1/tsconfig.spec.json',
'/apps/app1-e2e/tsconfig.e2e.json',
'/apps/app2/tsconfig.app.json',
'/apps/app2/tsconfig.spec.json',
'/apps/app2-e2e/tsconfig.e2e.json',
'/apps/node-app/tsconfig.app.json',
'/apps/node-app/tsconfig.spec.json',
'/libs/lib1/tsconfig.lib.json',
'/libs/lib1/tsconfig.spec.json',
'/libs/lib2/tsconfig.lib.json',
'/libs/lib2/tsconfig.spec.json'
].forEach(tsConfig => {
const value = workspace_2.readJsonInTree(result, tsConfig);
expect(value.extends).toEqual('./tsconfig.json');
});
expect(workspace_2.readJsonInTree(result, 'apps/weird/app/src/tsconfig.app.json').extends).toEqual('../tsconfig.json');
expect(workspace_2.readJsonInTree(result, 'apps/weird/app/src/tsconfig.spec.json').extends).toEqual('../tsconfig.json');
}));
it('should edit existing tsconfigs to have a union of all types being used', () => __awaiter(this, void 0, void 0, function* () {
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
function getTypes(path) {
return workspace_2.readJsonInTree(result, path).compilerOptions.types;
}
expect(getTypes('apps/app1/tsconfig.json')).toEqual([
'jquery',
'jasmine',
'node',
'sinon'
]);
expect(getTypes('apps/app1-e2e/tsconfig.json')).toEqual([
'jasmine',
'jasminewd2',
'node'
]);
expect(getTypes('apps/app2/tsconfig.json')).toEqual(['jest', 'node']);
expect(getTypes('apps/app2-e2e/tsconfig.json')).toEqual([
'cypress',
'node'
]);
expect(getTypes('apps/node-app/tsconfig.json')).toEqual(['node', 'jest']);
expect(getTypes('apps/weird/app/tsconfig.json')).toBeUndefined();
expect(getTypes('libs/lib1/tsconfig.json')).toEqual(['jasmine', 'node']);
expect(getTypes('libs/lib2/tsconfig.json')).toEqual(['jest', 'node']);
}));
it("should not set types if one of the project's tsconfigs do not have types defined", () => __awaiter(this, void 0, void 0, function* () {
initialTree = yield schematicRunner
.callRule(workspace_2.updateJsonInTree('apps/app1/tsconfig.app.json', json => {
delete json.compilerOptions.types;
return json;
}), initialTree)
.toPromise();
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
function getTypes(path) {
return workspace_2.readJsonInTree(result, path).compilerOptions.types;
}
expect(getTypes('apps/app1/tsconfig.json')).toBeUndefined();
}));
describe('tsconfig.json', () => {
it('should be updated with es2015 modules', () => __awaiter(this, void 0, void 0, function* () {
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
const tsConfig = workspace_2.readJsonInTree(result, 'tsconfig.json');
expect(tsConfig.compilerOptions.module).toEqual('es2015');
}));
});
it('should update @ngrx dependencies to 6.1.2', () => __awaiter(this, void 0, void 0, function* () {
const result = yield schematicRunner
.runSchematicAsync('update-7.2.0', {}, initialTree)
.toPromise();
const { dependencies, devDependencies } = JSON.parse(result.readContent('package.json'));
expect(dependencies['@ngrx/effects']).toEqual('6.1.2');
expect(dependencies['@ngrx/router-store']).toEqual('6.1.2');
expect(dependencies['@ngrx/store']).toEqual('6.1.2');
expect(devDependencies['@ngrx/schematics']).toEqual('6.1.2');
expect(devDependencies['@ngrx/store-devtools']).toEqual('6.1.2');
}));
});