How to interpret and run the following ant command? - javascript

I am new to nodeJS and Jake but in my company they are using it to run unit tests.This is how they are running unit tests through ant
<exec executable="cmd" dir="${nodeJsTests.basedir}/../nodejs/">
<arg value="/C"/>
<arg value="start cmd /C "npm install & .\node_modules\.bin\jake local dir=${basedir} --trace & pause"" />
</exec>
From what I understood is they are doing the following things in this piece of code, do correct me if I am wrong
Going to nodejs driectory.
Installing jake at a particular location (.\node_modules.bin\jake)
Run unit tests
I want to achieve the same(run the tests), without using ant.I think I am able to do first two steps but stuck in the third step.I tried running command - Jake local from various directories but no success
If anyone can help me on this?

It's easier to see what's happening if you parse the string in the second arg value:
npm install & .\node_modules\.bin\jake local dir=${basedir} --trace & pause
This is a shorthand way of essentially running these 3 commands in order:
npm install
.\node_modules\.bin\jake local dir=${basedir} --trace
pause
The first command installs all the dependencies defined in your package.json file (which presumably includes jake).
The second command runs the local version of jake (the one that is installed inside the node_modules folder after running the previous step).
The third command is simply a cmd util to pause execution.
As long as you have installed the dependencies you should have no problem running jake without ANT (simply run the 2nd command above, replacing the ${basedir} value, and make sure you run it in the same directory that your package.json is located in).

Related

How to Run JavaScript file with node.js on windows (scribbletune)

