Code Monkey home page Code Monkey logo

jscover's People

Contributors

ajaxsys avatar jakecobb avatar jbuchanan-sfdc avatar mas3 avatar robinjmurphy avatar rusashi avatar stephdz avatar sylvestre avatar tedda42 avatar tntim96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jscover's Issues

Result showing instrumented code in the report

In the code coverage report, I am seeing code used to calculate code coverage as part of the source file and it's impacting real code coverage.

Below are the steps I performed:

  • Instrumented my JavaScript code using "file system" approach.
  • Ran qunit test on the target-directory.
  • Updated one of my project files to output code coverage data in JSON format. (based on implementation in jscoverage.js)
  • Converted the data to Cobertura format
  • Displayed results on Jenkins,
  • When navigating to view the coverage, I see the code that's used to capture code coverage. I was hoping to see just the original .js file.

Please advise.

JSCover-all.jar missing

perhaps I'm missing something but example-server.sh looks for a file

target/dist/JSCover-all.jar

but it doesn't exist. I get the following error:

Unable to access jarfile target/dist/JSCover-all.jar

what am I missing? or is this a bug?

Build failed

I cloned the repo, ran ant, and got the following:

$ ant
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Buildfile: /Users/dalvarez/Code/JSCover/build.xml

clean:

dirsetup:
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/dist
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports/test
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports/spec
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports/checkstyle
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports/coverage/int
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports/coverage/all
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/classes/main
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/classes/instrumented
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/classes/test-unit
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/classes/test-integration
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/classes/test-acceptance

compile:
    [javac] Compiling 27 source files to /Users/dalvarez/Code/JSCover/target/classes/main
    [javac] Note: /Users/dalvarez/Code/JSCover/src/main/java/jscover/server/NanoHTTPD.java uses or overrides a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: /Users/dalvarez/Code/JSCover/src/main/java/jscover/server/NanoHTTPD.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
     [copy] Copying 13 files to /Users/dalvarez/Code/JSCover/target/classes/main

compile-tests:
    [javac] Compiling 25 source files to /Users/dalvarez/Code/JSCover/target/classes/test-unit
     [copy] Copying 6 files to /Users/dalvarez/Code/JSCover/target/classes/test-unit

compile-integration-tests:
    [javac] Compiling 4 source files to /Users/dalvarez/Code/JSCover/target/classes/test-integration
     [copy] Copying 136 files to /Users/dalvarez/Code/JSCover/target/classes/test-integration

cobertura-setup:
[cobertura-instrument] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 25 files to /Users/dalvarez/Code/JSCover/target/classes/instrumented
[cobertura-instrument] Cobertura: Saved information on 25 classes.
[cobertura-instrument] Instrument time: 225ms
     [copy] Copying 149 files to /Users/dalvarez/Code/JSCover/target/classes/instrumented

