feat(core): add postinstall ngcc migration (#32999)

PR Close #32999
This commit is contained in:
Filipe Silva
2019-10-04 14:20:03 +01:00
committed by Miško Hevery
parent ca94d2b7f0
commit 30d25f67af
7 changed files with 182 additions and 0 deletions

View File

@ -11,6 +11,7 @@ ts_library(
"//packages/core/schematics/migrations/dynamic-queries",
"//packages/core/schematics/migrations/missing-injectable",
"//packages/core/schematics/migrations/move-document",
"//packages/core/schematics/migrations/postinstall-ngcc",
"//packages/core/schematics/migrations/renderer-to-renderer2",
"//packages/core/schematics/migrations/static-queries",
"//packages/core/schematics/migrations/template-var-assignment",

View File

@ -0,0 +1,58 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {EmptyTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
describe('postinstall ngcc migration', () => {
let runner: SchematicTestRunner;
let tree: UnitTestTree;
const pkgJsonPath = '/package.json';
const ngccPostinstall =
`"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"`;
beforeEach(() => {
runner = new SchematicTestRunner('test', require.resolve('../migrations.json'));
tree = new UnitTestTree(new EmptyTree());
});
it(`should add postinstall if scripts object is missing`, async() => {
tree.create(pkgJsonPath, JSON.stringify({}, null, 2));
await runMigration();
expect(tree.readContent(pkgJsonPath)).toContain(ngccPostinstall);
});
it(`should add postinstall if the script is missing`, async() => {
tree.create(pkgJsonPath, JSON.stringify({scripts: {}}, null, 2));
await runMigration();
expect(tree.readContent(pkgJsonPath)).toContain(ngccPostinstall);
});
it(`should prepend to postinstall if script already exists`, async() => {
tree.create(pkgJsonPath, JSON.stringify({scripts: {postinstall: 'do-something'}}, null, 2));
await runMigration();
expect(tree.readContent(pkgJsonPath))
.toContain(
`"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && do-something"`);
});
it(`should not prepend to postinstall if script contains ngcc`, async() => {
tree.create(pkgJsonPath, JSON.stringify({scripts: {postinstall: 'ngcc --something'}}, null, 2));
await runMigration();
expect(tree.readContent(pkgJsonPath)).toContain(`"postinstall": "ngcc --something"`);
expect(tree.readContent(pkgJsonPath)).not.toContain(ngccPostinstall);
expect(tree.readContent(pkgJsonPath))
.not.toContain(
`ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points`);
});
function runMigration() {
return runner.runSchematicAsync('migration-v9-postinstall-ngcc', {}, tree).toPromise();
}
});