How to figure out the root cause for JS Error: SyntaxError: Parse error

Apr 26, 2013 at 2:03 PM
Hi All,

I am getting many errors in different files related to syntax as described below , when i run my .js tests as part of Build Process.

JS Error: SyntaxError: Parse error While Running: "TestFile Path".

Note: Tests in these files are able to run and pass successfully.
Anyone, having any idea, how to figure out the syntax issues.

Thanks in advance,
Harish Bansal
Coordinator
Apr 26, 2013 at 2:57 PM
Hmm that is not a helpful error ;)

Could you give me a zip/sample which has this error so I can look into it and help Chutzpah report this better?
Apr 29, 2013 at 9:31 AM
Thanks mmanela for looking into this at such a short notice.

Please find below the sample code from a file. When these tests are run as a part of TFS Build, it shows there are 4 syntax in this file, i mean 4 error messages like "JS Error: SyntaxError: Parse error
While Running: "File Path" "

So, basically it means below code should have 4 syntax errors. Interesting all the tests in this file are run and pass succesfully.

Sample code:

/// <reference path="../ExternalScripts/jquery-1.9.1.min.js"/>
/// <reference path="../ExternalScripts/jquery-ui-1.10.0.min.js"/>
/// <reference path="../ExternalScripts/jquery.mockjax.js" />
/// <reference path="../ExternalScripts/jquery.unobtrusive-ajax.min.js"/>
/// <reference path="../ExternalScripts/jquery.validate.min.js" />
/// <reference path="../ExternalScripts/jquery.validate.unobtrusive.min.js"/>
/// <reference path="../ExternalScripts/modernizr-2.6.2.js" />
/// <reference path="../ExternalScripts/qunit-1.11.0.js" />
/// <reference path = "../Scripts/ABC.Core.js" />
module("ABC RequiredIfEmpty Client Validators Test", {
setup: function () {
},
teardown: function () {

    //Remove the div element from qunit-fixture
    $("#qunit-fixture").children("Div1").remove();
}
});

test("Test RequiredifEmpty : Valid Email and ContactNumber Empty.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val('john@outlook.com');
$("#ContactNumber").val("");

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok(!$("#ContactNumber").hasClass("input-validation-error"), "Empty ContactNumber does not present error.");
});

test("Test RequiredifEmpty : Valid Email and ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val('john@outlook.com');
$("#ContactNumber").val("912344598098");

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok(!$("#ContactNumber").hasClass("input-validation-error"), "Valid ContactNumber does not present error.");
});

test("Test RequiredifEmpty : Empty Email and ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val('');
$("#ContactNumber").val('');

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok($("#ContactNumber").hasClass("input-validation-error"), "Empty ContactNumber presents error.");
});

test("Test RequiredifEmpty : Empty Email and Valid ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val('');
$("#ContactNumber").val('98018927987');

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok(!$("#ContactNumber").hasClass("input-validation-error"), "Valid ContactNumber does not present error.");
});

test("Test RequiredifEmpty : Empty Email and Null ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val('');
$("#ContactNumber").val(null);

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok($("#ContactNumber").hasClass("input-validation-error"), "Null ContactNumber presents error.");
});


test("Test RequiredifEmpty : Null Email and Valid ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val(null);
$("#ContactNumber").val('98018927987');

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok(!$("#ContactNumber").hasClass("input-validation-error"), "Valid ContactNumber does not present error.");
});

test("Test RequiredifEmpty : Null Email and ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val(null);
$("#ContactNumber").val(null);

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok($("#ContactNumber").hasClass("input-validation-error"), "Null ContactNumber presents error.");
});


test("Test RequiredifEmpty : Null Email and Empty ContactNumber.", function () {
// Arrange
$("#qunit-fixture").append('<div id="Div1"><form action="javascript:myFunction(); return false;" id="Form1" method="post"><div><input  id="Email" name="Email" type="text" value="" /><input data-val="true" data-val-ABCrequiredifempty="The field Contact Number is required if Email is empty" data-val-ABCrequiredifempty-otherproperty="Email" id="ContactNumber" name="ContactNumber" type="text" value=""/></div></form></div>');

$('#Email').val(null);
$("#ContactNumber").val('');

// Act
$.validator.unobtrusive.parse(document);
$("#Form1").submit();

// Assert
ok($("#ContactNumber").hasClass("input-validation-error"), "Empty ContactNumber presents error.");
});
Coordinator
May 4, 2013 at 1:59 AM
Could you send me a functioning zip file of your test suite? This would allow me to run it exactly like you have it to see what is going on.
May 4, 2013 at 7:21 AM
Actually, I can't do that, because the code is proprietary code for my client. Whatever contents I have pasted above are the complete contents of a file. There are 5-6 such files, and the tests are run as a part of TFS Build process. All the tests pass, but in the logs, Build report different no. of syntax errors for different files. For the above contents it reports 4 syntax errors.

However, let me check with my client, if it's possible to share the complete zip with you. Can you please share your email id?

Regards,
Harish Bansal