ZaDarkSide / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

Need ability to analyse code coverage for files from 'serve' section #309

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When using some JavaScript library that supports dependency loading (like 
curl.js, RequireJS, Dojo, YUI etc.)
some files aren't declared in 'load' section of test configuration file. 
Instead they are declared in 'serve' section of that file
and loaded dynamically by JavaScript code. But due to file.isServeOnly() 
condition check in  
com.google.jstestdriver.coverage.CoverageInstrumentingProcessor.process()
these files aren't instrumented by coverage plugin. There should be an option 
to analyse code coverage for such files.

I suggest a patch for coverage plugin (see attachment) to solve this problem. 
It checks plugin arguments list to see if there are arguments that start with 
'includesRegex:' of 'excludesRegex:'. From that arguments it takes regular 
expressions. When it comes to processing files in 
com.google.jstestdriver.coverage.CoverageInstrumentingProcessor.process() 
patched plugin matches filePath against lists of regexes. If it is found in 
first list ('includesRegex:')
then file is instrumented even if it has serveOnly flag set. If it is found in 
second list ('excludesRegex:') then file is not instrumented. 

All this stuff relates to version 1.3.3d of jsTestDriver.

Original issue reported on code.google.com by Paul.Ly...@gmail.com on 9 Dec 2011 at 3:32

Attachments:

GoogleCodeExporter commented 8 years ago
Does this patch work for 1.3.4.b?

Original comment by bret.lit...@gmail.com on 10 May 2012 at 10:51

GoogleCodeExporter commented 8 years ago
It does work in 1.3.4.b, here is a jar built from the previously posted patch. 
(If you don't want to download and built it yourself)

Original comment by bret.lit...@gmail.com on 24 May 2012 at 9:23

Attachments:

GoogleCodeExporter commented 8 years ago
Does anyone have an example of our they are using this patch? I need this 
solution.

Original comment by jason.do...@gmail.com on 10 Sep 2012 at 5:17

GoogleCodeExporter commented 8 years ago
It might be a bit more involved than what you are looking for, but I have a 
github repo that uses this for testing requirejs modules in jsTestDriver and 
PhantomJS.

https://github.com/blittle/jstesting

Original comment by bret.lit...@gmail.com on 10 Sep 2012 at 5:31

GoogleCodeExporter commented 8 years ago
Thanks for the link. I was able to get it working with RequireJS and our large 
Backbone app.

Original comment by jason.do...@gmail.com on 11 Sep 2012 at 3:27

GoogleCodeExporter commented 8 years ago
Glad to hear it helped, I'll try to keep that updated with various gotchas in 
getting this all working. Sometimes jsTestDriver will die on things and it is 
hard to debug as to what happened. More often than not though, it seems like it 
is a requirejs module loading issue that stops the rest of the process.

Original comment by bret.lit...@gmail.com on 11 Sep 2012 at 3:38

GoogleCodeExporter commented 8 years ago
I was happily surprised when I got it to work because I too have encountered 
many issues between JsTestDriver and RequireJS. Our app is not a small or 
simple one, but JsTestDriver tests and analyzes it in 2-3 seconds. Loading our 
source files in the "serve" section was the key, as loading them in the "load" 
section required them to be named modules, and there's no way we're going to 
maintain something like that. I only wish that browser launching and 
auto-capture were a little more robust (i.e. usable).

In your repo do you use a patched version of JsTestDriver/Coverage?

Original comment by jason.do...@gmail.com on 12 Sep 2012 at 3:21

GoogleCodeExporter commented 8 years ago
Yes, the repo automatically includes the patched version that Paul posted. If 
you find some better ways of doing things, go ahead and fork that repo and add 
to it. I appreciate your feedback and look forward to more mature tools and 
frameworks in the future.

Original comment by bret.lit...@gmail.com on 12 Sep 2012 at 8:32

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
For anyone interested, here's an example that uses this patch:

In the conf file:

plugin:
- name: "coverage"
  jar: "../plugins/coverage-1.3.5.serve-patch.jar"  
  module: "com.google.jstestdriver.coverage.CoverageModule"  
  args: "includesRegex: /js/app/.*\\.js$, excludesRegex: /js/lib/.*\\.js$"

In this example, we include for coverage all the js files inside js/app, and 
exclude all the js files inside js/lib.
(Note that the regex tests over the full file path)

I'm attaching the latest patched jar (1.3.5 at the time of writing) of the 
coverage plugin in case someone needs it.

If I can help, feel free to email me. 

Cheers, from La Paz, Bolivia

Original comment by edgarinv...@gmail.com on 1 Nov 2012 at 8:37

Attachments:

GoogleCodeExporter commented 8 years ago
Really helpful, I have 2 different projects, 1 is not using requirejs and 
working pretty well without this patch, producing code coverage report from a 
dev environment to continuous build environment. A second project using 
requirejs and AMDLoaderPlugin, we use the serve section, I got it working just 
fine on macOS production code coverage report using phantomjs as browser agent.
What I'm struggling with is that when I run on linux, the logs show that the 
instrumentation doesn't kick in and no coverage report is produced 'No lines of 
coverage found.' toward the end.
Any idea of what could cause the discrepancy?
I'm using phantom 1.7.0 in both environment, and I would assume macos is fairly 
close to our linux box.

Original comment by sbard...@gmail.com on 7 Mar 2013 at 7:05

GoogleCodeExporter commented 8 years ago
Forget about my last comment, I found out that the integration server was using 
a root path matching the exclusion pattern.
Thanks for this wonderful patch.

Original comment by sbard...@gmail.com on 7 Mar 2013 at 8:38

GoogleCodeExporter commented 8 years ago
Could you please share source for this coverage plugin? I am trying to 
integrate coverage plugin with phantomjs and I was not able to get it working. 

Original comment by bestwayt...@gmail.com on 2 Nov 2013 at 3:36