我坚持设置angularjs项目。像业力和茉莉花这样的单元测试需要js。我的项目安装不正确。我对test-main.js和karma.config.js以及如何正确设置业力感到困惑。我总是遇到错误。请说明如何设置和运行业力
projectname
node_modules
public
FolderName
FolderName
app
folderName
contoller
service
app.js
config,js
assets
css
images
js
vedio
templates
html files
tests
unit
dashboardSpec.js
karma.config.js
test-main.js
favicon.ico
index.html
package.json
server.js
我定义了我的项目结构。请指导我如何使用test.main.js和karma.config.js。
test-main.js -
var tests = [];
//console.log("window.__karma__.files",window.__karma__.files);
for (var file in window.__karma__.files) {
if (/Spec\.js$/.test(file)) {
//console.log("if file",file);
tests.push(file);
}
}
//console.log("tests main karma",tests);
requirejs.config({
// Karma serves files from '/base'
baseUrl: '',
paths: {
},
shim: {
},
// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: window.__karma__.start
});
karma.config.js
// Karma configuration
// Generated on Mon Jan 07 2019 13:38:40 GMT+0530 (IST)
module.exports = function(config) {
'use strict';
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],
// list of files / patterns to load in the browser
files: [
'test-main.js',
{pattern: '../assets/js/angular.js',included:true},
{pattern:'../assets/js/angular-mocks.js',included:true},
{pattern:'../assets/js/angular-route.js', included:true},
{pattern:'../app/config.js',included:false},
{pattern:'../app/app.js',included:false},
{pattern:'../app/dashboard/controller/dashboardCtrl.js',included:false},
{pattern: 'unit/*.js', included: false},
],
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}