tntim96 / JSCover

JSCover is a JavaScript Code Coverage Tool that measures line, branch and function coverage
GNU General Public License v2.0
399 stars 84 forks source link

"Error saving coverage data",jscover.server.InstrumentingRequestHandler, com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 8376000 path $..functionData[35] #267

Closed weiding111 closed 6 years ago

weiding111 commented 6 years ago

There are error messages as followings when I use jscover and adding the option "--include-unloaded-js" in proxy mode.

start proxy command - java -jar JSCover-all-2.0.3.jar -ws --proxy --port=3128 --report-dir=./jscover/output --document-root=/Users/weiding/Git/fmw-bi-qafmk/bitools-utils/podapiutil/coverage/carbs/js/plugins --local-storage --include-unloaded-js

I do not have any idea about this issue. Is it a bug when saving the coverage data?

Detailed error messages- 20180403 11:20:00.439,227,SEVERE,"Error saving coverage data",jscover.server.InstrumentingRequestHandler, com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 8370739 path $..branchData.5[1].evalFalse at com.google.gson.Gson.fromJson(Gson.java:902) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.google.gson.Gson.fromJson(Gson.java:773) at jscover.report.JSONDataMerger.jsonToMap(JSONDataMerger.java:404) at jscover.report.JSONDataSaver.saveJSONData(JSONDataSaver.java:382) at jscover.server.InstrumentingRequestHandler.storeReport(InstrumentingRequestHandler.java:421) at jscover.server.InstrumentingRequestHandler.handlePostOrPut(InstrumentingRequestHandler.java:391) at jscover.server.HttpServer.run(HttpServer.java:418) Caused by: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 8370739 path $..branchData.5[1].evalFalse at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1559) at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1017) at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:61) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145) at com.google.gson.Gson.fromJson(Gson.java:887) ... 8 more

20180403 11:25:32.769,441,SEVERE,"Error saving coverage data",jscover.server.InstrumentingRequestHandler, com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 8376000 path $..functionData[35] at com.google.gson.Gson.fromJson(Gson.java:897) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.google.gson.Gson.fromJson(Gson.java:773) at jscover.report.JSONDataMerger.jsonToMap(JSONDataMerger.java:404) at jscover.report.JSONDataSaver.saveJSONData(JSONDataSaver.java:382) at jscover.server.InstrumentingRequestHandler.storeReport(InstrumentingRequestHandler.java:421) at jscover.server.InstrumentingRequestHandler.handlePostOrPut(InstrumentingRequestHandler.java:391) at jscover.server.HttpServer.run(HttpServer.java:418) Caused by: java.io.EOFException: End of input at line 1 column 8376000 path $..functionData[35] at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1393) at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:467) at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:414) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:60) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145) at com.google.gson.Gson.fromJson(Gson.java:887) ... 8 more

tntim96 commented 6 years ago

First thing to check is the URI to file path translation or you can try running without the --include-unloaded-js just to see if this is the cause.

If that's not the problem, I'd probably have to see the JSON to determine what's causing the error.

weiding111 commented 6 years ago

I tried running without the |--include-unloaded-js, there is no issue without ||--include-unloaded-js. This error only appears when running with |||--include-unloaded-js.

Thanks, Wei

On 03/04/2018 6:35 PM, tntim96 wrote:

First thing to check is the URI to file path translation https://urldefense.proofpoint.com/v2/url?u=http-3A__tntim96.github.io_JSCover_manual_manual.xml-23proxyURIToFilePathTranslation&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=brO5Ub7iyJF6SWs0LCqku2Z2mrued19mhvnHi-Q0xZA&m=wyYI82YmXC0kpIKDz30gLkWll_zhUZ5If9_6OrFw7aI&s=yieLxJHPdnj-eOJMW5wn4btxnnlhrsq5K_qoptVsqog&e= or you can try running without the |--include-unloaded-js| just to see if this is the cause.

