Resuscitating the Apps Script execution transcript – JavaScript Proxy and Reflect to the rescue

113 views
Skip to first unread message

Bruce Mcpherson

unread,
Jul 30, 2021, 12:06:48 PM7/30/21
to Google Apps Script Community
If you’ve been using Apps Script for a while, since back when it was running on the Rhino JavaScript emulator; see (What JavaScript engine is Apps Script running on?), you’ll remember the Execution Transcript. This was a really useful log of every call made to built-in Apps Script services, along with the arguments passed and the result. It was a great tool for debugging.
 
With V8, that disappeared, so I wondered if there might be a way to intercept calls to Apps Script services to bring back what we lost with the disappearance of the Execution Transcript. And, of course we can! With a minimum of coding, we can fiddle around with any Gas Service call. This article will show you how.

CBMServices Web

unread,
Jul 30, 2021, 12:19:04 PM7/30/21
to google-apps-sc...@googlegroups.com
Thanks Bruce. You have been a great source of help with Apps Script. Keep it up.

One thing I have used in other software environments which I can't find in Apps Script is a Code Coverage tool. Something that would trace the execution of the software to determine what percentage of code has been covered in testing. Are you aware of any such for Apps Script?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/9f2d03b3-42d3-4cf7-8361-38c7847b4fa5n%40googlegroups.com.

Bruce Mcpherson

unread,
Jul 30, 2021, 12:34:50 PM7/30/21
to google-apps-sc...@googlegroups.com, Adam Morris
Hi

No - I'm not aware of anything like that for Apps Script. V8 has some built in coverage capability but that'd be browser side. If I understand how these things work correctly, counters are inserted inside code blocks to see how many times certain paths are followed, so I don't know to what extent any of that could be applied to Apps Script v8. I guess there might be a workflow that instrumented your source and imported that built version into apps script for testing coverage.

It's an interesting question though and worth digging into. 

@Adam Morris is usually pretty well informed on testing tools - perhaps he has some insight

bruce



Adam Morris

unread,
Jul 30, 2021, 9:01:34 PM7/30/21
to Google Apps Script Community
Hi everyone,

Thanks Bruce for the mention. 

I made a unit testing framework, which funny enough uses its own methods to test itself. 

It doesn’t have code coverage; I’ve never needed it either so haven’t built anything that could do it. 

If you find an npm module written with es modules then perhaps you’ll find this repo useful:

That will let you bring in npm modules into appscripts projects by bundling it up. Es modules work best as it allows for tree shaking which cuts down on code size. But any npm module… assuming JavaScript is compatible with appsscripts version of v8. Even then, we could use Babel to compile it down.

There’s also another implementation with esbuild

CBMServices Web

unread,
Jul 30, 2021, 9:58:49 PM7/30/21
to google-apps-sc...@googlegroups.com
Thanks Adam. I will check out the tools. But call me old school if you want, only code coverage gives me the assurance that the code has been fully tested.

I have been trying to test as best as I can and ensure all the cases are covered, but tough to say if I managed to get all of the code written tested or not with some tool to validate this.

Adam Morris

unread,
Jul 31, 2021, 12:08:40 AM7/31/21
to google-apps-sc...@googlegroups.com
Hmmm, it's certainly an interesting problem to solve.

I think this is the sort of thing that would need extensive development to get working. In case anyone is interested this is what (I think) would need to happen:

1) Download the scripts via the appsscripts API
2) Parse the files into AST (syntax tree … hopefully an npm module would be around)
3) Instrument the sourcecode to insert statement counts
4) Use the appsscripts API to execute this instrumented code with the testing suite, wrapped by coverage reporter
5) The response from above api request would then be the coverage info
6) Oh, and do that under 6 minutes (instrumentation slows everything way down)

TBH I think the above is just too much for the platform.

Adam



You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/w-YZYs6K3YI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAFX%2Bz3V2YSQQGbBWvH-JxAS0eCiuUnaeKExsVhg_8u%3DnsSAMAQ%40mail.gmail.com.

cbmserv...@gmail.com

unread,
Jul 31, 2021, 12:19:18 AM7/31/21
to google-apps-sc...@googlegroups.com

Yes, you may be right. The instrumentation could easily double if not triple the amount of time the code takes to run normally.

 

Google is working on improving the editor and adding better debugging capabilities. Perhaps we should make a feature request to them to add this as a new capability within their editor. This way we don’t need to do any external instrumentation, but the platform itself will provide this capability on request instead.

 

Sorry to hear there is no existing code coverage tool currently in place. I was hoping there was something that can be used.

Adam Morris

unread,
Jul 31, 2021, 1:06:21 AM7/31/21
to google-apps-sc...@googlegroups.com
V8 itself does have coverage capability built in. I read about it … somewhere. So could be exposed. Good idea to suggest. 

I wonder what they think of some of us really maxing on the platform… 


--
Reply all
Reply to author
Forward
0 new messages