Installing Google js test for unit testing - javascript

I am currently working on JavaScript and want to design unit test for JavaScript I am using google-JS-Test
http://code.google.com/p/google-js-test/
I have downloaded gjstest-1.0.7
I have installed all the prerequisites need.
http://code.google.com/p/google-js-test/wiki/Installing#Prerequisites
but when I install google js test using
$ cd gjstest-1.0.7
$ make
I got following errors
g++ -DHASH_NAMESPACE=__gnu_cxx -lrt -I. -I/usr/include/libxml2 -DDEFAULT_DATA_DIR=/usr/local/share/gjstest -c -o gjstest/internal/cpp/v8_utils.o gjstest/internal/cpp/v8_utils.cc
gjstest/internal/cpp/v8_utils.cc:33: error: ‘v8::StackFrame’ has not been declared
gjstest/internal/cpp/v8_utils.cc:34: error: ‘v8::StackTrace’ has not been declared
gjstest/internal/cpp/v8_utils.cc: In function ‘void gjstest::ConvertToStringVector(const v8::Handle<v8::Value>&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*)’:
gjstest/internal/cpp/v8_utils.cc:60: error: no matching function for call to ‘v8::Array::Get(uint32&)’
/usr/include/v8.h:1161: note: candidates are: v8::Local<v8::Value> v8::Object::Get(v8::Handle<v8::Value>)
make: *** [gjstest/internal/cpp/v8_utils.o] Error 1
It seems like v8 is not install correctly
I have installed V8 using commands like
sudo apt-get install libv8-2.0.3
sudo apt-get install libv8-dbg
sudo apt-get install libv8-dev
And also by downloading it
svn checkout http://v8.googlecode.com/svn/trunk/ v8
cd v8
make dependencies
scons
But still getting these errors
So if any one has installed and used Google Js or installed v8, kindly guide me on how should I solve this problem.
I am using Ubuntu 10.04.
Any help will be appreciated.

This is indeed caused by trying to build gjstest against a very old version of libv8.
I checked out and built a more recent libv8 on ubuntu 10.04 by following the instructions here:
svn checkout http://v8.googlecode.com/svn/trunk/ v8
cd v8
make depdendencies
make native library=shared
cp out/native/lib.target/libv8.so /usr/local/lib/libv8.so
cp include/v8.h /usr/local/include/v8.h
cp include/v8stdint.h /usr/local/include/v8stdint.h
After which gjstest compiled and ran without further surprises.

Related

Vue js & node js installed. Version also showing but not starting

kirti#kirti-Vostro-14-3468:~/flipbook-vue$ node --version
v17.6.0
kirti#kirti-Vostro-14-3468:~/flipbook-vue$ vue --version
#vue/cli 5.0.1
kirti#kirti-Vostro-14-3468:~/flipbook-vue$ npm run serve
> flipbook-vue#0.10.4 serve
> vue-cli-service serve
sh: 1: vue-cli-service: not found
kirti#kirti-Vostro-14-3468:~/flipbook-vue$
System: Ubuntu 20.04
Via: Downloaded via terminal.
I'm running a GitHub repo on my system. I saw the instructions for directly running a github repo on VS Code but as it gave me this error.
I thought, to verify and install vue & node properly first and then run. But, it still gives me error. What can I do?
restart your system it may help sometime it is important to restart your system after installing nodejs

Install SpiderMonkey 45 failed in Ubuntu 16.04

I tried to install SpiderMonkey 45 in Ubuntu 16.04, but I failed. I refered to SpiderMonkey Build Documentation and finished the make process.
cd js/src
autoconf-2.13
mkdir build_DBG.OBJ
cd build_DBG.OBJ
../configure --enable-debug --disable-optimize
make
After the installation, when I change the directory to ../build_DEBUG.OPT/js/src/shell and type js, the terminal gave me an error:
The program 'js' can be found in the following packages:
* nodejs
* rhino
Try: sudo apt install <selected package>
How to solve the problem? Thank you very much.
Calling js directly looks in your PATH environment variable for an executable called js. Since the directory that you built Spidermonkey in isn't in your path, the executable isn't found, causing an error.
./js expands to <your current directory>/js, which is specific enough for your terminal to find the executable and run it.
See this question for a more general explanation as to why ./executable works but executable doesn't.

Karma-Runner on Ubuntu: 'usr/bin/env: node: No such file or directory' error

I am trying to set up the JavaScript code tester Karma, but when I run the command to initialise karma I get the error 'usr/bin/env: node: No such file or directory'. How can I fix it?
As per #digitalmediums
I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so "sudo ln -s /usr/bin/nodejs /usr/bin/node"
sudo ln -s /usr/bin/nodejs /usr/bin/node
this worked for me.
node is a reserved term in ubuntu thus node.js is actually nodejs.
I found a similar question with same issue here
Usually the non packaged node version (not nodejs) that the user installs can be run from /usr/local/bin/node
as
#!/usr/local/bin/node

