This repository was archived by the owner on Nov 22, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
express-engine/schematics/install
hapi-engine/schematics/install Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,8 +131,23 @@ describe('Universal Schematic', () => {
131131 . toPromise ( ) ;
132132 const filePath = '/projects/bar/src/main.server.ts' ;
133133 const contents = tree . readContent ( filePath ) ;
134- console . log ( { contents} ) ;
135134 expect ( contents ) . toContain ( 'ngExpressEngine' ) ;
136135 expect ( contents ) . toContain ( 'provideModuleMap' ) ;
137136 } ) ;
137+
138+ it ( 'should update angular.json' , async ( ) => {
139+ const tree = await schematicRunner
140+ . runSchematicAsync ( 'ng-add' , defaultOptions , appTree )
141+ . toPromise ( ) ;
142+ const contents = JSON . parse ( tree . readContent ( 'angular.json' ) ) ;
143+ const architect = contents . projects . bar . architect ;
144+ expect ( architect . build . configurations . production ) . toBeDefined ( ) ;
145+ expect ( architect . build . options . outputPath ) . toBe ( 'dist/browser' ) ;
146+ expect ( architect . server . options . outputPath ) . toBe ( 'dist/server' ) ;
147+
148+ const productionConfig = architect . server . configurations . production ;
149+ expect ( productionConfig . fileReplacements ) . toBeDefined ( ) ;
150+ expect ( productionConfig . optimization ) . toBeDefined ( ) ;
151+ expect ( productionConfig . sourceMap ) . toBeDefined ( ) ;
152+ } ) ;
138153} ) ;
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ function updateConfigFile(options: UniversalOptions) {
116116 const clientProject = workspace . projects . get ( options . clientProject ) ;
117117 if ( clientProject ) {
118118 const buildTarget = clientProject . targets . get ( 'build' ) ;
119- const serverTarget = clientProject . targets . get ( 'build ' ) ;
119+ const serverTarget = clientProject . targets . get ( 'server ' ) ;
120120
121121 // We have to check if the project config has a server target, because
122122 // if the Universal step in this schematic isn't run, it can't be guaranteed
@@ -125,23 +125,13 @@ function updateConfigFile(options: UniversalOptions) {
125125 return ;
126126 }
127127
128- serverTarget . configurations = {
129- production : {
130- fileReplacements : [
131- {
132- replace : 'src/environments/environment.ts' ,
133- with : 'src/environments/environment.prod.ts'
134- }
135- ]
136- }
137- } ;
138-
139128 serverTarget . options = {
140129 ...serverTarget . options ,
141130 outputPath : SERVER_DIST ,
142131 } ;
143132
144133 buildTarget . options = {
134+ ...buildTarget . options ,
145135 outputPath : BROWSER_DIST ,
146136 } ;
147137 }
Original file line number Diff line number Diff line change @@ -131,8 +131,23 @@ describe('Universal Schematic', () => {
131131 . toPromise ( ) ;
132132 const filePath = '/projects/bar/src/main.server.ts' ;
133133 const contents = tree . readContent ( filePath ) ;
134- console . log ( { contents} ) ;
135134 expect ( contents ) . toContain ( 'ngHapiEngine' ) ;
136135 expect ( contents ) . toContain ( 'provideModuleMap' ) ;
137136 } ) ;
137+
138+ it ( 'should update angular.json' , async ( ) => {
139+ const tree = await schematicRunner
140+ . runSchematicAsync ( 'ng-add' , defaultOptions , appTree )
141+ . toPromise ( ) ;
142+ const contents = JSON . parse ( tree . readContent ( 'angular.json' ) ) ;
143+ const architect = contents . projects . bar . architect ;
144+ expect ( architect . build . configurations . production ) . toBeDefined ( ) ;
145+ expect ( architect . build . options . outputPath ) . toBe ( 'dist/browser' ) ;
146+ expect ( architect . server . options . outputPath ) . toBe ( 'dist/server' ) ;
147+
148+ const productionConfig = architect . server . configurations . production ;
149+ expect ( productionConfig . fileReplacements ) . toBeDefined ( ) ;
150+ expect ( productionConfig . sourceMap ) . toBeDefined ( ) ;
151+ expect ( productionConfig . optimization ) . toBeDefined ( ) ;
152+ } ) ;
138153} ) ;
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ function updateConfigFile(options: UniversalOptions) {
121121 const clientProject = workspace . projects . get ( options . clientProject ) ;
122122 if ( clientProject ) {
123123 const buildTarget = clientProject . targets . get ( 'build' ) ;
124- const serverTarget = clientProject . targets . get ( 'build ' ) ;
124+ const serverTarget = clientProject . targets . get ( 'server ' ) ;
125125
126126 // We have to check if the project config has a server target, because
127127 // if the Universal step in this schematic isn't run, it can't be guaranteed
@@ -130,23 +130,13 @@ function updateConfigFile(options: UniversalOptions) {
130130 return ;
131131 }
132132
133- serverTarget . configurations = {
134- production : {
135- fileReplacements : [
136- {
137- replace : 'src/environments/environment.ts' ,
138- with : 'src/environments/environment.prod.ts'
139- }
140- ]
141- }
142- } ;
143-
144133 serverTarget . options = {
145134 ...serverTarget . options ,
146135 outputPath : SERVER_DIST ,
147136 } ;
148137
149138 buildTarget . options = {
139+ ...buildTarget . options ,
150140 outputPath : BROWSER_DIST ,
151141 } ;
152142 }
You can’t perform that action at this time.
0 commit comments