run-tests:
   [delete] Deleting directory /Users/dalvarez/Code/JSCover/target/reports/test
    [mkdir] Created dir: /Users/dalvarez/Code/JSCover/target/reports/test
    [junit] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
    [junit] Testsuite: jscover.ConfigurationTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.058 sec
    [junit] 
    [junit] Testsuite: jscover.MainInstanceTest
    [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.274 sec
    [junit] 
    [junit] ------------- Standard Output ---------------
    [junit] Usage: java -jar jscover.jar -ws [OPTION]...
    [junit] Run a server for instrumenting JavaScript with code coverage information.
    [junit] 
    [junit] Options:
    [junit]       --document-root=DIR   serve content from DIR (default: current directory)
    [junit]       --no-instrument=URL   do not instrument URL
    [junit]       --report-dir=DIR      store report to DIR (default: current directory)
    [junit]       --port=PORT           use PORT for TCP port (default: 8080)
    [junit]       --proxy               run as a proxy
    [junit]       --js-version=VERSION  JavaScript version 1.0, 1.2, ..., 1.8 (default: 1.3)
    [junit]   -h, --help                display this help and exit
    [junit] 
    [junit] Usage: java -jar jscover.jar -ws [OPTION]...
    [junit] Run a server for instrumenting JavaScript with code coverage information.
    [junit] 
    [junit] Options:
    [junit]       --document-root=DIR   serve content from DIR (default: current directory)
    [junit]       --no-instrument=URL   do not instrument URL
    [junit]       --report-dir=DIR      store report to DIR (default: current directory)
    [junit]       --port=PORT           use PORT for TCP port (default: 8080)
    [junit]       --proxy               run as a proxy
    [junit]       --js-version=VERSION  JavaScript version 1.0, 1.2, ..., 1.8 (default: 1.3)
    [junit]   -h, --help                display this help and exit
    [junit] 
    [junit] ------------- ---------------- ---------------
    [junit] Testsuite: jscover.MainParsingTest
    [junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.019 sec
    [junit] 
    [junit] Testsuite: jscover.filesystem.ConfigurationForFSTest
    [junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.011 sec
    [junit] 
    [junit] ------------- Standard Error -----------------
    [junit] Source directory 'unknown' is invalid
    [junit] Source directory 'build.xml' is invalid
    [junit] ------------- ---------------- ---------------
    [junit] Testsuite: jscover.format.PlainFormatterTest
    [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.009 sec
    [junit] 
    [junit] Testsuite: jscover.instrument.InstrumenterServiceTest
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.04 sec
    [junit] 
    [junit] Testsuite: jscover.instrument.InstrumenterTest
    [junit] Tests run: 9, Failures: 0, Errors: 0, Time elapsed: 0.016 sec
    [junit] 
    [junit] Testsuite: jscover.instrument.LineCountNodeVisitorTest
    [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.008 sec
    [junit] 
    [junit] Testsuite: jscover.instrument.StatementBuilderTest
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.005 sec
    [junit] 
    [junit] Testsuite: jscover.json.JSONDataMergerTest
    [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.015 sec
    [junit] 
    [junit] Testsuite: jscover.json.JSONDataSaverTest
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.015 sec
    [junit] 
    [junit] Testsuite: jscover.server.ConfigurationForServerTest
    [junit] Tests run: 11, Failures: 0, Errors: 0, Time elapsed: 0.012 sec
    [junit] 
    [junit] Testsuite: jscover.server.HttpRequestTest
    [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.009 sec
    [junit] 
    [junit] Testsuite: jscover.server.InstrumentingRequestHandlerTest
    [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.047 sec
    [junit] 
    [junit] Testsuite: jscover.server.WebServerTest
    [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.022 sec
    [junit] 
    [junit] Testsuite: jscover.util.FileScannerTest
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.006 sec
    [junit] 
    [junit] Testsuite: jscover.util.IoServiceTest
    [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.013 sec
    [junit] 
    [junit] Testsuite: jscover.util.IoUtilsTest
    [junit] Tests run: 24, Failures: 0, Errors: 0, Time elapsed: 0.106 sec
    [junit] 
    [junit] ------------- Standard Error -----------------
    [junit] java.io.IOException: Ouch!
    [junit]     at jscover.util.IoUtils.closeQuietly(IoUtils.java:354)
    [junit]     at jscover.util.IoUtilsTest.shouldCloseStreamQuietly(IoUtilsTest.java:370)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:597)
    [junit]     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    [junit]     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    [junit]     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    [junit]     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    [junit]     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    [junit]     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    [junit]     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    [junit]     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    [junit]     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    [junit]     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    [junit]     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    [junit]     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    [junit]     at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    [junit]     at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
    [junit]     at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    [junit]     at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:879)
    [junit] ------------- ---------------- ---------------
    [junit] Testsuite: jscover.instrument.InMemoryCoverageTest
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.047 sec
    [junit] 
    [junit] Testsuite: jscover.instrument.InstrumentAndHighlightRegressionTest
    [junit] Tests run: 45, Failures: 0, Errors: 0, Time elapsed: 0.125 sec
    [junit] 
    [junit] ------------- Standard Output ---------------
    [junit] Test javascript-function-chain.js failed
    [junit] Test javascript-getter-setter.js errored
    [junit] Test javascript-iso-8859-1.js failed
    [junit] ------------- ---------------- ---------------
    [junit] Testsuite: jscover.instrument.InstrumenterIntegrationTest
    [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.005 sec
    [junit] 
    [junit] Testsuite: jscover.instrument.ParseTreeInstrumenterIntegrationTest
    [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.028 sec
    [junit] 
    [junit] Flushing results...
    [junit] Flushing results done
    [junit] Cobertura: Loaded information on 25 classes.
    [junit] Cobertura: Saved information on 25 classes.
Trying to override old definition of task cobertura-instrument
Trying to override old definition of task cobertura-merge
Trying to override old definition of task cobertura-check
Trying to override old definition of task cobertura-report

report-if-failed:

coverage-report:
[cobertura-report] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[cobertura-report] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 25 classes.
[cobertura-report] Report time: 465ms

coverage-check:
[cobertura-check] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
[cobertura-check] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-check] Cobertura: Loaded information on 25 classes.
[cobertura-check] All checks passed.

junit:

compile-acceptance-tests:
    [javac] Compiling 3 source files to /Users/dalvarez/Code/JSCover/target/classes/test-acceptance

BUILD FAILED
/Users/dalvarez/Code/JSCover/build.xml:167: /Users/dalvarez/Code/htmlunit-2.10/lib does not exist.

Total time: 6 seconds

In Proxy mode, is there a way to save files to original-src/ on store?

Sorry, this'll be my last issue I swear...

I've searched through the manual for this but couldn't find anything for this particular scenario. I'm running in proxy mode, and the coverage report is working beautifully, but when I hit store and try to access the report using a simple web server, I can only view the summary, because there's no JS in the original-src dir of the report. Is there a way to have the proxy server save the JS files it proxied when storing the report?

Exception in thread "main" org.mozilla.javascript.EvaluatorException: illegal character

When I jscover my project, it throw this error, my js file code including Chinese charset.

Exception in thread "main" org.mozilla.javascript.EvaluatorException: illegal character
    at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)
    at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:64)
    at org.mozilla.javascript.Parser.addError(Parser.java:188)
    at org.mozilla.javascript.Parser.addError(Parser.java:166)
    at org.mozilla.javascript.Parser.addError(Parser.java:162)
    at org.mozilla.javascript.TokenStream.getToken(TokenStream.java:831)
    at org.mozilla.javascript.Parser.peekToken(Parser.java:296)
    at org.mozilla.javascript.Parser.parse(Parser.java:524)
    at org.mozilla.javascript.Parser.parse(Parser.java:502)
    at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.java:409)
    at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceProcessor.java:393)
    at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java:385)
    at jscover.instrument.SourceProcessor.processSourceForFileSystem(SourceProcessor.java:380)
    at jscover.instrument.InstrumenterService.instrumentJSForFileSystem(InstrumenterService.java:376)
    at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:386)
    at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
    at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
    at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
    at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
    at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
    at jscover.filesystem.FileSystemInstrumenter.run(FileSystemInstrumenter.java:367)
    at jscover.Main.runFileSystem(Main.java:445)
    at jscover.Main.runMain(Main.java:417)
    at jscover.Main.main(Main.java:406)

Strange constraints: Destination directory 'webapp-instrumented' must be in the source directory

If I have webapp and webapp-instrumented as sibling folder, JSCover complains. I don't see any justification for this. Even more, if webapp-instrumented is a child of webapp, then JSCover recursives for ever.

C:\JSCover-0.0.11>java -jar C:\JSCover-0.0.11\target\dist\JSCover-all.jar -fs webapp webapp-instrumented
Destination directory 'webapp-instrumented' must be in the source directory
Usage: java -jar jscover.jar -fs [OPTION]... SOURCE-DIRECTORY DESTINATION-DIRECTORY
Instrument JavaScript with code coverage information.

Options:
--js-version=VERSION use the specified JavaScript version
--no-instrument=PATH copy but do not instrument PATH
--exclude=PATH don't copy from source/PATH
-h, --help display this help and exit

JSCover breaks loop labels

Javascript in :

looking:
for(var nm in o){

JSCover out :

looking:
{
   _$jscoverage['/web/dojo/_firebug/firebug.js'].lineData[1099]++;
   _$jscoverage['/web/dojo/_firebug/firebug.js'].lineData[1100]++;
   for (var nm in o) {

In JS you aren't allowed have statements between a label and its loop. I understand that the simplest fix would be to just move the label on to the loop line but it's a legacy project and I don't have the luxury of editing this particular dependency. JSCover looks great so far, I'm just inches away from getting it fully functional...

Show incorrect coverage of code inside $.map() and $.each()

Tried JSCover and must say it's so easy and nice to use, but I stumpled upon an error with the jQuery functions jQuery.map() and jQuery.each. It will show how often the these functions are called but will completely ignore the callback part, which is set to 0.
But the callback part is executed multiple times not the .map/.each.

E.g.:

$.map( [0,1,2], function(n){
    return n + 4;
});

JSCover will show that line 1 is called 3 times and line 2 is never called.

Would like a single JS method that return HTML or save HTML report without having to deal with frame/window when using inversed mode

Would a single JS method that return HTML or save HTML report without having to deal with frame/window when using inversed mode.

So ideally, if I include the jscover javascript library in my app (no point of having an html file), I would like to be able to call from anywhere, like Selenium something like "var myHTMLReport = jscoverage.getHTMLReport()" or "jscoverage.saveHTMLReport("myReport.html")

The button game or iframe mechanism is more work.

I just care about automated build.

Stop Server and write report in Server Mode

Hi there,

I am using a command line script to start JSCover headless in Server Mode, and then, via CasperJs run my tests.

Currently I am stopping the server by pointing my headless browser to 0.0.0.0:8080/stop

But how do I write out the report before I stop the server? I missing something.

Exit status is always zero

When JSCover does filesystem instrumentation, the exit code is always zero, regardless of whether the instrumentation was successful or not. It should be non-zero in case of error.

UTF-8 BOM results in exception

I have a JavaScript file encoded in UTF-8 with a BOM. Less from a Mingw console shows:

<U+FEFF>function ...

JSCover chokes on this:

Exception in thread "main" org.mozilla.javascript.EvaluatorException: illegal ch
aracter
        at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultError
Reporter.java:77)
        at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporte
r.java:64)
        at org.mozilla.javascript.Parser.addError(Parser.java:188)
        at org.mozilla.javascript.Parser.addError(Parser.java:166)
        at org.mozilla.javascript.Parser.addError(Parser.java:162)
        at org.mozilla.javascript.TokenStream.getToken(TokenStream.java:832)
        at org.mozilla.javascript.Parser.peekToken(Parser.java:296)
        at org.mozilla.javascript.Parser.name(Parser.java:2880)
        at org.mozilla.javascript.Parser.primaryExpr(Parser.java:2792)
        at org.mozilla.javascript.Parser.memberExpr(Parser.java:2418)
        at org.mozilla.javascript.Parser.unaryExpr(Parser.java:2316)
        at org.mozilla.javascript.Parser.mulExpr(Parser.java:2241)
        at org.mozilla.javascript.Parser.addExpr(Parser.java:2225)
        at org.mozilla.javascript.Parser.shiftExpr(Parser.java:2206)
        at org.mozilla.javascript.Parser.relExpr(Parser.java:2181)
        at org.mozilla.javascript.Parser.eqExpr(Parser.java:2153)
        at org.mozilla.javascript.Parser.bitAndExpr(Parser.java:2142)
        at org.mozilla.javascript.Parser.bitXorExpr(Parser.java:2131)
        at org.mozilla.javascript.Parser.bitOrExpr(Parser.java:2120)
        at org.mozilla.javascript.Parser.andExpr(Parser.java:2109)
        at org.mozilla.javascript.Parser.orExpr(Parser.java:2098)
        at org.mozilla.javascript.Parser.condExpr(Parser.java:2062)
        at org.mozilla.javascript.Parser.assignExpr(Parser.java:2033)
        at org.mozilla.javascript.Parser.expr(Parser.java:2012)
        at org.mozilla.javascript.Parser.nameOrLabel(Parser.java:1765)
        at org.mozilla.javascript.Parser.statementHelper(Parser.java:1032)
        at org.mozilla.javascript.Parser.statement(Parser.java:901)
        at org.mozilla.javascript.Parser.parse(Parser.java:540)
        at org.mozilla.javascript.Parser.parse(Parser.java:478)
        at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.j
ava:413)
        at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceP
rocessor.java:399)
        at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java
:391)
        at jscover.instrument.SourceProcessor.processSourceForFileSystem(SourceP
rocessor.java:385)
        at jscover.instrument.InstrumenterService.instrumentJSForFileSystem(Inst
rumenterService.java:376)
        at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstru
menter.java:387)
        at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstru
