@@ -6,6 +6,7 @@ import { getFileContent } from '@schematics/angular/utility/test';
66import { join } from 'path' ;
77
88import { setupProject } from '../utils/test-utils' ;
9+ import { getPackageJson } from '../utils/utils' ;
910
1011const schematicCollectionPath = join (
1112 __dirname ,
@@ -33,6 +34,8 @@ exports.config = {
3334};
3435` ;
3536
37+ const ANGULAR_CONF_PATH = '/angular.json' ;
38+
3639const defaultOptions = Object . freeze ( {
3740 project : 'defaultProject'
3841} ) ;
@@ -83,9 +86,7 @@ describe('scully schematic', () => {
8386
8487 it ( `should modify the 'package.json'` , ( ) => {
8588 expect ( appTree . files ) . toContain ( PACKAGE_JSON_PATH ) ;
86- const packageJson = JSON . parse (
87- getFileContent ( appTree , PACKAGE_JSON_PATH )
88- ) ;
89+ const packageJson = getPackageJson ( appTree ) ;
8990 const { scripts } = packageJson ;
9091 expect ( scripts . scully ) . toEqual ( 'scully' ) ;
9192 expect ( scripts [ 'scully:serve' ] ) . toEqual ( 'scully serve' ) ;
@@ -103,4 +104,24 @@ describe('scully schematic', () => {
103104 expect ( getFileContent ( appTree , SCULLY_PATH ) ) . toEqual ( 'foo' ) ;
104105 } ) ;
105106 } ) ;
107+
108+ describe ( 'when the angular.json contains any comment' , ( ) => {
109+ it ( 'should deal with it' , async ( ) => {
110+ const options = { ...defaultOptions } ;
111+ const angularConfigContent = getFileContent ( appTree , ANGULAR_CONF_PATH ) ;
112+ const angularConfigLines = angularConfigContent . split ( '\n' ) ;
113+ angularConfigLines [ 3 ] += ` // dummy comment` ;
114+ appTree . overwrite ( ANGULAR_CONF_PATH , angularConfigLines . join ( '\n' ) ) ;
115+ const NO_ERROR = '' ;
116+ let error = NO_ERROR ;
117+ try {
118+ await customRunner
119+ . runSchematicAsync ( 'scully' , options , appTree )
120+ . toPromise ( ) ;
121+ } catch ( e ) {
122+ error = e ;
123+ }
124+ expect ( error ) . toEqual ( NO_ERROR ) ;
125+ } ) ;
126+ } ) ;
106127} ) ;
0 commit comments