@@ -52,122 +52,123 @@ describe('PWA Schematic', () => {
52
52
) ;
53
53
} ) ;
54
54
55
- it ( 'should run the service worker schematic' , ( done ) => {
56
- schematicRunner
57
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
58
-
59
- . then ( ( tree ) => {
60
- const configText = tree . readContent ( '/angular.json' ) ;
61
- const config = JSON . parse ( configText ) ;
62
- const swFlag = config . projects . bar . architect . build . options . serviceWorker ;
63
- expect ( swFlag ) . toEqual ( true ) ;
64
- done ( ) ;
65
- } , done . fail ) ;
66
- } ) ;
67
-
68
- it ( 'should create icon files' , ( done ) => {
55
+ it ( 'should create icon files' , async ( ) => {
69
56
const dimensions = [ 72 , 96 , 128 , 144 , 152 , 192 , 384 , 512 ] ;
70
57
const iconPath = '/projects/bar/src/assets/icons/icon-' ;
71
- schematicRunner
72
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
73
-
74
- . then ( ( tree ) => {
75
- dimensions . forEach ( ( d ) => {
76
- const path = `${ iconPath } ${ d } x${ d } .png` ;
77
- expect ( tree . exists ( path ) ) . toEqual ( true ) ;
78
- } ) ;
79
- done ( ) ;
80
- } , done . fail ) ;
58
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
59
+
60
+ dimensions . forEach ( ( d ) => {
61
+ const path = `${ iconPath } ${ d } x${ d } .png` ;
62
+ expect ( tree . exists ( path ) ) . toBeTrue ( ) ;
63
+ } ) ;
81
64
} ) ;
82
65
83
- it ( 'should create a manifest file' , ( done ) => {
84
- schematicRunner
85
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
66
+ it ( 'should run the service worker schematic' , async ( ) => {
67
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
68
+ const configText = tree . readContent ( '/angular.json' ) ;
69
+ const config = JSON . parse ( configText ) ;
70
+ const swFlag = config . projects . bar . architect . build . configurations . production . serviceWorker ;
86
71
87
- . then ( ( tree ) => {
88
- expect ( tree . exists ( '/projects/bar/src/manifest.webmanifest' ) ) . toEqual ( true ) ;
89
- done ( ) ;
90
- } , done . fail ) ;
72
+ expect ( swFlag ) . toBe ( 'projects/bar/ngsw-config.json' ) ;
91
73
} ) ;
92
74
93
- it ( 'should set the name & short_name in the manifest file' , ( done ) => {
94
- schematicRunner
95
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
75
+ it ( 'should create a manifest file' , async ( ) => {
76
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
77
+ expect ( tree . exists ( '/projects/bar/src/manifest.webmanifest' ) ) . toBeTrue ( ) ;
78
+ } ) ;
79
+
80
+ it ( 'should set the name & short_name in the manifest file' , async ( ) => {
81
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
96
82
97
- . then ( ( tree ) => {
98
- const manifestText = tree . readContent ( '/projects/bar/src/manifest.webmanifest' ) ;
99
- const manifest = JSON . parse ( manifestText ) ;
83
+ const manifestText = tree . readContent ( '/projects/bar/src/manifest.webmanifest' ) ;
84
+ const manifest = JSON . parse ( manifestText ) ;
100
85
101
- expect ( manifest . name ) . toEqual ( defaultOptions . title ) ;
102
- expect ( manifest . short_name ) . toEqual ( defaultOptions . title ) ;
103
- done ( ) ;
104
- } , done . fail ) ;
86
+ expect ( manifest . name ) . toEqual ( defaultOptions . title ) ;
87
+ expect ( manifest . short_name ) . toEqual ( defaultOptions . title ) ;
105
88
} ) ;
106
89
107
- it ( 'should set the name & short_name in the manifest file when no title provided' , ( done ) => {
90
+ it ( 'should set the name & short_name in the manifest file when no title provided' , async ( ) => {
108
91
const options = { ...defaultOptions , title : undefined } ;
109
- schematicRunner
110
- . runSchematic ( 'ng-add' , options , appTree )
92
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , options , appTree ) ;
111
93
112
- . then ( ( tree ) => {
113
- const manifestText = tree . readContent ( '/projects/bar/src/manifest.webmanifest' ) ;
114
- const manifest = JSON . parse ( manifestText ) ;
94
+ const manifestText = tree . readContent ( '/projects/bar/src/manifest.webmanifest' ) ;
95
+ const manifest = JSON . parse ( manifestText ) ;
115
96
116
- expect ( manifest . name ) . toEqual ( defaultOptions . project ) ;
117
- expect ( manifest . short_name ) . toEqual ( defaultOptions . project ) ;
118
- done ( ) ;
119
- } , done . fail ) ;
97
+ expect ( manifest . name ) . toEqual ( defaultOptions . project ) ;
98
+ expect ( manifest . short_name ) . toEqual ( defaultOptions . project ) ;
120
99
} ) ;
121
100
122
- it ( 'should update the index file' , ( done ) => {
123
- schematicRunner
124
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
125
-
126
- . then ( ( tree ) => {
127
- const content = tree . readContent ( 'projects/bar/src/index.html' ) ;
101
+ it ( 'should update the index file' , async ( ) => {
102
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
103
+ const content = tree . readContent ( 'projects/bar/src/index.html' ) ;
128
104
129
- expect ( content ) . toMatch ( / < l i n k r e l = " m a n i f e s t " h r e f = " m a n i f e s t .w e b m a n i f e s t " > / ) ;
130
- expect ( content ) . toMatch ( / < m e t a n a m e = " t h e m e - c o l o r " c o n t e n t = " # 1 9 7 6 d 2 " > / ) ;
131
- expect ( content ) . toMatch (
132
- / < n o s c r i p t > P l e a s e e n a b l e J a v a S c r i p t t o c o n t i n u e u s i n g t h i s a p p l i c a t i o n .< \/ n o s c r i p t > / ,
133
- ) ;
134
- done ( ) ;
135
- } , done . fail ) ;
105
+ expect ( content ) . toMatch ( / < l i n k r e l = " m a n i f e s t " h r e f = " m a n i f e s t .w e b m a n i f e s t " > / ) ;
106
+ expect ( content ) . toMatch ( / < m e t a n a m e = " t h e m e - c o l o r " c o n t e n t = " # 1 9 7 6 d 2 " > / ) ;
107
+ expect ( content ) . toMatch (
108
+ / < n o s c r i p t > P l e a s e e n a b l e J a v a S c r i p t t o c o n t i n u e u s i n g t h i s a p p l i c a t i o n .< \/ n o s c r i p t > / ,
109
+ ) ;
136
110
} ) ;
137
111
138
- it ( 'should not add noscript element to the index file if already present' , ( done ) => {
112
+ it ( 'should not add noscript element to the index file if already present' , async ( ) => {
139
113
let index = appTree . readContent ( 'projects/bar/src/index.html' ) ;
140
114
index = index . replace ( '</body>' , '<noscript>NO JAVASCRIPT</noscript></body>' ) ;
141
115
appTree . overwrite ( 'projects/bar/src/index.html' , index ) ;
142
- schematicRunner
143
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
144
-
145
- . then ( ( tree ) => {
146
- const content = tree . readContent ( 'projects/bar/src/index.html' ) ;
147
-
148
- expect ( content ) . toMatch ( / < l i n k r e l = " m a n i f e s t " h r e f = " m a n i f e s t .w e b m a n i f e s t " > / ) ;
149
- expect ( content ) . toMatch ( / < m e t a n a m e = " t h e m e - c o l o r " c o n t e n t = " # 1 9 7 6 d 2 " > / ) ;
150
- expect ( content ) . not . toMatch (
151
- / < n o s c r i p t > P l e a s e e n a b l e J a v a S c r i p t t o c o n t i n u e u s i n g t h i s a p p l i c a t i o n .< \/ n o s c r i p t > / ,
152
- ) ;
153
- expect ( content ) . toMatch ( / < n o s c r i p t > N O J A V A S C R I P T < \/ n o s c r i p t > / ) ;
154
- done ( ) ;
155
- } , done . fail ) ;
116
+
117
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
118
+ const content = tree . readContent ( 'projects/bar/src/index.html' ) ;
119
+
120
+ expect ( content ) . toMatch ( / < l i n k r e l = " m a n i f e s t " h r e f = " m a n i f e s t .w e b m a n i f e s t " > / ) ;
121
+ expect ( content ) . toMatch ( / < m e t a n a m e = " t h e m e - c o l o r " c o n t e n t = " # 1 9 7 6 d 2 " > / ) ;
122
+ expect ( content ) . not . toMatch (
123
+ / < n o s c r i p t > P l e a s e e n a b l e J a v a S c r i p t t o c o n t i n u e u s i n g t h i s a p p l i c a t i o n .< \/ n o s c r i p t > / ,
124
+ ) ;
125
+ expect ( content ) . toMatch ( / < n o s c r i p t > N O J A V A S C R I P T < \/ n o s c r i p t > / ) ;
156
126
} ) ;
157
127
158
- it ( 'should update the build and test assets configuration' , ( done ) => {
159
- schematicRunner
160
- . runSchematic ( 'ng-add' , defaultOptions , appTree )
128
+ it ( 'should update the build and test assets configuration' , async ( ) => {
129
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
130
+ const configText = tree . readContent ( '/angular.json' ) ;
131
+ const config = JSON . parse ( configText ) ;
132
+ const targets = config . projects . bar . architect ;
161
133
162
- . then ( ( tree ) => {
163
- const configText = tree . readContent ( '/angular.json ') ;
164
- const config = JSON . parse ( configText ) ;
165
- const targets = config . projects . bar . architect ;
134
+ [ 'build' , 'test' ] . forEach ( ( target ) => {
135
+ expect ( targets [ target ] . options . assets ) . toContain ( 'projects/bar/src/manifest.webmanifest ') ;
136
+ } ) ;
137
+ } ) ;
166
138
167
- [ 'build' , 'test' ] . forEach ( ( target ) => {
168
- expect ( targets [ target ] . options . assets ) . toContain ( 'projects/bar/src/manifest.webmanifest' ) ;
169
- } ) ;
170
- done ( ) ;
171
- } , done . fail ) ;
139
+ describe ( 'Legacy browser builder' , ( ) => {
140
+ function convertBuilderToLegacyBrowser ( ) : void {
141
+ const config = JSON . parse ( appTree . readContent ( '/angular.json' ) ) ;
142
+ const build = config . projects . bar . architect . build ;
143
+
144
+ build . builder = '@angular-devkit/build-angular:browser' ;
145
+ build . options = {
146
+ ...build . options ,
147
+ main : build . options . browser ,
148
+ browser : undefined ,
149
+ } ;
150
+
151
+ build . configurations . development = {
152
+ ...build . configurations . development ,
153
+ vendorChunk : true ,
154
+ namedChunks : true ,
155
+ buildOptimizer : false ,
156
+ } ;
157
+
158
+ appTree . overwrite ( '/angular.json' , JSON . stringify ( config , undefined , 2 ) ) ;
159
+ }
160
+
161
+ beforeEach ( ( ) => {
162
+ convertBuilderToLegacyBrowser ( ) ;
163
+ } ) ;
164
+
165
+ it ( 'should run the service worker schematic' , async ( ) => {
166
+ const tree = await schematicRunner . runSchematic ( 'ng-add' , defaultOptions , appTree ) ;
167
+ const configText = tree . readContent ( '/angular.json' ) ;
168
+ const config = JSON . parse ( configText ) ;
169
+ const swFlag = config . projects . bar . architect . build . options . serviceWorker ;
170
+
171
+ expect ( swFlag ) . toBeTrue ( ) ;
172
+ } ) ;
172
173
} ) ;
173
174
} ) ;
0 commit comments