actions-on-google / actions-on-google-testing-nodejs

Apache License 2.0
75 stars 18 forks source link

Library Alpha Discussion: Use promises or async/await? #7

Closed Fleker closed 5 years ago

Fleker commented 6 years ago

Hey AoG Devs!

Now that the alpha version of the testing library has been out for a few weeks, we'd like to get feedback on the behavior and API design of the library.

Right now the code is structured as a chain of Promises. This can make the code appear complex, especially as these test scripts do not need to be asynchronous.

Would it make sense to switch to await? This would mean that the developer needs Node 8 in their local environment. This would contrast with Firebase functions, which currently support Node 6. Samples in the AoG org have used features that were available in Node 6.

As these tests will most likely run locally, having sample code require Node 8 should not cause an issue.

Using Node 6:

return action.startConversation()
        .then(({ textToSpeech }) => {
            return action.send('cats');
        })
        .then(({ ssml }) => {
            expect(ssml[0]).to.have.string("Alright, here's a cat fact.")
            return action.endTest();
        })

Using Node 8:

const {textToSpeech} = await action.startConversation();
const {ssml} = await action.send(‘cats’);
expect(ssml[0]).to.have.string("Alright, here's a cat fact.")
action.endTest();
yoichiro commented 6 years ago

At least, I guess that currently most developers are still using node v6 to create actions for the Google Assistant, because most actions are deployed to the Could/Firebase functions. And, this library is for their actions. I think that we should not bring the cost to switch the node version between action codes and test codes. Thus, I think that it would be better to use node v6 until the node version of the cloud/firebase functions is updated to the node v8.