Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add mock fs multiple swift file test #721

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/amplify-codegen/tests/commands/mock-fs-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const { getOutputFileName } = require('@aws-amplify/graphql-types-generator');
* Mocks existence of `schema.json` using mocks fs
* Mocks existence of `.graphqlconfig.yml` by mocking return value for loadConfig utility
*/
function setupMocks(mockFs, loadConfig, apiId, frontend, target) {
function setupMocks(mockFs, loadConfig, apiId, frontend, target, generatedFileNameOverride, extendMockFs) {
mockFs.restore();
const docsFilePath = {
javascript: 'src/graphql',
android: 'app/src/main/graphql/com/amazonaws/amplify/generated/graphql',
swift: 'graphql',
};
const generatedFileName = getOutputFileName('API', target);
const generatedFileName = generatedFileNameOverride || getOutputFileName('API', target);
const schemaFilePath = 'schema.json';
const nodeModulesPrettier = path.resolve(path.join(__dirname, '../../../../node_modules/prettier'));
const mockedFiles = {
Expand All @@ -26,6 +26,7 @@ function setupMocks(mockFs, loadConfig, apiId, frontend, target) {
lazy: true,
}),
[schemaFilePath]: mockFs.load(path.resolve(path.join(__dirname, './blog-introspection-schema.json'))),
...extendMockFs,
};
mockFs(mockedFiles);

Expand Down
16 changes: 16 additions & 0 deletions packages/amplify-codegen/tests/commands/types-mock-fs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ describe('command - types (mock fs)', () => {
});
});

it('should generate multiple swift files if generatedFileName is a dir', async () => {
const generatedFileName = 'api';
setupMocks(mockFs, loadConfig, MOCK_API_ID, 'swift', 'swift', generatedFileName, { [generatedFileName]: {} });

await generateStatements(MOCK_CONTEXT, false);
await generateTypes(MOCK_CONTEXT, false);

expect(fs.existsSync(generatedFileName)).toBeTruthy();
expect(fs.readdirSync(generatedFileName)).toEqual([
'Types.graphql.swift',
'mutations.graphql.swift',
'queries.graphql.swift',
'subscriptions.graphql.swift',
]);
});

it('should not generate types when target is javascript', async () => {
const generatedFileName = setupMocks(mockFs, loadConfig, MOCK_API_ID, 'javascript', 'javascript');

Expand Down