@@ -182,6 +182,53 @@ describe('selectModulesInProjectSource', () => {
182182 expect ( result . getModel ( ) . modules ) . to . deep . equal ( [ ] ) ;
183183 } ) ;
184184
185+ it ( 'removes files that become comment-only' , ( ) => {
186+ const project = new Project ( {
187+ sources : [
188+ new ProjectSource (
189+ 'modules.json' ,
190+ JSON . stringify ( {
191+ modules : [ 'module1' , 'module2' , 'module3' , 'extra1' , 'extra2' ] ,
192+ } ) ,
193+ ) ,
194+ gql `
195+ # a comment in the keeper file
196+ type Keeper @rootEntity @modules(in: "module1", includeAllFields: true) {
197+ key: String @key
198+ }
199+ ` . loc ! . source ,
200+ gql `
201+ # a comment in the discard file
202+ type Discard @rootEntity @modules(in: "extra2", includeAllFields: true) {
203+ key: String @key
204+ }
205+ ` . loc ! . source ,
206+ // will also remove this one because we're throwing away comment-only file when
207+ // parsing a project. Documenting that behavior in this test case, but it's
208+ // probably fine either way
209+ {
210+ name : 'empty.graphqls' ,
211+ body : "# a file that's already comment-only" ,
212+ } ,
213+ ] ,
214+ modelOptions : { withModuleDefinitions : true } ,
215+ } ) ;
216+ expectToBeValid ( project ) ;
217+
218+ const result = project . withModuleSelection ( [ 'module1' , 'module2' ] , {
219+ removeModuleDeclarations : true ,
220+ } ) ;
221+ expectToBeValid ( result ) ;
222+ expect ( result . sources . map ( ( s ) => s . body ) ) . to . deep . equal ( [
223+ `
224+ # a comment in the keeper file
225+ type Keeper @rootEntity {
226+ key: String @key
227+ }
228+ ` ,
229+ ] ) ;
230+ } ) ;
231+
185232 it ( 'removes the modules part in an object file with modules and something else' , ( ) => {
186233 const project = new Project ( {
187234 sources : [
0 commit comments