@@ -35,8 +35,8 @@ const MOCK_CONTEXT = {
3535 } ,
3636} ;
3737const OUTPUT_PATHS = {
38- javascript : 'src' ,
39- android : 'app/src/main/java' ,
38+ javascript : 'src/models ' ,
39+ android : 'app/src/main/java/com/amplifyframework/datastore/generated/model ' ,
4040 ios : 'amplify/generated/models' ,
4141 flutter : 'lib/models' ,
4242} ;
@@ -60,7 +60,7 @@ describe('command-models-generates models in expected output path', () => {
6060 const outputDirectory = path . join ( MOCK_PROJECT_ROOT , OUTPUT_PATHS [ frontend ] ) ;
6161 const mockedFiles = { } ;
6262 mockedFiles [ schemaFilePath ] = {
63- 'schema.graphql' : ' type SimpleModel { id: ID! status: String } ' ,
63+ 'schema.graphql' : ' type SimpleModel @model { id: ID! status: String } ' ,
6464 } ;
6565 mockedFiles [ outputDirectory ] = { } ;
6666 mockFs ( mockedFiles ) ;
@@ -75,7 +75,7 @@ describe('command-models-generates models in expected output path', () => {
7575 expect ( graphqlCodegen . codegen ) . toBeCalled ( ) ;
7676
7777 // assert model files are generated in expected output directory
78- expect ( fs . readdirSync ( outputDirectory ) . length ) . toBeGreaterThan ( 0 ) ;
78+ expect ( fs . readdirSync ( outputDirectory ) ) . toMatchSnapshot ( ) ;
7979 } ) ;
8080
8181 it ( frontend + ': Should generate models from any subdirectory in schema folder' , async ( ) => {
@@ -99,7 +99,35 @@ describe('command-models-generates models in expected output path', () => {
9999 expect ( graphqlCodegen . codegen ) . toBeCalled ( ) ;
100100
101101 // assert model files are generated in expected output directory
102- expect ( fs . readdirSync ( outputDirectory ) . length ) . toBeGreaterThan ( 0 ) ;
102+ expect ( fs . readdirSync ( outputDirectory ) ) . toMatchSnapshot ( ) ;
103+ } ) ;
104+
105+ it ( frontend + ': Should generate models in overrideOutputDir' , async ( ) => {
106+ // mock the input and output file structure
107+ const schemaFilePath = path . join ( MOCK_BACKEND_DIRECTORY , 'api' , MOCK_PROJECT_NAME ) ;
108+ const outputDirectory = path . join ( MOCK_PROJECT_ROOT , OUTPUT_PATHS [ frontend ] ) ;
109+ const mockedFiles = { } ;
110+ mockedFiles [ schemaFilePath ] = {
111+ 'schema.graphql' : ' type SimpleModel @model { id: ID! status: String } ' ,
112+ } ;
113+ const overrideOutputDir = 'some/other/dir' ;
114+ mockedFiles [ outputDirectory ] = { } ;
115+ mockedFiles [ overrideOutputDir ] = { } ;
116+ mockFs ( mockedFiles ) ;
117+ MOCK_CONTEXT . amplify . getProjectConfig . mockReturnValue ( { frontend : frontend } ) ;
118+
119+ // assert empty folder before generation
120+ expect ( fs . readdirSync ( outputDirectory ) . length ) . toEqual ( 0 ) ;
121+ expect ( fs . readdirSync ( overrideOutputDir ) . length ) . toEqual ( 0 ) ;
122+
123+ await generateModels ( MOCK_CONTEXT , { overrideOutputDir } ) ;
124+
125+ // assert model generation succeeds with a single schema file
126+ expect ( graphqlCodegen . codegen ) . toBeCalled ( ) ;
127+
128+ // assert model files are generated in expected output directory
129+ expect ( fs . readdirSync ( outputDirectory ) . length ) . toEqual ( 0 ) ;
130+ expect ( fs . readdirSync ( overrideOutputDir ) . length ) . not . toEqual ( 0 ) ;
103131 } ) ;
104132
105133 if ( frontend === 'flutter' ) {
0 commit comments