【发布时间】:2016-04-26 15:43:10
【问题描述】:
我正在尝试为 Angular 应用程序编写单元测试,现在正致力于描述单元测试所需的所有包,例如 karma、phantomjs 等。操作系统:Ubuntu 14。
问题是,如果系统中没有安装“libfontconfig”,Phantom.js 将无法工作 (bug description),据我了解,无法安装它:
npm install --save-dev libfontconfig
如何在用户尝试执行某些安装时向用户输出警告:
npm install
更新
我决定就我的案例提供更具体的细节。所以,我将使用 Karma 和 Phantom.js 来测试我的应用程序。以下是项目的所有 devDependencies:
"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"
}
当我尝试使用 Karma 运行单元测试时:
node node_modules/karma/bin/karma start test/karma.conf.js
我收到以下错误:
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
所以,我的问题是:
1) 我应该检查这个库的存在还是我可以在 README 中描述它?
2)如果我应该检查,我该怎么做?使用 bash 是个好主意吗?据我了解,在这种情况下它不适用于 Windows 机器。
【问题讨论】: