Skip to content

Commit 0c9db5b

Browse files
author
Dane Pilcher
authored
test: add mock fs multiple swift file test (#721)
1 parent cdca3eb commit 0c9db5b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/amplify-codegen/tests/commands/mock-fs-setup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ const { getOutputFileName } = require('@aws-amplify/graphql-types-generator');
77
* Mocks existence of `schema.json` using mocks fs
88
* Mocks existence of `.graphqlconfig.yml` by mocking return value for loadConfig utility
99
*/
10-
function setupMocks(mockFs, loadConfig, apiId, frontend, target) {
10+
function setupMocks(mockFs, loadConfig, apiId, frontend, target, generatedFileNameOverride, extendMockFs) {
1111
mockFs.restore();
1212
const docsFilePath = {
1313
javascript: 'src/graphql',
1414
android: 'app/src/main/graphql/com/amazonaws/amplify/generated/graphql',
1515
swift: 'graphql',
1616
};
17-
const generatedFileName = getOutputFileName('API', target);
17+
const generatedFileName = generatedFileNameOverride || getOutputFileName('API', target);
1818
const schemaFilePath = 'schema.json';
1919
const nodeModulesPrettier = path.resolve(path.join(__dirname, '../../../../node_modules/prettier'));
2020
const mockedFiles = {
@@ -26,6 +26,7 @@ function setupMocks(mockFs, loadConfig, apiId, frontend, target) {
2626
lazy: true,
2727
}),
2828
[schemaFilePath]: mockFs.load(path.resolve(path.join(__dirname, './blog-introspection-schema.json'))),
29+
...extendMockFs,
2930
};
3031
mockFs(mockedFiles);
3132

packages/amplify-codegen/tests/commands/types-mock-fs.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ describe('command - types (mock fs)', () => {
9090
});
9191
});
9292

93+
it('should generate multiple swift files if generatedFileName is a dir', async () => {
94+
const generatedFileName = 'api';
95+
setupMocks(mockFs, loadConfig, MOCK_API_ID, 'swift', 'swift', generatedFileName, { [generatedFileName]: {} });
96+
97+
await generateStatements(MOCK_CONTEXT, false);
98+
await generateTypes(MOCK_CONTEXT, false);
99+
100+
expect(fs.existsSync(generatedFileName)).toBeTruthy();
101+
expect(fs.readdirSync(generatedFileName)).toEqual([
102+
'Types.graphql.swift',
103+
'mutations.graphql.swift',
104+
'queries.graphql.swift',
105+
'subscriptions.graphql.swift',
106+
]);
107+
});
108+
93109
it('should not generate types when target is javascript', async () => {
94110
const generatedFileName = setupMocks(mockFs, loadConfig, MOCK_API_ID, 'javascript', 'javascript');
95111

0 commit comments

Comments
 (0)