menter.java:383)
        at jscover.filesystem.FileSystemInstrumenter.run(FileSystemInstrumenter.
java:368)
        at jscover.Main.runFileSystem(Main.java:445)
        at jscover.Main.runMain(Main.java:418)
        at jscover.Main.main(Main.java:407)

Running PHP files

Is it possible to make JSCover run PHP files?

Maybe you could add a CGI handler to pass off php files?

Instrument issue

Hi,

Use the new build to instrument code, find some issue after instrumented code:
before :
var Count = base + Math.round( (Math.random() - 0.5) * base / 5);
after:
var Count = base + Math.round((Math.random() - 0x0.5) * base / 0x5);

also:
supported = {'a':3.0,'b:7,'c':4,'d':2};
supported= {'a': 0x3.0, 'b': 0x7, 'c': 0x4, 'd': 0x2};

There has some error with instrument decimals, please help check on it.

Thanks in advance!

Support for Windows Store apps

I have a Windows Store app developed in JS. I was wondering how I could instrument the app to collect code coverage data.

Below is what I have done so far:

  • Instrumented the app using File Mode.
  • Packaged the app.
  • Launched the app, which would run the unit tests.

I was wondering how I could see the coverage data for this app?

Thanks,
Rahul

Instrument issue with jquery

In my project, there has a jquery file "jquery-1.7.1.js", instrument the file there has many error in log, you can have a try first.

Thanks in advance!

Proxy mode does not send headers to server when fetching .js files

When running JSCover in proxy mode, and a .js file is requested, the ProxyService class does not send the original request headers to the actual server, causing behavior changes and some times complete failure, especially if the "Cookie" header is involved.

I've changed the ProxyService#getUrl method to send all of the original request headers, (except for the "Accept-Encoding" header) and everything worked perfectly after that.
here is the modified method:

public String getUrl(HttpRequest request) throws IOException {
        URL url = request.getUrl();
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        Map<String, List<String>> clientHeaders = request.getHeaders();
        if (clientHeaders != null) {
            for (String header : clientHeaders.keySet()) {
                if (header.equalsIgnoreCase("accept-encoding")) {
                    continue;
                }
                List<String> values = clientHeaders.get(header);
                for (String value : values) {
                    conn.addRequestProperty(header, value);
                }
            }
        }
        return ioUtils.toString(conn.getInputStream());
    }

_$jscoverage cannot be properly JSON-stringified

I'm experimenting with using JSCover for coverage data generation in the Chutzpah test runner for .NET. As soon as the test run is over, I serialize the _$jscoverage object using JSON.stringify to eventually dump it to a file.

The problem is that the source array is a property of the line count array, and JSON.stringify simply ignores it. Currently, I have to preprocess _$jscoverage before serializing it as a workaround.

It would be nice to get rid of the preprocessing, although I realize that this is a breaking change in that respect.

Could make use of JavaDoc on the APIs

I really appreciate the work done on this project.

The code is harder to read that what I'm used to see, it's very compact, uses a lot of output parameters instead of return, use structure instead of class, and have no JavaDoc.

I could make use of JavaDoc, and the JavaDoc could be available online.

Hexadecimal numeral issue

Hi,
Today I find the new software and have a try, met some issue.

I implement the js code with JSCover, but run the html file failed. Check the implemented JS file, I found there has some Hexadecimal numeral error, like this:
" String.fromCharCode((c1 << 2) | ((c2 & 30) >> 4) & ff)",
while it should be :
"String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4) & 0xff)".
Could anyone give me a hand?
Thanks in advance!

Comma Operator incorrectly handled

Hi, I encountered a piece of code that broke when annotated by JSCover, it goes like this:

if(true, false) {
   // should never reach here
}

This makes use of the Javascript comma operator (https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Comma_Operator) that isn't used very often, but is used by the CoffeeScript compilers 'in' keyword.

JSCover generates the following code:

if(visit0_0_0(true, visit0_0_1(false)) {
    _$jscoverage['myfile.js'][1]++;
    // should never reach here
}

The visit0_0_0 call returns true, its first argument, instead of false, its last argument.

I bet there's an easy fix for this, but I'm working for a deadline at the moment so I didn't have time to make a pull request yet.

Kind regards,
Tinco

In file mode, instrumented files that were not executed at all are not reported as 0% coverage.

  • I have instrumented part of the JS files in my solution using "java -jar JSCover-all.jar -fs ..."
  • I have a suite of unit tests (using QUnit) that use the instrumented files.
  • In my test runner page, I use "window.open('instrumented/jscoverage.html');" to open the code coverage report.
  • Everything runs great, except that there are many instrumented files that are never loaded by the test files (I use google closure to deal with dependencies). I would love it if those files were listed in the code coverage report (as 0%).

encoding problem when var contain no-ascii char

I found out JSCover will transfer wrong with no-ascii char.

My file charset is utf8. And it contains some Chinese word.

Example:

// lib/regexp.js

var foo = /,|,你好/ig;

After JSCover, it will come out:

// lib-cov/regexp.js

// ... ignore ....
_$jscoverage['regexp.js'].source = ["var foo = /,|&#65292;&#20320;&#22909;/ig;"];
_$jscoverage['regexp.js'][1]++;
var foo = /,|???/ig;

Is there any way to set java -jar JSCover-all.jar --encoding=utf8 params just like jscoverage --encoding=utf8 ?

I'm using sibling folder for source and destination and still error out

In the example below it's expected that "webapp-instrumented" folder will be created on the fly in the current folder, which is a sibling of "webapp"

c:\JSCover-0.0.12>dir /w
Volume in drive C is Windows7_OS
Volume Serial Number is B84D-1359

Directory of c:\JSCover-0.0.12

[.] [..] bookmarks.html build.properties build.xml
cobertura.ser [doc] example-filesystem.bat example-filesystem.sh example-server.bat
example-server.sh History.md JSCover.iml JSCover.ipr JSCover.iws
[lib] README.md [src] [target] Todo.md
[webapp]
14 File(s) 185,643 bytes
7 Dir(s) 55,451,303,936 bytes free

c:\JSCover-0.0.12>java -jar C:\JSCover-0.0.12\target\dist\JSCover-all.jar -fs webapp webapp-instrumented
Destination directory 'webapp-instrumented' must not be in the source directory
Usage: java -jar jscover.jar -fs [OPTION]... SOURCE-DIRECTORY DESTINATION-DIRECTORY
Instrument JavaScript with code coverage information.

Options:
--js-version=VERSION use the specified JavaScript version
--no-instrument=PATH copy but do not instrument PATH
--exclude=PATH don't copy from source/PATH
-h, --help display this help and exit

Excess CPU usage when IDLE?

  1. Launch JSCover with default arguments
  2. Observe process CPU usage, remains constant at 100%

Should it be using this much CPU when idling?

Would be nice if I could attach a test name to coverage, then merge api and report able to deal with it

I'm currently coding using JSCover with UI automated test. I can retrieve for each test a JSON report, then merge all of them to one, then use the report tool usingjscoverage.html or Sonar (LCOV).

I do have the information to provide to JSCover which test is running. If somehow we can attach which test is touching a class/method, then we could know which tests to run to test a specific class and method.

I know this is advanced stuff, but I want to put it out there so someone may improve the idea or handle it.

I guess it's about being able to do report mining, and when you can do that you want more "properties" attached to "touch" points.

Malformed JSON

Hi,

I seem to be getting malformed JSON in jscoverage.json sometimes. My guess on why this could be happening is we're running our tests in a parallel fashion and there needs to be some locking when reading / writing from jscoverage.json. I haven't invested if this critical section of code is actually threaded, so I might be talking nonsense.

I'll attach an example of malformed JSON that is being produced shortly.

Have any ideas why this could happen yourself?

Running in webserver mode.

  • Josh

Web server not instrumenting js code

Hi, i'm not able to get the summary and source in the js coverage tool, even though the tests are running fine (i'm using qunit) . Is jscover dependent on the structure of the folder?

Provide ready built jars

Please provide ready build jars for download.
It's probably trivial for you to create the jars.
But I have to install Ant (which I don't know so well), which smells like trouble to me...

coverage report doesn't have full file path

the coverage report has only the file name, it doesn't have the file path, this is an issue when I instrument files in different folder,I can't group them to the same root! so can't generate the reports!

Issue about encoding

When I use jscover as a web server, some js file load failed, while us jscoverage-server with parameter --encoding=utf-8 it can be loaded successfully, I thought this maybe caused by encoding issue. Does the jscover can support the parameter --encoding or is there some way can resolve the issue?

Can anyone give some suggestion on this?
Thanks for your support!

NPE when defining function under reusing var

Code like below gives NPE on line defining "function(record)"

,onViewReady: function(view) {
var store = view.getStore(),
tree = this.getTree(),
treeStore = tree.getStore(),
checkNode = function(record) { // NPE HERE
this.checkNode(record, tree, treeStore);
};

    store.each(checkNode, this);
},

Error on line 23 of app/controller/common/ContactPanel.js
java.lang.NullPointerException
at org.mozilla.javascript.Node.getChildBefore(Node.java:222)
at org.mozilla.javascript.Node.addChildBefore(Node.java:287)
at jscover.instrument.NodeProcessor.processNode(NodeProcessor.java:435)
at jscover.instrument.ParseTreeInstrumenter.visit(ParseTreeInstrumenter.java:371)
at org.mozilla.javascript.ast.FunctionNode.visit(FunctionNode.java:414)
at org.mozilla.javascript.ast.VariableInitializer.visit(VariableInitializer.java:122)
at org.mozilla.javascript.ast.VariableDeclaration.visit(VariableDeclaration.java:151)
at org.mozilla.javascript.ast.Block.visit(Block.java:61)
at org.mozilla.javascript.ast.FunctionNode.visit(FunctionNode.java:421)
at org.mozilla.javascript.ast.InfixExpression.visit(InfixExpression.java:182)
at org.mozilla.javascript.ast.ObjectLiteral.visit(ObjectLiteral.java:132)
at org.mozilla.javascript.ast.FunctionCall.visit(FunctionCall.java:160)
at org.mozilla.javascript.ast.ExpressionStatement.visit(ExpressionStatement.java:120)
at org.mozilla.javascript.ast.ScriptNode.visit(ScriptNode.java:312)
at org.mozilla.javascript.ast.AstRoot.visitAll(AstRoot.java:110)
at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.java:410)
at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceProcessor.java:394)
at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java:386)
at jscover.instrument.SourceProcessor.processSourceForFileSystem(SourceProcessor.java:381)
at jscover.instrument.InstrumenterService.instrumentJSForFileSystem(InstrumenterService.java:375)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:386)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:382)
at jscover.filesystem.FileSystemInstrumenter.run(FileSystemInstrumenter.java:367)
at jscover.Main.runFileSystem(Main.java:444)
at jscover.Main.runMain(Main.java:417)
at jscover.Main.main(Main.java:406)