If that's not the problem, I'd probably have to see the JSON what's causing the error.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_tntim96_JSCover_issues_267-23issuecomment-2D378205322&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=brO5Ub7iyJF6SWs0LCqku2Z2mrued19mhvnHi-Q0xZA&m=wyYI82YmXC0kpIKDz30gLkWll_zhUZ5If9_6OrFw7aI&s=WSWVCurnGwHRnnbzeudD28W94aj0h5RpA619nhiNL1I&e=, or mute the thread https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AkRZPPteKcOMkFGaBEy1DTzMr4kxgGG1ks5tk1B4gaJpZM4TEtDW&d=DwMFaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=brO5Ub7iyJF6SWs0LCqku2Z2mrued19mhvnHi-Q0xZA&m=wyYI82YmXC0kpIKDz30gLkWll_zhUZ5If9_6OrFw7aI&s=h-u79neggDfO1twr6YPV2qjIONa8x90erTJinDtNDzE&e=.

tntim96 commented 6 years ago

In that case, please read the URI to file path translation documentation - it may need some tweaking. Also take a look in the log file to make sure there's no error there.

Also, you might be able to narrow down which "unloaded-source-file" is causing the problem by progressively removing files. I can add logging to assist with this, and can tailor that to whatever you need. Let me know.

weiding111 commented 6 years ago

Is it possible to get more logs info, like which js file cause the error? Is the error due to the file under --document-root is not with the expected format?

tntim96 commented 6 years ago

Can you put the JSON somewhere for me to look at?

weiding111 commented 6 years ago

Which json file do you mean? As for my side, I just start the jscover server by proxy mode, and running the selenium automated tests by firefox. Then the error messages appear in the jscover.log. There is no json file under --report-dir, there are jscover.log, jscover.log.lck and original-src folder under --report-dir.

weiding111 commented 6 years ago

I call the following code in the framework. Generate the reprot - ((JavascriptExecutor)(auto.getDriver())).executeScript( "if(window.jscoverage_report)jscoverage_report();");

Firefox Profile setting - firefoxProfile.setPreference("network.proxy.http", "localhost"); firefoxProfile.setPreference("network.proxy.http_port", "3128");

There is jscoverage.json under --report-dir without "--unloaded-source-file"

tntim96 commented 6 years ago

Is it possible to get more logs info, like which js file cause the error?

If you set the logging level to FINE or jscover.util.FileScanner.level = FINE as described in the documentation section on logging, you should see something like 20180404 20:45:24.143,18,FINE,"Adding path test-simple.js",jscover.util.FileScanner. Hopefully you'll notice if something is there that shouldn't be.

Is the error due to the file under --document-root is not with the expected format?

I suspect so.

weiding111 commented 6 years ago

I use logging level FINE and found there are many WARNING,"Bad type annotation...." against js files, but indeed, these js files contains the correct content. Set an example as following.

Warning message - 20180409 13:22:54.286,223,WARNING,"Bad type annotation. expected closing } See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information., sourceName: application/obitech-data-replication/datareplication-replicateobjects-step.js, line: 2,068 lineOffset: 25",jscover.instrument.SourceProcessor,

source code on 2068 line - 2065 /* 2066 Validates the custom object against the source connection by trying to get the object list 2067 @param {String} sCustomObject The custom object name 2068 @returns {module:obitech-framework/uif-promise.Promise} A promise that will be rejected if the custom object does not exist 2069 */

There are too many js files has this kind of warning messages (more than 10000), so I could not use the way of filtering these source files from --document-root dir. Is there any other way to make it work?

Another question is about "Translating a URI to a File Path", if I use "--uri-to-file-matcher=REG" and "--uri-to-file-replace=REG" to mapping URI to a local file location, the issue above should be a blocker, right?

tntim96 commented 6 years ago

There are too many js files has this kind of warning messages (more than 10000), so I could not use the way of filtering these source files from --document-root dir. Is there any other way to make it work?

What about excluding by regular expression using --no-instrument-reg?

weiding111 commented 6 years ago

The point is most of them are the files we need to map to URI files, if I exclude them, there are many source files are missing, and js coverage report will lost the area that automated tests not covered.

tntim96 commented 6 years ago

OK. Can you provide a sample of the code that isn't parsed correctly and provide details of what tools you use with the source currently?

weiding111 commented 6 years ago

The source files are provided by other DEV, I use selenium webdriver to implement automated tests. So I am not sure what tools the DEV uses. Here is an sample of the code that isn't parsed correctly. ` // Copyright © 1997, 2018, and/or its affiliates // All rights reserved.

