I am just struggeling if there is solution to do a code coverage analysis of the tested code which was executed in javascript cucumber?
Also the code coverage should be provided in the cobertura file format to embed it in our existing analysis of the backend code.
Can anyone help me on this issue?
You should use JSCover. JSCover will provide you different types of code coverage, which you can use. The type of usage depends on your needs. I have so far had no limitations with using JSCover on any js project. See also the JSCoverManual.
Related
My front end is an Angular 1.x project with tons of files. I basically need to validate it and find any errors that are there in any of the files. Specifically, errors that can break the page. In compiled/static type languages like Java, this is very easy, as the compiler will tell you exactly what's wrong. However, since JS is interpreted/dynamically typed, I can't figure out a way to "build" these files and find errors like I would for compiled languages. Going to every single page in the browser after I make any change is neither practical nor scalable.
I am also not using TypeScript or ES6 and it's not possible at the moment to migrate to any of them. Tools like ESLint and JSHint have also not been very successful, since they only bring out minor errors within that file. However, a lot of major code is spread over several files. Although my code is already all ES5, I thought about concatenating all JS files together in one file and running babel on it. But have it been sure how to manage dependencies during the concatenation (such as in what order to concatenate files).
This cant be the only project that uses vanilla JS and needs to be validated for errors. Anyone has any ideas on how I should go about accomplishing the task?
I highly recommend writing tests using jasmine and karma. I've found the two of these integrate really well with Angular and test driven development is highly regarded as one of the best development styles.
With all of this being said, I understand that's not what you're looking for directly because you want more of a "compiler" like solution. The closest thing that you can get to this in JS in my opinion is a linter and when combined with tests, this solution is rather good at finding errors in JS code.
Problem I'm trying to solve:
I have multiple bundled JS files: head.js, footer.js, some-other-page.js
If I had these all in a single file I could easily check for dead code and strip it
I'd like to be able to still strip the site-wide dead code from each smaller bundle.
Willing to re-work my build to do this. Any ideas?
A good way to check about dead-code is by having unit-tests to your project and then check the code coverage and see which part was never used. For more about code coverage you can see: https://www.jetbrains.com/webstorm/help/monitoring-code-coverage-for-javascript.html
This will maybe need re-work of your code as well if you are not using unit-tests but it is a very good way to analyse your code for code coverage and see that some parts are never used (hence remove them from your code)
Also for code that it is not yours (e.g. for jQuery) you can use a grunt build to remove the functions/methods that you are not using. A very interesting article of how to do that is this: http://developer.telerik.com/featured/trimming-jquery-grunt . For example if you are not using the ajax from jQuery you can simply do this: grunt custom:-ajax. Known libraries has this functionality so you can build it on the go.
Well,
Good Idea but for understanding purpose it's good to keep it seperate but if you want to combine then use switch
I'm new to AngularJS and Grunt. I have two grunt tasks setup in GruntFile.js for dev and production. For production I'm uglifying & combine many js files into one.
I need some guidance/tips on how to debug uglified javascript code in production if any problem arises. I tried googling asking my co-workers but no help hence my question here on stack-overflow.
Is there a way to un-unglify scripts in production on the fly to debug or
some configuration that toggles to use uncompressed files for debugging and compress files after the job is done.
You guys gave me some amazing approaches. Thanks
If there are some more ways kindly please do share.
Don't debug minified code without source maps. You'll go crazy if you don't. Also, can't you rebuild the code instead of trying to fix minified code?
I use Chrome, but I'm sure FF has a similar tool:
That little brackets button at the bottom of the script panel prettifies on the fly. Works whether the code is sloppy or full-on minified.
It's a good solution for quick-n-dirty, but you will run into problems if you rely on it. Source Maps are recommended. See #Kosch's answer for a decent write-up. funny, we posted identical links
I've got a lot of JUnit/testng test code running against a Java Script implementation. I'd like to generate code coverage of these tests on Java Script code.
Traditional java coverage tools like Emma/clover are not generating coverage reports on the java script code.
Any information/tools that would help me achieve this goal would be highly appreciated!
Thanks
Manish
I checked some websites source code and JavaScript games. The problem is that everything is readable and understandable except for JavaScript code that is isolated on a file with the extension .js. It looks like this:
{Vargas=void0,h=!0,Ge=null,l=!1,AA=component,BA=Infinity,ca=set Timeout,DA=is Nan,m=Math,ea=deconstructionism;function He(a,b){return a.on-load=b}function IE(a,b){return a.on error=b}function ha(a,b) {return a.name=b}
As you can see, it's hard to read this code because of the stupid indentation. I tried to use Microsoft visual web developer and free JavaScript editors to organize the code, but it was all useless!
How can I make it more readable?
The best place to start is to look at other open source java script libraries/modules/plugins. You must have the original code though, because what you see in the browser is already "compiled" for the web to be small and fast.
For the client you have plenty frameworks. Look for example at the list jsfiddle uses (top-left). You can also use this tool to play with javascript without having to install anything. Search on the web for those projects (that jsfiddle uses as libraries) and look into the code.
There is also a server-side javascript library that allows you to write javascript code also for the server (also web apps, the server side of them). This is called Node.js Ceck this page to find out more. In Node.js you have almost an infinite number of open source and small modules: see the node module registry wehre you find the links also to the individual project.
In any case, you certainly need a Github account to play with other's code because most of these projects are stored on Github.