Create Maven release and POM

It'd be nice to have a ready made maven version for easy inclusion into another maven project.

As an extension, it would be nice to have a maven plugin for launching the server and killing it after the integration phase.

I can try and create a maven pom.xml for you in the next few days if you aren't familiar.

Null Pointer exception using latest version

Hi I am getting below exception while using latest vesion with proxy server
java.lang.NullPointerException
at org.mozilla.javascript.Node.getChildBefore(Node.java:222)
at org.mozilla.javascript.Node.addChildBefore(Node.java:287)
at jscover.instrument.NodeProcessor.processNode(NodeProcessor.java:480)
at jscover.instrument.ParseTreeInstrumenter.visit(ParseTreeInstrumenter.java:367)
at org.mozilla.javascript.ast.IfStatement.visit(IfStatement.java:178)
at org.mozilla.javascript.ast.SwitchCase.visit(SwitchCase.java:149)
at org.mozilla.javascript.ast.SwitchStatement.visit(SwitchStatement.java:175)
at org.mozilla.javascript.ast.Block.visit(Block.java:61)
at org.mozilla.javascript.ast.FunctionNode.visit(FunctionNode.java:423)
at org.mozilla.javascript.ast.InfixExpression.visit(InfixExpression.java:182)
at org.mozilla.javascript.ast.ObjectLiteral.visit(ObjectLiteral.java:132)
at org.mozilla.javascript.ast.InfixExpression.visit(InfixExpression.java:182)
at org.mozilla.javascript.ast.ObjectLiteral.visit(ObjectLiteral.java:132)
at org.mozilla.javascript.ast.InfixExpression.visit(InfixExpression.java:182)
at org.mozilla.javascript.ast.VariableInitializer.visit(VariableInitializer.java:122)
at org.mozilla.javascript.ast.VariableDeclaration.visit(VariableDeclaration.java:151)
at org.mozilla.javascript.ast.Block.visit(Block.java:61)
at org.mozilla.javascript.ast.FunctionNode.visit(FunctionNode.java:423)
at org.mozilla.javascript.ast.FunctionCall.visit(FunctionCall.java:158)
at org.mozilla.javascript.ast.InfixExpression.visit(InfixExpression.java:182)
at org.mozilla.javascript.ast.ExpressionStatement.visit(ExpressionStatement.java:120)
at org.mozilla.javascript.ast.Block.visit(Block.java:61)
at org.mozilla.javascript.ast.FunctionNode.visit(FunctionNode.java:423)
at org.mozilla.javascript.ast.ParenthesizedExpression.visit(ParenthesizedExpression.java:75)
at org.mozilla.javascript.ast.FunctionCall.visit(FunctionCall.java:158)
at org.mozilla.javascript.ast.ExpressionStatement.visit(ExpressionStatement.java:120)
at org.mozilla.javascript.ast.ScriptNode.visit(ScriptNode.java:312)
at org.mozilla.javascript.ast.AstRoot.visitAll(AstRoot.java:110)
at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.java:409)
at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceProcessor.java:394)
at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java:386)
at jscover.instrument.SourceProcessor.processSourceForServer(SourceProcessor.java:375)
at jscover.instrument.InstrumenterService.instrumentJSForWebServer(InstrumenterService.java:368)
at jscover.server.InstrumentingRequestHandler.handleGet(InstrumentingRequestHandler.java:434)
at jscover.server.HttpServer.run(HttpServer.java:403)