/**

/**

` Here is the error message -

20180409 13:54:12.438,212,WARNING,"illegal use of unknown JSDoc tag "exports"; ignoring it, sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 36 lineOffset: 6",jscover.instrument.SourceProcessor, 20180409 13:54:12.438,212,WARNING,"Bad type annotation. expected closing } See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information., sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 45 lineOffset: 19",jscover.instrument.SourceProcessor, 20180409 13:54:12.438,212,WARNING,"Bad type annotation. expecting a variable name in a @param tag. See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information., sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 45 lineOffset: 19",jscover.instrument.SourceProcessor, 20180409 13:54:12.438,212,WARNING,"Bad type annotation. expected closing } See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information., sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 47 lineOffset: 21",jscover.instrument.SourceProcessor, 20180409 13:54:12.438,212,WARNING,"illegal use of unknown JSDoc tag "inheritdoc"; ignoring it, sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 63 lineOffset: 6",jscover.instrument.SourceProcessor, 20180409 13:54:12.438,212,WARNING,"Bad type annotation. expected closing } See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information., sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 75 lineOffset: 20",jscover.instrument.SourceProcessor, 20180409 13:54:12.438,212,WARNING,"Bad type annotation. expecting a variable name in a @param tag. See https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation for more information., sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 75 lineOffset: 20",jscover.instrument.SourceProcessor, 20180409 13:54:12.439,212,WARNING,"illegal use of unknown JSDoc tag "funcdataoDition"; ignoring it, sourceName: report/obitech-dssdataset/catalogsourcequerycard.js, line: 78 lineOffset: 6",jscover.instrument.SourceProcessor,

tntim96 commented 6 years ago

That looks like a library. Normally you'd exclude them from coverage reports (unless you're from Oracle and own that source).

weiding111 commented 6 years ago

I excluded all the files which is not parsed from from --document-root dir, and the issue still be there. So I think the error is not due to Unformatted js files as they are the WARNING message in log. Please see the error message in jscover.log after I exclude these unformatted files. Do you have any idea from the log? If you want to see the whole content of the log, I could send the log to your email?

... 20180411 16:06:27.708,217,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180411 16:06:27.709,217,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180411 16:06:35.895,217,INFO,"Saving/merging JSON with unloaded JavaScript JSON",jscover.report.JSONDataSaver, 20180411 16:06:35.895,217,INFO,"Saving/merging JSON with unloaded JavaScript JSON",jscover.report.JSONDataSaver, 20180411 16:06:36.194,217,SEVERE,"Error saving coverage data",jscover.server.InstrumentingRequestHandler, com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 8372464 path $..branchData.5[1]. at com.google.gson.Gson.fromJson(Gson.java:902) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.google.gson.Gson.fromJson(Gson.java:773) at jscover.report.JSONDataMerger.jsonToMap(JSONDataMerger.java:404) at jscover.report.JSONDataSaver.saveJSONData(JSONDataSaver.java:382) at jscover.server.InstrumentingRequestHandler.storeReport(InstrumentingRequestHandler.java:421) at jscover.server.InstrumentingRequestHandler.handlePostOrPut(InstrumentingRequestHandler.java:391) at jscover.server.HttpServer.run(HttpServer.java:418) Caused by: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 8372464 path $..branchData.5[1]. at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1559) at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1017) at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:61) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145) at com.google.gson.Gson.fromJson(Gson.java:887) ... 8 more

20180411 16:06:36.204,217,FINE,"Sending response status:200 OK mime:text/plain",jscover.server.HttpServer,

tntim96 commented 6 years ago

I just tried with the current JSCover which uses closure-compiler v20180402 and didn't see an issue.

Can you try again with http://jscover.sourceforge.net/latest/JSCover-all.jar or with maven:

<!--- Configure repository --->
<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
<!--- Configure snapshot --->
<dependency>
    <groupId>com.github.tntim96</groupId>
    <artifactId>JSCover</artifactId>
    <version>2.0.5-SNAPSHOT</version>
</dependency>

If that fixes the issue I'll release ASAP.

tntim96 commented 6 years ago

Actually - I've just released 2.0.5 anyway, so you can try that.

weiding111 commented 6 years ago

I used the jscover-all.jar file against release 2.0.5, the error is not the com.google.gson.stream.MalformedJsonException, the new exception "com.google.gson.JsonSyntaxException: java.io.EOFException" appears.

Here is the log -

...... 20180412 14:01:10.023,367,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180412 14:01:10.024,367,FINE,"Adding empty coverage for file: '/Users/weiding/Git/fmw-bi-qafmk/bitools-utils/podapiutil/coverage/carbs/js/plugins/application/obitech-share/nls/ru/exportscreenshotconf.messages.js' URI: 'obitech-share/nls/ru/exportscreenshotconf.messages.js'",jscover.instrument.UnloadedSourceProcessor, 20180412 14:01:10.024,367,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180412 14:01:10.024,367,FINE,"Adding empty coverage for file: '/Users/weiding/Git/fmw-bi-qafmk/bitools-utils/podapiutil/coverage/carbs/js/plugins/application/obitech-appservices/nls/el/messagecomponent.messages.js' URI: 'obitech-appservices/nls/el/messagecomponent.messages.js'",jscover.instrument.UnloadedSourceProcessor, 20180412 14:01:10.025,367,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180412 14:01:10.025,367,FINE,"Adding empty coverage for file: '/Users/weiding/Git/fmw-bi-qafmk/bitools-utils/podapiutil/coverage/carbs/js/plugins/application/obitech-appservices/nls/he/cspmanager.messages.js' URI: 'obitech-appservices/nls/he/cspmanager.messages.js'",jscover.instrument.UnloadedSourceProcessor, 20180412 14:01:10.025,367,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180412 14:01:10.025,367,FINE,"Adding empty coverage for file: '/Users/weiding/Git/fmw-bi-qafmk/bitools-utils/podapiutil/coverage/carbs/js/plugins/application/obitech-appservices/nls/ro/messagecomponent.messages.js' URI: 'obitech-appservices/nls/ro/messagecomponent.messages.js'",jscover.instrument.UnloadedSourceProcessor, 20180412 14:01:10.025,367,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180412 14:01:10.026,367,FINE,"Adding empty coverage for file: '/Users/weiding/Git/fmw-bi-qafmk/bitools-utils/podapiutil/coverage/carbs/js/plugins/application/obitech-appservices/nls/pt/gadgetfactory.messages.js' URI: 'obitech-appservices/nls/pt/gadgetfactory.messages.js'",jscover.instrument.UnloadedSourceProcessor, 20180412 14:01:10.026,367,FINE,"No branchInstrumentor condition changes after parse 1",jscover.instrument.SourceProcessor, 20180412 14:01:12.220,367,INFO,"Saving/merging JSON with unloaded JavaScript JSON",jscover.report.JSONDataSaver, 20180412 14:01:12.220,367,INFO,"Saving/merging JSON with unloaded JavaScript JSON",jscover.report.JSONDataSaver, 20180412 14:01:12.310,367,SEVERE,"Error saving coverage data",jscover.server.InstrumentingRequestHandler, com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 8352906 path $..branchData.3[187].nodeLength at com.google.gson.Gson.fromJson(Gson.java:897) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.google.gson.Gson.fromJson(Gson.java:773) at jscover.report.JSONDataMerger.jsonToMap(JSONDataMerger.java:404) at jscover.report.JSONDataSaver.saveJSONData(JSONDataSaver.java:382) at jscover.server.InstrumentingRequestHandler.storeReport(InstrumentingRequestHandler.java:421) at jscover.server.InstrumentingRequestHandler.handlePostOrPut(InstrumentingRequestHandler.java:391) at jscover.server.HttpServer.run(HttpServer.java:418) Caused by: java.io.EOFException: End of input at line 1 column 8352906 path $..branchData.3[187].nodeLength at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1393) at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:482) at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:414) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:69) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:61) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:70) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187) at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145) at com.google.gson.Gson.fromJson(Gson.java:887) ... 8 more

weiding111 commented 6 years ago

indeed, I choose different sub folder as --document-root, the exception is different. Sometime it is com.google.gson.stream.MalformedJsonException and sometime it is com.google.gson.JsonSyntaxException.

tntim96 commented 6 years ago

I think I need a copy of the source code (minimal example) or JSON to progress this.

weiding111 commented 6 years ago

Could you please show me your email so I could send your the code?

tntim96 commented 6 years ago

Just paste a minimal example here with nothing confidential in it (i.e. remove all the code except the part causing the error and rename as necessary). Also, you could post to the closure-compiler issues, because that's sounding like where it'll get fixed.

weiding111 commented 6 years ago

Is there any restriction for the folder depth of --document-root?

tntim96 commented 6 years ago

Nothing that I've put in. It should be able to work to a large depth.

weiding111 commented 6 years ago

I take much effort to focus on the limitation the code scope and test code scope. I discovered that, this issue only appears when I load the login page in the automation test no matter what the --document-root dir is. it is very simple test code which just login our product. The test code I used as following.- ` public static void main(String[] args) { FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference("network.proxy.type", 1); firefoxProfile.setPreference("network.proxy.http", "localhost"); firefoxProfile.setPreference("network.proxy.http_port", 3128);

    WebDriver driver = new FirefoxDriver(firefoxProfile);
    driver.get("http://slc13ard.us.oracle.com:9704/va");
    driver.manage().window().maximize();

    try {
        Thread.sleep(2000);
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    WebElement username = driver.findElement(By.xpath("//input[@id='idUser']"));
    WebElement passwd = driver.findElement(By.xpath("//input[@id='idPassword']"));
    WebElement button = driver.findElement(By.xpath("//button[@id='btn_login']"));
    username.sendKeys("admin");
    passwd.sendKeys("welcome1");
    **button.click();**

       ((JavascriptExecutor)(driver)).executeScript(
            "if(window.jscoverage_report)jscoverage_report();");
    driver.close();
}`

Below is my conclusion about this issue -

So I guess there is something wrong when jscover adding additional code about branch data to the js files which loaded after login. My doubt is why only appears when I use --include-unloaded-js? As I use the same --document-root dir, same selenium code. Is there any difference about the jscover work logic between with --include-unloaded-js or without --include-unloaded-js when adding the branch related jscover code?

tntim96 commented 6 years ago

Is there any difference about the jscover work logic between with --include-unloaded-js or without --include-unloaded-js when adding the branch related jscover code?

There will be a slight difference as the uncovered branches have to be calculated. The relevant code is here.

weiding111 commented 6 years ago

I could not get any clue from the source code you mentioned. The error contains "SEVERE,"Error saving coverage data",jscover.server.InstrumentingRequestHandler, com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 8727168 path $..branchData.3[441].evalFalse". So I think it should relate to the source code where adding "branchData" to js files or collecting and summary the branch data part into jacoverage.json.

weiding111 commented 6 years ago

As the issue appears when 2 conditions together

tntim96 commented 6 years ago

So is there any relation between covered js files and unloaded js files when generate the branch data?

Yes. It's hard for me to debug the problem from that information. It would be helpful to isolate (and remove anything sensitive from) the JavaScript source code that is causing the problem.

weiding111 commented 6 years ago

I would like to strip js source code that is causing the problem. But you know that, it is product, how could I know which Javascript that JSCover covered is caused this issue? I could know the source code not covered which is under --document-root dir, but I don't know which covered Javascript from product causing the problem. Now the issue is blocked here. The only way I could think about is there is origin-src under target folder which is generated automatically when enable "--include-unloaded-js", the files under origin-src are the Javascript source code which covered, right? Could this issue be reproduced if I provide these origin-src to you side? Do you have any other idea to move this issue on?

tntim96 commented 6 years ago

I see a couple of options:

  1. Use a binary search to exclude different parts of the unloaded JavaScript to narrow down the source
  2. Try instrumenting the JavaScript on the file system and deploy that to your system instead of using proxy mode. There's a working example here.

I recommend trying option 2, because it's a more robust way to test anyway.

weiding111 commented 6 years ago

just one doubt of the option 1. There is no issue when I use "--include-unloaded-js" and the selenium tests does not launched the login page of the product. There are 3 situations here.

  1. with "--include-unloaded-js", not login product page ---- no issue
  2. no "--include-unloaded-js", login product page -------no issue
  3. "--include-unloaded-js" and login product page ---the issue appears.

so the focus should be the relation between covered js files and unloaded js files when generate the branch data, I am not clear about the option 1. Please correct me if my understanding is wrong?

tntim96 commented 6 years ago

Firstly, I recommend option 2.

With option 1, I'm suggesting a mechanism for narrowing down which source file are causing they error. The --include-unloaded-js option will respect the --no-instrument(-reg) and --only-instrument-reg to help you narrow down the cause.