5
5
updateProjectConfiguration ,
6
6
removeProjectConfiguration ,
7
7
getProjects ,
8
+ readWorkspaceConfiguration ,
9
+ WorkspaceConfiguration ,
10
+ updateWorkspaceConfiguration ,
8
11
} from './project-configuration' ;
9
12
import { createTreeWithEmptyWorkspace } from '../tests/create-tree-with-empty-workspace' ;
10
13
import { ProjectConfiguration } from '@nrwl/tao/src/shared/workspace' ;
@@ -23,115 +26,149 @@ describe('project configuration', () => {
23
26
tree = createTreeWithEmptyWorkspace ( ) ;
24
27
} ) ;
25
28
26
- it ( 'should create project.json file when adding a project if standalone is true' , ( ) => {
27
- addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
29
+ describe ( 'addProjectConfiguration' , ( ) => {
30
+ it ( 'should create project.json file when adding a project if standalone is true' , ( ) => {
31
+ addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
28
32
29
- expect ( tree . exists ( 'libs/test/project.json' ) ) . toBeTruthy ( ) ;
30
- } ) ;
33
+ expect ( tree . exists ( 'libs/test/project.json' ) ) . toBeTruthy ( ) ;
34
+ } ) ;
31
35
32
- it ( 'should create project.json file if all other apps in the workspace use project.json' , ( ) => {
33
- addProjectConfiguration (
34
- tree ,
35
- 'project-a' ,
36
- {
36
+ it ( 'should create project.json file if all other apps in the workspace use project.json' , ( ) => {
37
+ addProjectConfiguration (
38
+ tree ,
39
+ 'project-a' ,
40
+ {
41
+ root : 'apps/project-a' ,
42
+ targets : { } ,
43
+ } ,
44
+ true
45
+ ) ;
46
+ addProjectConfiguration (
47
+ tree ,
48
+ 'project-b' ,
49
+ {
50
+ root : 'apps/project-b' ,
51
+ targets : { } ,
52
+ } ,
53
+ true
54
+ ) ;
55
+ expect ( tree . exists ( 'apps/project-b/project.json' ) ) . toBeTruthy ( ) ;
56
+ } ) ;
57
+
58
+ it ( "should not create project.json file if any other app in the workspace doesn't use project.json" , ( ) => {
59
+ addProjectConfiguration ( tree , 'project-a' , {
37
60
root : 'apps/project-a' ,
38
61
targets : { } ,
39
- } ,
40
- true
41
- ) ;
42
- addProjectConfiguration (
43
- tree ,
44
- 'project-b' ,
45
- {
62
+ } ) ;
63
+ addProjectConfiguration ( tree , 'project-b' , {
46
64
root : 'apps/project-b' ,
47
65
targets : { } ,
48
- } ,
49
- true
50
- ) ;
51
- expect ( tree . exists ( 'apps/project-b/project.json' ) ) . toBeTruthy ( ) ;
52
- } ) ;
66
+ } ) ;
67
+ expect ( tree . exists ( 'apps/project-a/project.json' ) ) . toBeFalsy ( ) ;
68
+ expect ( tree . exists ( 'apps/project-b/project.json' ) ) . toBeFalsy ( ) ;
69
+ } ) ;
70
+
71
+ it ( 'should not create project.json file when adding a project if standalone is false' , ( ) => {
72
+ addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , false ) ;
53
73
54
- it ( "should not create project.json file if any other app in the workspace doesn't use project.json" , ( ) => {
55
- addProjectConfiguration ( tree , 'project-a' , {
56
- root : 'apps/project-a' ,
57
- targets : { } ,
74
+ expect ( tree . exists ( 'libs/test/project.json' ) ) . toBeFalsy ( ) ;
58
75
} ) ;
59
- addProjectConfiguration ( tree , 'project-b' , {
60
- root : 'apps/project-b' ,
61
- targets : { } ,
76
+
77
+ it ( 'should be able to read from standalone projects' , ( ) => {
78
+ tree . write (
79
+ 'libs/test/project.json' ,
80
+ JSON . stringify ( baseTestProjectConfig , null , 2 )
81
+ ) ;
82
+ tree . write (
83
+ 'workspace.json' ,
84
+ JSON . stringify (
85
+ {
86
+ projects : {
87
+ test : 'libs/test' ,
88
+ } ,
89
+ } ,
90
+ null ,
91
+ 2
92
+ )
93
+ ) ;
94
+
95
+ const projectConfig = readProjectConfiguration ( tree , 'test' ) ;
96
+
97
+ expect ( projectConfig ) . toEqual ( baseTestProjectConfig ) ;
62
98
} ) ;
63
- expect ( tree . exists ( 'apps/project-a/project.json' ) ) . toBeFalsy ( ) ;
64
- expect ( tree . exists ( 'apps/project-b/project.json' ) ) . toBeFalsy ( ) ;
65
- } ) ;
66
99
67
- it ( 'should not create project.json file when adding a project if standalone is false' , ( ) => {
68
- addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , false ) ;
100
+ it ( 'should update project.json file when updating a project' , ( ) => {
101
+ addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
102
+ const expectedProjectConfig = {
103
+ ...baseTestProjectConfig ,
104
+ targets : { build : { executor : '' } } ,
105
+ } ;
106
+ updateProjectConfiguration ( tree , 'test' , expectedProjectConfig ) ;
107
+
108
+ expect ( readJson ( tree , 'libs/test/project.json' ) ) . toEqual (
109
+ expectedProjectConfig
110
+ ) ;
111
+ } ) ;
69
112
70
- expect ( tree . exists ( 'libs/test/project.json' ) ) . toBeFalsy ( ) ;
71
- } ) ;
113
+ it ( 'should update workspace.json file when updating an inline project' , ( ) => {
114
+ addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , false ) ;
115
+ const expectedProjectConfig = {
116
+ ...baseTestProjectConfig ,
117
+ targets : { build : { executor : '' } } ,
118
+ } ;
119
+ updateProjectConfiguration ( tree , 'test' , expectedProjectConfig ) ;
120
+
121
+ expect ( readJson ( tree , 'workspace.json' ) . projects . test ) . toEqual (
122
+ expectedProjectConfig
123
+ ) ;
124
+ } ) ;
72
125
73
- it ( 'should be able to read from standalone projects' , ( ) => {
74
- tree . write (
75
- 'libs/test/project.json' ,
76
- JSON . stringify ( baseTestProjectConfig , null , 2 )
77
- ) ;
78
- tree . write (
79
- 'workspace.json' ,
80
- JSON . stringify (
81
- {
82
- projects : {
83
- test : 'libs/test' ,
84
- } ,
85
- } ,
86
- null ,
87
- 2
88
- )
89
- ) ;
126
+ it ( 'should remove project.json file when removing project configuration' , ( ) => {
127
+ addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
128
+ removeProjectConfiguration ( tree , 'test' ) ;
90
129
91
- const projectConfig = readProjectConfiguration ( tree , 'test' ) ;
130
+ expect ( readJson ( tree , 'workspace.json' ) . projects . test ) . toBeUndefined ( ) ;
131
+ expect ( tree . exists ( 'test/project.json' ) ) . toBeFalsy ( ) ;
132
+ } ) ;
92
133
93
- expect ( projectConfig ) . toEqual ( baseTestProjectConfig ) ;
134
+ it ( 'should support workspaces with standalone and inline projects' , ( ) => {
135
+ addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
136
+ addProjectConfiguration ( tree , 'test2' , baseTestProjectConfig , false ) ;
137
+ const configurations = getProjects ( tree ) ;
138
+ expect ( configurations . get ( 'test' ) ) . toEqual ( baseTestProjectConfig ) ;
139
+ expect ( configurations . get ( 'test2' ) ) . toEqual ( baseTestProjectConfig ) ;
140
+ } ) ;
94
141
} ) ;
95
142
96
- it ( 'should update project.json file when updating a project' , ( ) => {
97
- addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
98
- const expectedProjectConfig = {
99
- ...baseTestProjectConfig ,
100
- targets : { build : { executor : '' } } ,
101
- } ;
102
- updateProjectConfiguration ( tree , 'test' , expectedProjectConfig ) ;
103
-
104
- expect ( readJson ( tree , 'libs/test/project.json' ) ) . toEqual (
105
- expectedProjectConfig
106
- ) ;
107
- } ) ;
143
+ describe ( 'updateWorkspaceConfiguration' , ( ) => {
144
+ let workspaceConfiguration : WorkspaceConfiguration ;
145
+ beforeEach ( ( ) => {
146
+ workspaceConfiguration = readWorkspaceConfiguration ( tree ) ;
147
+ } ) ;
108
148
109
- it ( 'should update workspace.json file when updating an inline project' , ( ) => {
110
- addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , false ) ;
111
- const expectedProjectConfig = {
112
- ...baseTestProjectConfig ,
113
- targets : { build : { executor : '' } } ,
114
- } ;
115
- updateProjectConfiguration ( tree , 'test' , expectedProjectConfig ) ;
116
-
117
- expect ( readJson ( tree , 'workspace.json' ) . projects . test ) . toEqual (
118
- expectedProjectConfig
119
- ) ;
120
- } ) ;
149
+ it ( 'should update properties in workspace.json' , ( ) => {
150
+ workspaceConfiguration . version = 3 ;
121
151
122
- it ( 'should remove project.json file when removing project configuration' , ( ) => {
123
- addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
124
- removeProjectConfiguration ( tree , 'test' ) ;
152
+ updateWorkspaceConfiguration ( tree , workspaceConfiguration ) ;
125
153
126
- expect ( readJson ( tree , 'workspace.json' ) . projects . test ) . toBeUndefined ( ) ;
127
- expect ( tree . exists ( 'test/project.json' ) ) . toBeFalsy ( ) ;
128
- } ) ;
154
+ expect ( readJson ( tree , 'workspace.json' ) . version ) . toEqual ( 3 ) ;
155
+ } ) ;
156
+
157
+ it ( 'should update properties in nx.json' , ( ) => {
158
+ workspaceConfiguration . npmScope = 'new-npmScope' ;
129
159
130
- it ( 'should support workspaces with standalone and inline projects' , ( ) => {
131
- addProjectConfiguration ( tree , 'test' , baseTestProjectConfig , true ) ;
132
- addProjectConfiguration ( tree , 'test2' , baseTestProjectConfig , false ) ;
133
- const configurations = getProjects ( tree ) ;
134
- expect ( configurations . get ( 'test' ) ) . toEqual ( baseTestProjectConfig ) ;
135
- expect ( configurations . get ( 'test2' ) ) . toEqual ( baseTestProjectConfig ) ;
160
+ updateWorkspaceConfiguration ( tree , workspaceConfiguration ) ;
161
+
162
+ expect ( readJson ( tree , 'nx.json' ) . npmScope ) . toEqual ( 'new-npmScope' ) ;
163
+ } ) ;
164
+
165
+ it ( 'should not update unknown properties' , ( ) => {
166
+ workspaceConfiguration [ '$schema' ] = 'schema' ;
167
+
168
+ updateWorkspaceConfiguration ( tree , workspaceConfiguration ) ;
169
+
170
+ expect ( readJson ( tree , 'workspace.json' ) . $schema ) . not . toBeDefined ( ) ;
171
+ expect ( readJson ( tree , 'nx.json' ) . $schema ) . not . toBeDefined ( ) ;
172
+ } ) ;
136
173
} ) ;
137
174
} ) ;
0 commit comments