11const { generateModelIntrospection, getModelIntrospection } = require ( '../../src/commands/model-intropection' ) ;
22const graphqlGenerator = require ( '@aws-amplify/graphql-generator' ) ;
3+ const codegen_core = require ( '@graphql-codegen/core' ) ;
34const mockFs = require ( 'mock-fs' ) ;
45const path = require ( 'path' ) ;
56const fs = require ( 'fs' ) ;
@@ -14,7 +15,6 @@ jest.mock('@aws-amplify/graphql-generator', () => {
1415jest . mock ( '@graphql-codegen/core' , ( ) => {
1516 const originalModule = jest . requireActual ( '@graphql-codegen/core' ) ;
1617 const codegen = jest . fn ( ) ;
17- codegen . mockReturnValue ( MOCK_GENERATED_CODE ) ;
1818 return {
1919 ...originalModule ,
2020 codegen,
@@ -27,6 +27,7 @@ const MOCK_PROJECT_NAME = 'myapp';
2727const MOCK_BACKEND_DIRECTORY = 'backend' ;
2828const MOCK_GENERATED_INTROSPECTION = { schemaVersion : 1 } ;
2929const MOCK_GENERATED_CODE = JSON . stringify ( MOCK_GENERATED_INTROSPECTION ) ;
30+
3031const MOCK_CONTEXT = {
3132 print : {
3233 info : jest . fn ( ) ,
@@ -55,7 +56,6 @@ const MOCK_CONTEXT = {
5556} ;
5657
5758describe ( 'generateModelIntrospection' , ( ) => {
58- graphqlGenerator . generateModels . mockReturnValue ( { 'model-introspection.json' : MOCK_GENERATED_CODE } ) ;
5959 const schemaFilePath = path . join ( MOCK_BACKEND_DIRECTORY , 'api' , MOCK_PROJECT_NAME ) ;
6060 const outputDirectory = path . join ( MOCK_PROJECT_ROOT , MOCK_OUTPUT_DIR ) ;
6161 const mockedFiles = { } ;
@@ -64,6 +64,11 @@ describe('generateModelIntrospection', () => {
6464 } ;
6565 mockedFiles [ outputDirectory ] = { } ;
6666
67+ beforeAll ( ( ) => {
68+ codegen_core . codegen . mockReturnValue ( MOCK_GENERATED_CODE ) ;
69+ graphqlGenerator . generateModels . mockReturnValue ( { 'model-introspection.json' : MOCK_GENERATED_CODE } ) ;
70+ } ) ;
71+
6772 beforeEach ( ( ) => {
6873 jest . clearAllMocks ( ) ;
6974 } ) ;
@@ -76,7 +81,7 @@ describe('generateModelIntrospection', () => {
7681 ...MOCK_CONTEXT ,
7782 parameters : {
7883 options : {
79- [ 'output-dir' ] : MOCK_OUTPUT_DIR ,
84+ 'output-dir' : MOCK_OUTPUT_DIR ,
8085 } ,
8186 } ,
8287 } ;
@@ -99,7 +104,7 @@ describe('generateModelIntrospection', () => {
99104} ) ;
100105
101106describe ( 'getModelIntrospection' , ( ) => {
102- graphqlGenerator . generateModels . mockReturnValue ( { 'model-introspection.json' : MOCK_GENERATED_CODE } ) ;
107+
103108 const schemaFilePath = path . join ( MOCK_BACKEND_DIRECTORY , 'api' , MOCK_PROJECT_NAME ) ;
104109 const outputDirectory = path . join ( MOCK_PROJECT_ROOT , MOCK_OUTPUT_DIR ) ;
105110 const mockedFiles = { } ;
@@ -108,6 +113,11 @@ describe('getModelIntrospection', () => {
108113 } ;
109114 mockedFiles [ outputDirectory ] = { } ;
110115
116+ beforeAll ( ( ) => {
117+ codegen_core . codegen . mockReturnValue ( MOCK_GENERATED_CODE ) ;
118+ graphqlGenerator . generateModels . mockReturnValue ( { 'model-introspection.json' : MOCK_GENERATED_CODE } ) ;
119+ } ) ;
120+
111121 beforeEach ( ( ) => {
112122 jest . clearAllMocks ( ) ;
113123 } ) ;
0 commit comments