forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-workspace-config_spec.ts
112 lines (100 loc) · 3.64 KB
/
update-workspace-config_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @license
* Copyright Google LLC 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';
import { Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models';
function createWorkSpaceConfig(tree: UnitTestTree) {
const angularConfig: WorkspaceSchema = {
version: 1,
projects: {
app: {
root: '/project/lib',
sourceRoot: '/project/app/src',
projectType: ProjectType.Application,
prefix: 'app',
architect: {
'app-shell': {
builder: Builders.AppShell,
options: {
browserTarget: 'app:build',
serverTarget: 'app:server',
route: '',
},
configurations: {
production: {
browserTarget: 'app:build:production',
serverTarget: 'app:server:production',
},
},
},
serve: {
builder: Builders.DevServer,
options: {
browserTarget: 'app:build:development',
},
configurations: {
production: {
browserTarget: 'app:build:production',
},
},
},
i18n: {
builder: Builders.ExtractI18n,
options: {
browserTarget: 'app:build:production',
},
},
},
},
},
};
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
}
describe(`Migration to update 'angular.json'.`, () => {
const schematicName = 'update-workspace-config';
const schematicRunner = new SchematicTestRunner(
'migrations',
require.resolve('../migration-collection.json'),
);
let tree: UnitTestTree;
beforeEach(() => {
tree = new UnitTestTree(new EmptyTree());
createWorkSpaceConfig(tree);
});
it(`should replace 'browserTarget' when using '@angular-devkit/build-angular:dev-server'`, async () => {
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
const {
projects: { app },
} = JSON.parse(newTree.readContent('/angular.json'));
const { browserTarget, buildTarget } = app.architect['serve'].options;
expect(browserTarget).toBeUndefined();
expect(buildTarget).toBe('app:build:development');
const { browserTarget: browserTargetProd, buildTarget: buildTargetProd } =
app.architect['serve'].configurations['production'];
expect(browserTargetProd).toBeUndefined();
expect(buildTargetProd).toBe('app:build:production');
});
it(`should replace 'browserTarget' when using '@angular-devkit/build-angular:extract-i18n'`, async () => {
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
const {
projects: { app },
} = JSON.parse(newTree.readContent('/angular.json'));
const { browserTarget, buildTarget } = app.architect['i18n'].options;
expect(browserTarget).toBeUndefined();
expect(buildTarget).toBe('app:build:production');
});
it(`should not replace 'browserTarget' when using other builders`, async () => {
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree);
const {
projects: { app },
} = JSON.parse(newTree.readContent('/angular.json'));
const { browserTarget, buildTarget } = app.architect['app-shell'].options;
expect(browserTarget).toBe('app:build');
expect(buildTarget).toBeUndefined();
});
});