如何按单独的文件拆分覆盖范围?现在,捆绑文件一切正常。我正在使用Angular
,Webpack
进行捆绑和Karma
/ Mocha
/Chai
进行测试。
我有以下 webpack.config:
module.exports = {
entry: {
public: "./application/src/public.js",
office: "./application/src/office.js"
},
output: {
path: "./client/javascripts/",
filename: "[name].js",
sourceMapFilename: "[name].js.map"
}
};
并遵循 karma.conf.js:
module.exports = function(config) {
config.set({
basePath: "",
frameworks: ["mocha", "chai"],
reporters: ["mocha", "coverage"],
files: [
"./client/libs/angular/angular.js",
"./client/libs/angular-route/angular-route.js",
"./client/libs/angular-animate/angular-animate.js",
"./client/libs/angular-cookies/angular-cookies.js",
"./client/libs/angular-mocks/angular-mocks.js",
"./client/libs/angular-messages/angular-messages.js",
"./client/javascripts/office.js", /* the bundle */
"./application/**/*_tests.js"
],
preprocessors: {
"./client/javascripts/office.js": ["coverage"]
},
coverageReporter: {
type: "html",
dir: "coverage/"
},
exclude: [],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ["PhantomJS"],
singleRun: false
});
};
样本测试文件:
describe("AccountLoginCtrl", function() {
beforeEach(angular.mock.module("stAccount"));
var $controller;
var AccountLoginCtrl;
var $scope;
beforeEach(angular.mock.inject(function(_$controller_) {
$controller = _$controller_;
$scope = {};
AccountLoginCtrl = $controller("AccountLoginCtrl", {
$scope: $scope
});
}));
it("should exist", function() {
expect(AccountLoginCtrl).to.exist;
});
});