-
Notifications
You must be signed in to change notification settings - Fork 825
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(amplify-e2e-tests): add tests for graphql schemas in doc #4092
test(amplify-e2e-tests): add tests for graphql schemas in doc #4092
Conversation
e0600c8
to
e42bad5
Compare
6efb4c3
to
6ecc678
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main goal with tests should be verification (which this change does) and readability of the test code so one knows what is going on (and make it easier to figure out why tests are failing) rather then reducing code duplication.
Could you make the schema, query and mutation inline and use the runQuery, runMutation in the test itself. Also use the proper asserting for tests instead of returning true and expecting tests to return true as it makes it harder to figure out why a test failed
packages/amplify-e2e-tests/src/__tests__/api-directives-1.test.ts
Outdated
Show resolved
Hide resolved
packages/amplify-e2e-tests/src/__tests__/api-directives-1.test.ts
Outdated
Show resolved
Hide resolved
6ecc678
to
6ca3649
Compare
6ca3649
to
f0cf697
Compare
Codecov Report
@@ Coverage Diff @@
## master #4092 +/- ##
==========================================
+ Coverage 60.51% 60.93% +0.42%
==========================================
Files 350 347 -3
Lines 15199 15099 -100
Branches 2878 2860 -18
==========================================
+ Hits 9197 9200 +3
+ Misses 5514 5411 -103
Partials 488 488 Continue to review full report at Codecov.
|
This pull request introduces 3 alerts when merging f0cf6970bb23a3f40943fa7938d2e0e9dc118a74 into 15eac84 - view on LGTM.com new alerts:
|
8a73809
to
0ff23d4
Compare
This pull request introduces 3 alerts when merging 0ff23d47f2f58a07ebfad4d7677e3f38619f2b61 into 15eac84 - view on LGTM.com new alerts:
|
0ff23d4
to
23a9907
Compare
This pull request introduces 3 alerts when merging 23a9907 into 709491f - view on LGTM.com new alerts:
|
23a9907
to
be35572
Compare
In response to the following comments: "The main goal with tests should be verification (which this change does) and readability of the test code so one knows what is going on (and make it easier to figure out why tests are failing) rather then reducing code duplication. Could you make the schema, query and mutation inline and use the runQuery, runMutation in the test itself. Also use the proper asserting for tests instead of returning true and expecting tests to return true as it makes it harder to figure out why a test failed" The schema being tested, the mutations, queries and subscriptions to test the schema, and their expected responses are consolidated into one file for better readability. The test compares the actual mutation, query and subscription responses with the expected results. As the responses can be objects of depth, the test goes to a max depth of 50 (configurable constant) trying to identify mismatches. I can't figure out a simple assertion for that. But if there is a mismatch, the cause of mismatch is clearly printed out, so there shouldn't be any problem identifying the failed test, and the part that failed it. |
ec46f92
to
e180629
Compare
Consolidating them to one file is counter productive. The most important thing with tests is
We have similar tests in our GraphQL E2E tests. In those tests, the schema and mutation is all contained in the same file and makes it easy to understand what is going on. Schema Lines 39 to 77 in 8e0662e
Test Lines 189 to 224 in 8e0662e
I have added an example test in #4092 (comment) Could you explain what you mean by max depth of 50? Jest has the assertion |
} | ||
|
||
const MAX_DEPTH = 50; | ||
function runCompare(queue: { received: any; expected: any; depth: number }[]): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use .toMatchObject(object)
instead of rolling our own solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some technical difficulties.
In the test, the actual received mutation, query and subscription results are not directly compared with the expected results specified in the test case file (e.g. using the jest .toMatchObject(object) method).
- id, createdAt and updatedAt fields are generated (if not specified in the mutation), their values are not determined when the test starts to run. Those fields are generally given a value “” in the expected result specification, and the test only checks that they are defined in the actual received result.
- If error is expected, the test only checks for the error type, but the actual error response contains a lot of fields.
- The actual response can contain the "__typename" field, even if the schema does not contain union of interface, and even if the mutation or query does not specify it. The expected result in the test case files do not include this extra field.
To compare the expected and the actual result object, the test uses a BFS method to find mismatched field, if no mismatch is found after MAX_DEPTH (set at 50 in the test), the test passes.
packages/amplify-e2e-tests/src/api-directives/tests/searchable-usage.ts
Outdated
Show resolved
Hide resolved
packages/amplify-graphql-types-generator/test/__snapshots__/loading.ts.snap
Outdated
Show resolved
Hide resolved
packages/graphql-auth-transformer/src/__tests__/__snapshots__/OperationsArgument.test.ts.snap
Outdated
Show resolved
Hide resolved
packages/graphql-key-transformer/src/__tests__/__snapshots__/KeyTransformer.test.ts.snap
Outdated
Show resolved
Hide resolved
content | ||
} | ||
}`; | ||
export const expected_result_mutation1 = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please dont use the variable naming magic. Like i suggested in an earlier comment, move this inside a test and then wrap it inside an object, so both mutation and results are wrapped in the same object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the test layout that we discussed in the meeting.
1b522df
to
da29899
Compare
Add tests for graphql schemas in the document Amplify CLI/API(GraphQL)/Directives
b491c6a
to
af678b1
Compare
This pull request introduces 1 alert when merging 1cbee0c into 827c7b8 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 8b0521f into 0a6a7ea - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging 12f493d into 0a6a7ea - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging e7a4524 into 454fdc0 - view on LGTM.com new alerts:
|
…plify#4092) * test(amplify-e2e-tests): add e2e test for schema in doc Add tests for graphql schemas in the document Amplify CLI/API(GraphQL)/Directives * minor fix * fix searchable test * split long tests * minor fix * minor fix Co-authored-by: UnleashedMind <root@186590ce137f.ant.amazon.com> Co-authored-by: UnleashedMind <zhoweimi@186590ce137f.ant.amazon.com>
…plify#4092) * test(amplify-e2e-tests): add e2e test for schema in doc Add tests for graphql schemas in the document Amplify CLI/API(GraphQL)/Directives * minor fix * fix searchable test * split long tests * minor fix * minor fix Co-authored-by: UnleashedMind <root@186590ce137f.ant.amazon.com> Co-authored-by: UnleashedMind <zhoweimi@186590ce137f.ant.amazon.com>
…plify#4092) * test(amplify-e2e-tests): add e2e test for schema in doc Add tests for graphql schemas in the document Amplify CLI/API(GraphQL)/Directives * minor fix * fix searchable test * split long tests * minor fix * minor fix Co-authored-by: UnleashedMind <root@186590ce137f.ant.amazon.com> Co-authored-by: UnleashedMind <zhoweimi@186590ce137f.ant.amazon.com>
This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Add tests for graphql schemas in the document Amplify CLI/API(GraphQL)/Directives
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.