我正在尝试为Angular应用程序编写单元测试,现在正在编写单元测试所需的所有包,如karma,phantomjs等。操作系统:Ubuntu 14。
问题是如果没有在系统中安装“libfontconfig”,Phantom.js就无法工作(bug description)据我所知,无法安装它:
npm install --save-dev libfontconfig
如何输出到用户警告他尝试执行时需要进行某些安装:
npm install
UPD
我决定就我的案子提供更具体的细节。所以,我将使用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机器。
答案 0 :(得分:3)
您应该能够使用package.json
中的 <html >
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Add Rows</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<body ng-controller="MainController" ng-app="MyApp">
<a href="#" class="button" ng-click="addRow()">Add Row</a>
<form>
First Name : <input name="myInput" ng-model="user.firstName" required>
First Name : <input name="myInput" ng-model="user.lastName" required>
</form>
<table>
<thead>
<tr>
<th>Some Header</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="rowContent in rows">
<td>{{rowContent.firstName}}</td>
<td>{{rowContent.lastName}}</td>
</tr>
</tbody>
</table>
<script>
angular.module('MyApp', [])
.controller('MainController', [ '$scope', function($scope) {
$scope.rows = [];
$scope.counter = 0;
$scope.addRow = function() {
$scope.row.push({
firstName: $scope.firstName,
lastName: $scope.lastName
});
$scope.counter++;
}
}]);
</script>
</body>
</html>
字段
https://docs.npmjs.com/misc/scripts
只需要创建一个nodeJS脚本,您可以在安装后调用它来检查scripts