org.mozilla.javascript.EvaluatorException

For about 2/3 of my js files I am seeing this error when running

java -jar target/dist/JSCover-all.jar -fs --branch scripts/app jscover

this is a file that causes the issue

Exception in thread "main" org.mozilla.javascript.EvaluatorException: illegal character (ogs.checkout.Factory.js#1)

(function() {

 function CheckoutFactory(api) {
   var self = this;

   self.createCheckout = function(model) {

     var checkout = new window.checkout.CheckoutViewModel(model, api);

      return checkout;
   };
}

window.checkout.Factory = CheckoutFactory;
}());

but some larger more complex files seem to run ok. I'm not sure what's going on. Should I avoid using the -fs option?

Cobertura XML

It would be nice if JSCover could convert the jscoverage.json to a cobertura XML report for integration with Jenkins.

Error when trying to store report

I'm running JSCover 0.1.1 in server mode. When I try to save the report JSON, I get this error in the server's log:

org.mozilla.javascript.EvaluatorException: missing ; before statement
    at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)
    at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:64)
    at org.mozilla.javascript.Parser.addError(Parser.java:188)
    at org.mozilla.javascript.Parser.addError(Parser.java:166)
    at org.mozilla.javascript.Parser.reportError(Parser.java:223)
    at org.mozilla.javascript.Parser.reportError(Parser.java:210)
    at org.mozilla.javascript.Parser.reportError(Parser.java:203)
    at org.mozilla.javascript.Parser.autoInsertSemicolon(Parser.java:1067)
    at org.mozilla.javascript.Parser.statementHelper(Parser.java:1044)
    at org.mozilla.javascript.Parser.statement(Parser.java:901)
    at org.mozilla.javascript.Parser.parse(Parser.java:540)
    at org.mozilla.javascript.Parser.parse(Parser.java:478)
    at jscover.instrument.LineCountNodeVisitor.getCodeLines(LineCountNodeVisitor.java:363)
    at jscover.instrument.UnloadedSourceProcessor.getEmptyCoverageData(UnloadedSourceProcessor.java:376)
    at jscover.server.InstrumentingRequestHandler.handlePost(InstrumentingRequestHandler.java:389)
    at jscover.server.HttpServer.run(HttpServer.java:408)

