4 ms·
> The analyzer will parse your source code into an AST. It will then evaluate the AST dynamically, trying to reach every possible execution branch. If a global
by acobster 9y ago
> The analyzer will parse your source code into an AST. It will then evaluate the AST dynamically, trying to reach every possible execution branch. If a global entry point is specified, every exposed function will be evaluated, including functions that are returned by other functions. [0]
For anything but the smallest of libraries, testing every path through the code would be pretty burdensome to do in the browser on every change. Of course you can do it with the right test plan, but it doesn't take long for a codebase to get large enough to make it difficult to reason about the entire AST. At the very least, it seems like this is a good tool for exposing the blind spots in your testing. :)
[0] https://javascript.studio/features/ https://javascript.studio/features/
- jbob2000 9y agoAh cool, I didn't notice that. And I must admit, I am not familiar with how an AST works. My application makes a lot of HTTP requests and is full of async operations. How would it handle this? It wouldn't be able to run most of the code because all of the data is missing...
- batmansmk 9y agoIt does the job an expert human can do by reading the code without executing it. function willFail() { let x = null console.log(x.method()) } You can read that this function will throw an exception all the time. But you may never execute this function in your test cases, so you won't see this problem in development but only too late, when a user hits the problem in prod. It is called a static analysis and is 99.9% of the time faster to perform than executing every possible cases of your code. It doesn't catch exactly the same kind of issues either; so both are complementary.
- pseudosavant 9y agoUnfortunately it also thinks every function that uses a native browser variable/object (e.g. `screen` in my case) means it will fail because I never defined `screen` in my code. Other analysis tools like JSHint allow you to specify certain globals ($) or that you are in a browser environment with special annotations to handle this situation. I couldn't find anything in their documentation like that.
- mantoni 9y agoThe documentation has a list of supported browser features: https://javascript.studio/docs/browser-features https://javascript.studio/docs/browser-features Ideally all the browser APIs should be supported by the tool without the need to manually declare any globals.