Rails - Could not find a JavaScript runtime?

I created a new Rails project using rails 3.1.0.rc4 on my local machine but when I try to start the server I get:
Could not find a JavaScript runtime. See here for a list of available runtimes. (ExecJS::RuntimeUnavailable)
Note: This is not about Heroku.
Installing a javascript runtime library such as nodejs solves this
To install nodejs on ubuntu, you can type the following command in the terminal:
sudo apt-get install nodejs
To install nodejs on systems using yum, type the following in the terminal:
yum -y install nodejs
Note from Michael 12/28/2011 - I have changed my accept from this (rubytheracer) to above (nodejs) as therubyracer has code size issues. Heroku now strongly discourage it. It will 'work' but may have size/performance issues.
If you add a runtime, such as therubyracer to your Gemfile and run bundle then try and start the server it should work.
gem 'therubyracer'
A javascript runtime is required for compiling coffeescript and also for uglifier.
Update, 12/12/2011: Some folks found issues with rubytheracer (I think it was mostly code size). They found execjs (or nodejs) worked just as well (if not better) and were much smaller.
n.b. Coffeescript became a standard for 3.1+
Add following gems in your gem file
gem 'therubyracer'
gem 'execjs'
and run
bundle install
OR
Install Node.js to fix it permanently for all projects.
sudo apt-get install nodejs does not work for me. In order to get it to work, I have to do the following:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Hope this will help someone having the same problem as me.
On the windows platform, I met that problem too
The solution for me is just add
C:\Windows\System32
to the PATH
and restart the computer.
I had this issue on a Windows machine and installing node.js was the solution that finally worked for me. This came after trying multiple other routes including trying to get 'therubyracer' working. Though the github for node.js suggests that installation on windows is still unstable, the website at http://nodejs.org/ had a Windows installer which worked perfectly.
if you already install nodejs from source for example, and execjs isn't recognizing it you might want to try this tip: https://coderwall.com/p/hyjdlw
If all fails you can try
# aptitude install nodejs
as root. You can test your install with the following command:
# node -v
If you want to install NPM, please refer following link. Hope it helps.
On CentOS 6.5, the following worked for me:
sudo yum install -y nodejs
Install a Javascript runtime
The error is caused by the absence of a Javascript runtime on your local machine. To resolve this, you'll need to install NodeJS.
You can install NodeJS through the Node Version Manager or nvm:
First, install nvm:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Install Node through nvm:
nvm install 5.9.1
This will install version 5.9.1 of Node.
I ran into this issue using Phusion Passenger (running as an nginx module) on a Redhat server. We already had a Javascript runtime installed. Other Rails apps in the same parent directory worked fine.
It turned out that we had a permissions issue. Run "ls -l" and see if the folder has the same owner and group as other working apps on the system. I had to run chown and chgrp on the folder (with the recursive switch) to fix it.
I hope you have pre-installed nodejs || nmv.
My solution does not require gem setup or installing 'node with sudo apt" when you already have nvm.
All you need is to edit DesctopEntry of RubyMine. for that we will have those small steps:
Go to usr/share/applications
Open in any editor (i use vim ) Rubymine DesktopEntry vim RubyMine
Edit line 6 (starts with Exec). You shoud add to beginning /bin/bash -i -c. So your line should look like this
Exec=/bin/bash -i -c "/home/USERNAME/rubymine/RubyMine-2019.1.2/bin/rubymine.sh" %f
Done! You are glorious!
As a benefit all your environment variables are now available for RubyMine. So you feel no pain with additing them.
On MacOS try running:
brew install node
brew link node
To force the link and overwrite all conflicting files:
brew link --overwrite node
node -v

What is an easy-to-use JavaScript minifier for Ubuntu?

What is an easy-to-use free JavaScript minifier running in Ubuntu?
It should be easy to install as well. ;-)
I'm using the YUI Compressor
Check JSMin:
https://bitbucket.org/dcs/jsmin/
Install it with:
sudo apt-get install python-pip
sudo pip install jsmin
Usage as CLI:
python -m jsmin myfile.js
For example:
python -m jsmin large1.css large2.css > minified.css
As library:
from jsmin import jsmin
with open('myfile.js') as js_file:
minified = jsmin(js_file.read())
Use Closure Compiler
Documentation: Getting started
I recommend using some Javascript task runners such as Grunt or Gulp, if you dont want to use any task runners, just install Node in your ubuntu by
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
Once the installation is complete
Just install a package called "minifier" via NPM ( node package manager )
npm install -g minifier
g in the above command is to make this package available globally throughout the system .
Once the installation is complete you can just run the below command to minify your javascript.
minify --output path/to/output/file path/to/inputfile
Some times using Google Closure compiler, creates lot of problem, Since it throws lot of compiler errors by checking against standards,But still it does a great job, sometimes we will not be in a position to fix those ECMA standard issues displayed by google closure. :)
Hope this post helps other folks who are facing similar issue.

Categories