This is true when running the report from either Chrome or Firefox, with the server on OS X 10.7.4, java v1.6.0_37.

Problems using run-jasmine with JSCover and PhantomJS

I am trying to code coverage with JSCover on a set of unittests (written in Jasmine) executed with PhantomJS.

I have first instrumented the unittest files in the file system mode (with --fs option).

Then I run an ant target with PhantomJS executing run-jasmine on the instrumented files.

I get the error jscoverage_report variable is undefined. I don't see the variable defined in any of the instrumented files.

I think the documentation could be better for the PhantomJS use case.

Is Json file created whenever code coverage is generated?

I instrumented by project using File Mode. Opened jscoverage.html and specified the path to the html page that runs qunit tests.

Tests ran and in the Summary tab I am also seeing the coverage information. Looking into the folder where jscoverage.html exists I don't see the jscoverage.json file. I don't see the store button on jscoverage.html. I was wondering where can I find the code coverage data that I can use for merging and so on.

I have couple of other questions, I will have them separate so it's easier to search for other people.

Thanks,
Rahul

Need a way to be able to shutdown server when launched from Java

Hi,

I am trying to include the JAR in my java plugin for maven. I want to be able to launch / shutdown server from my plugin.

So far its working ok for launching using:

Main main = new Main();
main.runMain(args);

But I am wondering if there is a way to shutdown the server using the main class?

Thanks,
Josh

Can JsCover/JsCoverage be used to get stats of a complete Web application ?

Can JsCover/JsCoverage be used to get stats of a complete Web application without any manual actions. The objective is to see the coverage in even in the presence of tag and without any manual feed.

I need to get coverage of all the web-pages of a web-site/Web-Application just via single command and without browsing to every single page manually.

--merge broken

When trying to merge multiple reports with --merge, the code seems to merge the json files properly, but then promptly copies cover the merged json report with one of the originals.

JSCover doesn't handle floating parentheses well

In my project there are a few localization files which simply contain JS objects of key-value pairs for translation strings, they have a form like this :

    ({ string1: "some string", string2: "some other string" })

This is a rather strange (but valid) use of parentheses in JavaScript, making the file valid JSON and executable javascript, however JSCover is adding things after the first parenthesis, like this :

    (if (! window.jscoverage_report) {

Which is sadly not valid JavaScript. I haven't had time to look any deeper into this but I think since immediately invoked functions (pattern like (function(){/*stuff here */})() ) are handled correctly, there should be a reasonably simple way to do the right thing in this case as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.