getting more information from phantomjs "SyntaxError: Parse error" message - phantomjs

I have a long script that was not written by me. When i run it I get:
phantomjs file.js
SyntaxError: Parse error
i checked out the manual and --help, and the best i could came up with was:
phantomjs --debug=yes file.js
(irrelevant debug statement from CookieJar)
SyntaxError: Parse error
Is there any better way to get at least a line number? or any hint at all?

Run the file with node. If there is a parse error it will report it.
If the file is valid, then node will also try to run it, which will fail if your script depends on something not available in your node environment. So you'll have to ignore any runtime errors.
For example, given hello-world.js:
// Say Hello World twice
for (var i=0; i<2; i++) {
console.log("Hello World") );
}
Run it with node:
node hello-world.js
Output:
/home/someone/somewhere/hello-world.js:3
console.log("Hello World") );
^
SyntaxError: Unexpected token )
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

Your file.js contains an invalid syntax. You should check it with a syntax validator. An online tool which I have created can be one possible solution, check out http://esprima.org/demo/validate.html.

Getting More Information From PhantomJS
The next version of PhantomJS (presumably it will be 1.9.8, whatever comes after 1.9.7) will output errors like this:
SyntaxError: Parse error
http://localhost:9000/scripts/49e8b4f4.vendor.js:8
So that's slightly more useful than the current message.
Unfortunately there are no nightly builds for PhantomJS, so at this time you will need to compile your own version of master if you want to try this.
Debugging Minified files
If you are working with a minified file, often the line number won't be very helpful, and often debugging the un-minified file won't give you the parse error.
To solve this, once you get phantomjs to give you the name of the file, you can use the online demo of Esprima to get an actual parse of your JavaScript code:
http://esprima.org/demo/parse.html
From there, you can enter strategic line breaks to isolate the actual error.
Lint Tools are Sub-optimal for this use-case
A lint tool like jslint or jshint are more opinionated than a real parser, so if you are looking for a very specific syntax error, I would recommend using a real parser, since it will check only for code validity, and not opinionated styling guidelines. I'm not implying lint tools don't have value, just that they won't be as helpful for solving this type of problem.

You can also use syntax linters like jslint or jshint

I received SyntaxError: Parse error while trying to require a custom minified jquery.
I found the solution was to add a blank line to the bottom of jquery.min.js.
Hopefully this helps someone. Using PhantomJS 1.9.7.

I use a simple shell script that will run Phantom normally if no parse errors are found, otherwise it will display the errors. It runs the script through node, checks for SyntaxError in the output and then re-runs node to the terminal if there are errors. It passes all the command line arguments along to Phantom.
Failure mode for this method is if your node parser is significantly different from your Phantom parser. Mine are close enough that it's never been a problem.
usage: ./debug.sh --myArg1 val1 --myArg2 val2
debug.sh:
ERROR=$(node myscript.js 2>&1 >/dev/null | grep "SyntaxError")
if [ "$ERROR" = "" ]; then
echo "No parse errors, running script..."
# run the script with Phantom and pass all the args to it
phantomjs accession.js $*
else
echo "*********************************************************"
echo "********* There are parse errors in the script: *********"
echo "*********************************************************"
# show the errors by running again but not redirecting
node accession.js
fi

I did have the same issue, but none of the solutions worked for me.
I figured that the issue was probably an unsupported syntax by PhantomJS's webkit, since my page was working correctly in current browsers' versions.
What I did was finding out which webkit version PhantomJS was using, for 1.9.* it's here, 34.534.
Now we have to find the Chromium version using the same webkit, or close to it, in here (for Mac).
Ended up going with the Mac OSX 267668 and installed it.
Loaded the same URL as PhantomJS, and here it was, a real Uncaught SyntaxError: Unexpected token with a full stack trace.
Hope that helps.

Related

ESlint problem with Cypress while using Vite

I wanted to try automated testing with Vue3 for my next project.
When I created my app using Vite and selected that I would like to test with Cypress everything seems to work fine but...
Although project starts like it suppose to when i type in console npm run lint I receive an error message saying:
C:\Users\myname\Desktop\vue-project\cypress\support\component.js
27:1 error 'Cypress' is not defined no-undef
and this is the line in which error occurs:
Cypress.Commands.add("mount", mount);
Any help from you guys would be appreciated
Ok so maybe someone will find it helpful.
It appears that problem with this one considers mainly ESlint.
If you can not run Cypress with command npm run test:unit:
make sure Cypress is also installed globally.
Then simply ignore ESlint errors considering cypress and don't change this line - const { defineConfig } = require("cypress"); even if lint suggest
doing it.
Congrats, you now should be able to run tests with Cypress :)
Bonus: if you do mind errors in your console and wanna keep it clean you search for some lint setup considering Cypress, to find a good setup for your lint if you do mind errors in your console.'eslint-plugin-cypress' didn't do the trick for me.

Debug Configuration in WebStorm for CucumberJS and TestCafe based project