Is it possible to run a JavaScript file with node.js on windows? I have been trying to for hours and can't find any more solutions on the internet that work.
I have a js-file that uses scribbletune which only works with node.js.
I have node.js installed and I installed gitbash because it was recommended in a forum.
I tried to run from command prompt and gitbash but nothing seems to happen.
What am I doing wrong? Any help would be very much appreciated.
There is no need to install gitbash to use Node on Windows. It's a handy thing to have if you're used to a *nix environment. If you're not, it just gives you something more to learn, which isn't helpful if you're already in the middle of trying to learn Node.
Just:
Get the Windows installer from https://nodejs.org/en/download/
Run the Windows installer
Create a directory for your project
Open a Command Prompt Window to get a command line
Switch to your project directory
(Optional, but a good idea) Use npm init to create a package.json file (it'll walk you through it)
Install any libs you're going to be using via npm (for instance, npm install scribbletune from your command prompt window)
Put your JavaScript files in that directory
Use node main.js at the command line to run your main file (whatever it's called; main.js is just a placeholder)
Inorder to run a js (java script file) file
step 1. u need to go to the file location where u want to run.
step 2. just use "shift +right click".
u will see a pop-up and go to powershell or cmd.
step 3. type "node FILENAME.js"
final step: you will see the result ^.^

Using CasperJS within a regular JavaScript file

I am trying to create a NodeJS program that utilizes CasperJS within it. I have run into the error that the module 'casper' cannot be found. As a result, I have tried to npm install spooky --save as I have read around that it is a driver, but I am still getting the same error as I was getting before.
Also, before trying to install SpookyJS, I tried
var phantom = require('phantom');
phantom.casperPath = '/path/to/casperjs';
phantom.injectJs(phantom.casperPath + '/bin/bootstrap.js');
Which then gave me the error that injectJs is not a function. Any and all help appreciated.
First of all, to contextualize a bit, here is an important reminder for everyone:
While CasperJS is installable via npm, it is not a NodeJS module and will not work with NodeJS out of the box. You cannot load casper by using require(‘casperjs’) in node. Note that CasperJS is not capable of using a vast majority of NodeJS modules out there. Experiment and use your best judgement.
This is where SpookyJS comes into play... But how to make it work? (I assume you are on Linux.)
1. Make sure you have the right environment
Node.js >= 0.8
PhantomJS >= 1.9
CasperJS >= 1.0
Note: SpookyJS works on my computer (Arch Linux) and I have the following setup:
node --version ---> v7.7.4
npm --version ---> 4.4.4
phantomjs --version ---> 2.1.1
casperjs --version ---> 1.1.3
PhantomJS and CasperJS are installed globally.
2. Install SpookyJS locally (and its dependency: tiny-jsonrpc)
Create an empty directory and run npm i spooky tiny-jsonrpc inside. We do not need a package.json here, so you can forget about --save or --save-dev.
3. Test the given example
If SpookyJS is installed, you should have a local node_modules directory. Now, try to run the following command:
node node_modules/spooky/examples/hello.js
If you get "Hello, from Spooky the Tuff Little Ghost - Wikipedia", congrats! You can now integrate SpookyJS in your project, but you will have to respect the syntax presented in hello.js...
you can't include js files to phantom. you need to open a page and then you can includejs into it. page will accept js files. not phantom.
Please refer this
includeJs(url, callback) {void}
Includes external script from the specified url (usually a remote
location) on the page and executes the callback upon completion.

"CALL "C:\Program Files\nodejs\\node.exe" Error

I have been trying insall node js and install browser sync
C:\Users\Aly>npm install -g browser-sync
'CALL "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files `(x86)\nodejs\\`
node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,operable program or batch file.
Even if i want to know my node js version , the same error appear and then the version shown after that
C:\Users\Aly>npm --version
'CALL "C:\Program Files (x86)\nodejs\\node.exe" "C:\Program Files `(x86)\nodejs\\`
node_modules\npm\bin\npm-cli.js" prefix -g' is not recognized as an internal or external command,operable program or batch file.
3.10.9
Windows 10
Thanks So Much In Advance
I just spend way to long with this issue. I'm not sure how it got set, perhaps during an install, but I changed a System Variable:
Name: ComSpec
Value: %SystemRoot%\system32\cmd.exe;prefix=C:\Program Files (x86)\nodejs\node.exe
To this:
Name: ComSpec
Value: %SystemRoot%\system32\cmd.exe
And restarted my system and the issue was gone.
Good catch blur0224.
I also spent way too long on this issue reinstalling node in various ways and investigating administrator privileges for the %appdata%/roaming/npm -folder.
Your solution worked for me also. The ComSpec variable contained old trash (referring to uninstalled programs) which somehow interfered when calling npm.
Side note 1: What was REALLY confusing was that calling npm worked for many npm package retrievals, but not all. Error code in the failed cases would for me contain keywords such as code ELIFECYCLE and errno ENOENT.
Side note 2: I also received warning 1909 could not create shortcut node.js command prompt.lnk when installing node - perhaps implying that an environmental variable was not properly installed.
Anyone seeing the symptoms from the two previous paragraphs could try the answer from blur0224. I hope this helps people searching for these keywords.
Firstly, check using GitBash whether the npm -v command executes successfully.
If NPM is working in GitBash, then it is not a path problem (your path reference is OK).
Go to Environment Variables > System Variables and check if ComSpec: %SystemRoot%\system32\cmd.exe is correctly configured, or not.
In some cases, if you have a trailing slash, it will not work. (eg: ComSpec : %SystemRoot%\system32\cmd.exe\) If so, simple remove the trailing slash.
Otherwise, check where cmd.exe is located and use that path as the ComSpec value.
Usually, it resides at c://Windows/System32/cmd.exe.

Appium JavaScript, how to write & execute my first test?

I want to run tests with Appium written in JavaScript but I can't find any info on how to write/execute them. I have followed the tutorials that I have found and I am pretty sure that I have everything in place to get going.
I have installed:
npm install appium -g
npm install wd in my local directory
Android SDK
my device's driver and I can see it listed when I run adb devices.
When I run appium-doctor everything is with green ticks, executing appium & starts the appium server (I think?) and everything looks fine. What do I need to do from here on?
What files I need to create?
Any info is appreciated!
It looks like you have everything setup that will allow you to run mocha android-simple.js from the Appium node examples. You may need to npm install various modules required by the test's helpers before it will run.
If that works then the examples and the javascript bindings docs are a good starting point.

beefy command not found

I am new to node.js and trying to follow this tutorial. I am getting an error on the last command beefy game.js:bundle.js --live. It says sh.exe": beefy: command not found
The beefy package version I am using is 2.1.1
Tried to Google this problem but couldn't find a solution.
I have not followed the tutorial in detail, but the response form the console means that the the console command or program called beefy is not installed. The first word of your input into the console will be interpreted to be a command (a little program) that will run.
For instance cd is a program to change directory and the next thing you enter will specify a directory to which to change.
beefy is not a command/console program that is in your system. (It is not a standard command.) Probably somewhere else in the tutorial you were instructed to install it in one of your various bin/ directories (where shell program commands are stored.)
EDIT:
TL;DR
The fix: install beefy globally (on your machine not for directory only) using npm:
npm install beefy --global

Categories