This repository was archived by the owner on Feb 20, 2026. It is now read-only.
test: remove await from code samples#1229
Merged
danieljbruce merged 8 commits intogoogleapis:mainfrom Jan 29, 2024
Merged
Conversation
Remove await from the sample. It is preventing the sample from working.
await causes the code sample not to work so needs to be removed
The OR query code sample should be run in a similar way to the other code samples.
There is no guarantee that the integration test database will have no Buy Milk or Feed cats data in the database to begin with so we will have to make sure to remove all such data so that the test starts with no such data in datastore. This is a requirement for the console output to be correct. Also, since we now use execSync, the standard output cannot be found in console.log.firstCall.args[0] so we have to get it from stdout just like in the other tests.
bhshkh
approved these changes
Jan 26, 2024
cindy-peng
reviewed
Jan 29, 2024
samples/test/queryFilterOr.test.js
Outdated
| it('should get a combination of items from the Datastore', async () => { | ||
| await queryFilterOr(); | ||
| assert.include(console.log.firstCall.args[0], 'Entity'); | ||
| const stdout = execSync(`node ./queryFilterOr.js`); |
Contributor
There was a problem hiding this comment.
Nit: Inline simple local variables: go/unit-testing-practices#example-inlining-simple-local-variables
cindy-peng
approved these changes
Jan 29, 2024
Inline simple local variables as suggested in PR feedback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
General changes:
A customer raised an issue where they ran the OR query sample from https://cloud.google.com/datastore/docs/samples/datastore-query-filter-or and an error was thrown on the line that starts with
await.awaitcan only be used inside an async function so the code sample should not containawaitwhen it is not in an async function. This PR removes await from code samples where await is not used inside an async function.OR query sample changes:
In the OR query sample tests, the assert check no longer works after removing await as console.log.firstCall now equals null. This is because console log output inside an async function is not visible outside of the function if await is not used. Therefore, we should use the execSync function like the code in the import-export.test.js sample test file to get console output from running the sample. This way the
itblock with the assert statement can read the console output and ensure it equals “Entity found: Feed cats\nEntity found: Buy milk\n”.It is also possible that the database currently contains “Buy milk” and “Feed cats” data before the code sample is run which will affect the console output when running the OR query sample. Therefore, a script is added which runs before the OR query sample test is run. This script removes “Buy milk” and “Feed cats” data from the database so that the database starts from a consistent state and the console output is consistent in the assertion check.