I am trying to set up WebStorm for one of the TestCafe project integrated with CucumberJS (Link: https://github.com/rquellh/testcafe-cucumber).
I am able to sort the debug configuration so far using WebStorm help, however, when I debug the project, it throws the following error to the console:
I am passing the following cucumber.js arguments:
--require testlab/**/step_definitions/*.js --tags #debug
And while I debug, I get the following error:
ReferenceError: testController is not defined
at World.<anonymous>
Test ignored.
Test ignored.
Failures:
1) Scenario: Searching for TestCafe on GitHub #
testlab\features\finAPIDemo.feature:6
× Given I open the GitHub page # testlab\step_definitions\github.js:5
ReferenceError: testController is not defined
I am expecting the debug to execute correctly, however, it is not working, the alternative I believe would be to write a js config and pass through as mentioned in the CucumberJS document page, however, I am not sure how to achieve that.
Any input or help will be appreciated.
This error only occurs when running cucumber with --tags #debug, and it's not specific to the IDE - you will face the same issue when starting your tests in terminal with node node_modules/cucumber/bin/cucumber-js --tags #debug:
node node_modules/cucumber/bin/cucumber-js --tags #debug
0 scenarios
0 steps
0m00.000s
E:\WebstormProjects\testcafe-cucumber\features\support\hooks.js:77
if (testController.testRun.lastDriverStatusResponse === 'test-done-confirmation') {
^
ReferenceError: testController is not defined
at Timeout.checkLastResponse [as _onTimeout] (E:\WebstormProjects\testcafe-cucumber\features\support\hooks.js:77:9)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
I'm not sure why you need this option... There are no scenarios marked with #debug in your project, as far as I can see.
I'd suggest using a standard Cucumber.js run configuration for debugging. It works fine for me - tests are run, and breakpoints are hit:
You need to add the #debug directive for the scenario that you want to debug.
See the full setup in this help topic.
I would recommend using cucumber profiles and call that profile instead of using cli commands. Looking at the error you are receiving it looks like you are missing more required directories such as a custom world directory?
Under the hooks.js I have updated the import statements with const assignment and that worked for me:
Replaced:
'import errorHandling from "./support/errorHandling.js";\n' +
'import testControllerHolder from "./support/testControllerHolder.js";\n\n' +
with
'const errorHandling = require("./support/errorHandling.js");\n' +
'const testControllerHolder = require("./support/testControllerHolder.js");\n\n' +

How do I find out which module caused an error in Webpack?

When I run webpack, I get ERROR in Cannot find module 'lodash/lang/isFunction'. However, multiple module depend on lodash. How do I make Webpack go into debug or verbose mode?
Adding debug: true in my Webpack config file didn't do anything.
Are you familiar with the --display-error-details flag? Setting this when executing a build gives you more verbose output on errors (e.g. when a module is missing it will show you all the places it looked to find it). As far as I can tell this is command line only; I haven't been able to find an equivalent when running webpack via node.

I am getting a "Bad response from Chimp Server" in my console when trying to run a meteor app with velocity/cucumber testing on it

The error is not in my regular console, it's in my tail -f console. It won't run the tests at all. In my localhost:3000 velocity sidebar it also says chimp server error. I am not sure how to fix this, I am very new to velocity and cucumber so it could be a stupid mistake, but I couldn't find any information on this error anywhere.
could you provide us with the whole meteor log and also cucumber log? If possible - please do meteor reset first (be aware though that this will clean up your local mongodb, if you want to avoid that, at least clean the cucumber log - echo '' > filePath will work )
I ran into the same problem yesterday while trying to follow Josh Owen's now outdated cucumber tutorial. The error was coming from with the step definition file while not wrapping module.exports in a function like this:
(function() {
module.exports = function() {
// ...
}
});
It could also be that your test directory and files aren't structured correctly in your app.
It should look like this:
app/
tests/
cucumber/
features/
step_definitions/
my_steps.js
my_feature.feature
fixtures/
my_fixture.js
Let me know if that makes a difference. Also, this is a good place to start with velocity/cucumber: http://www.mhurwi.com/a-basic-cucumber-meteor-tutorial/
It's very basic but there isn't much out there for learning testing with Meteor.

Intellij external tool does not output stdout logs from Sass

i'm using sass for my project, in intellij using sass plugin.
i want to be able to launch sass --watch from within intellij, to be able to get console feedback, with clickable lines.
i've setup an external tool in intellij with:
Program: D:\ruby\bin\sass.bat
Parameters: --watch $/FileRelativeDir$
Working directory: $ProjectFileDir$
it does compile my scss to css without problems but the stdout from sass are not reported in the intellij console. i only get stderr.
if i have an error, after a while, i get a bunch of lines at once.
so i'm guessing there is some kind of buffering happening.
redirecting 1>&2 does not solve the problem.
Here's what i get in logs
Sass::Compiler#on_updating_stylesheet callback is deprecated and will be removed in a future release. Use Sass::Compiler#on_updated_stylesheet instead, which is run after stylesheet compilation.
d:/ruby/lib/ruby/gems/1.9.1/gems/sass-3.1.11/vendor/fssm/lib/fssm/support.rb:40: Use RbConfig instead of obsolete and deprecated Config.
and here's what i get using the same command in a console :
Sass::Compiler#on_updating_stylesheet callback is deprecated and will be removed in a future release. Use Sass::Compiler#on_updated_stylesheet instead, which is
run after stylesheet compilation.
>>> Sass is watching for changes. Press Ctrl-C to stop.
error src/main/www/css/test.scss (Line 3690: Invalid CSS after "...'); IE6 & IE7*": expected "{", was "/")
error src/main/www/css/test.scss (Line 80: Invalid CSS after "...unimplemented *": expected "{", was "/")
d:/ruby/lib/ruby/gems/1.9.1/gems/sass-3.1.11/vendor/fssm/lib/fssm/support.rb:40: Use RbConfig instead of obsolete and deprecated Config.
(yes i have an intended error in my scss file to produce logs)
found it thanks to default ruby arguments in intellij ruby projects
you need to pass ruby the following options :
-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)
and that did the trick
Program : D:\ruby\bin\ruby.exe
Parameters : -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) d:/ruby/bin/sass -g --watch $/FileRelativeDir$
Working directory : $ProjectFileDir$