0

I'm trying to write unit tests for Angular application and right now working on describing all required packages for unit testing like karma,phantomjs etc. OS: Ubuntu 14.

The thing is that Phantom.js doesn't work without "libfontconfig" installed in the system (bug description) And as I understand it's not possible to install it with:

npm install --save-dev libfontconfig

How to output to user warning that certain installation is required when he tries to do:

npm install

UPD

I decided to provide more specific details on my case. So, I'm going to use Karma and Phantom.js to test my application. Here are all devDependencies of a project:

"devDependencies": 
{
"grunt": "~0.4.5",
"grunt-contrib-less": "~1.1.0",
"grunt-contrib-watch": "~0.6.1",
"jit-grunt": "~0.9.1",
"angular-route": "~1.4.8",
"angular": "~1.4.8",
"moment": "~2.10.6",
"jquery": "~1.11.3",
"bootstrap": "~3.3.6",
"angularjs-datepicker": "~0.2.16",
"phantomjs": "~1.9.8",
"karma": "^0.12.16",
"karma-jasmine": "~0.1.0",
"karma-phantomjs-launcher": "~0.2.3"
}

When I try to run unit test with Karma:

node node_modules/karma/bin/karma start test/karma.conf.js

I receive the following error:

ERROR [phantomjs.launcher]: /vagrant/node_modules/phantomjs/lib/phantom/bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

So, my question is:

1) Should I check existence of this library or I can just describe it in README?

2) If I should check, how I can do it? Is it a good idea to use bash? As I understand it will not work on Windows machine in this case.

Tamara
  • 2,910
  • 6
  • 44
  • 73

1 Answers1

3

You should be able to use the scripts field in your package.json

https://docs.npmjs.com/misc/scripts

Would simply need to create a nodeJS script that you would call on post-install that would do the check for libfontconfig

Kody
  • 1,319
  • 1
  • 9
  • 12
  • Thank you for answer, I get an idea, but I still don't understand how to get information about applications installed in the system from nodeJS? – Tamara Jan 20 '16 at 17:16
  • You would need to do something similar to this http://stackoverflow.com/a/15303236 within the script that you set in the post-install field. – Kody Jan 20 '16 at 17:46
  • Ok, I tried this approach, but it looks like I can not check if application is installed in OS - I can check only npm modules here. While "libfontconfig" is not a npm module. Maybe it's possible to use some bash script here? – Tamara Jan 20 '16 at 19:02
  • Ah, I see.. Yeah that will probably be best. You could uses exec and look at the output of 'which libfontconfig'. – Kody Jan 20 '16 at 19:07
  • @Tamara you can actually use any shell commands in the npm scripts section. See how people use scripts feature as a [build system](http://blog.keithcirkel.co.uk/how-to-use-npm-as-a-build-tool/), running any commands they need to build the app. – Borys Serebrov Jan 20 '16 at 21:35