0
我有一個應用程序編寫的anglarjs 2應用程序,我想運行測試使用茉莉花和業力。我還需要測試在無頭的瀏覽器,如PhantomJS意外的令牌「)」當運行phantomJS for angular2使用業力
運行我的配置是目前如下:
卡瑪conf.js
/**
* @author: @AngularClass
*/
// Look in ./config for karma.conf.js
// module.exports = require('./config/karma.conf.js');
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
{pattern: 'src/test/**/*.ts', included: true, watched: true},
// Polyfills.
'node_modules/es6-shim/es6-shim.js',
'node_modules/reflect-metadata/Reflect.js',
// System.js for module loading
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/systemjs/dist/system.src.js',
// Zone.js dependencies
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/proxy.js',
'node_modules/zone.js/dist/sync-test.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',
// RxJs.
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
{pattern: 'karma-test-shim.js', included: true, watched: true},
{pattern: 'built/test/matchers.js', included: true, watched: true},
// paths loaded via module imports
// Angular itself
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: true},
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: true},
// Our built application code
{pattern: 'built/**/*.js', included: false, watched: true},
// paths loaded via Angular's component compiler
// (these paths need to be rewritten, see proxies section)
{pattern: 'built/**/*.html', included: false, watched: true},
{pattern: 'built/**/*.css', included: false, watched: true},
// paths to support debugging with source maps in dev tools
{pattern: 'src/**/*.ts', included: false, watched: false},
{pattern: 'built/**/*.js.map', included: false, watched: false}
],
mime: {
'text/x-typescript': ['ts']
},
// proxied base paths
proxies: {
// required for component assests fetched by Angular's compiler
"/built/app/": "/base/built/app/"
},
preprocessors: {
// this includes the tests as well
"src/**/*.ts": ["typescript"]
},
typescriptPreprocessor: {
// options passed to the typescript compiler
options: {
sourceMap: false, // (optional) Generates corresponding .map file.
target: 'ES5', // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
module: 'commonjs', // (optional) Specify module code generation: 'commonjs' or 'amd'
noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type.
noResolve: true, // (optional) Skip resolution and preprocessing.
removeComments: true, // (optional) Do not emit comments to output.
concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false.
},
// transforming the filenames
transformPath: function(path) {
return path.replace(/\.ts$/, '.js');
}
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', 'PhantomJS'],
singleRun: false
})
}
的package.json
{
"scripts": {
"start": "ng serve"
"test": "karma start karma.conf.js"
},
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"bootstrap": "^3.3.7",
"classlist.js": "^1.1.20150312",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"intl": "^1.2.5",
"ng2-cookies": "^1.0.12",
"primeng": "^4.0.3",
"rxjs": "^5.4.1",
"systemjs": "0.19.27",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.12"
},
"devDependencies": {
"@angular/cli": "1.1.3",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "2.5.53",
"@types/node": "~8.0.3",
"babel": "^6.23.0",
"babelify": "^7.3.0",
"browserify": "^14.4.0",
"codelyzer": "~3.1.1",
"gulp": "^3.9.1",
"gulp-add-src": "^0.2.0",
"gulp-concat": "^2.6.1",
"gulp-sourcemaps": "^2.6.0",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.8",
"jasmine-core": "^2.6.4",
"jasmine-spec-reporter": "^4.1.1",
"karma": "^1.7.0",
"karma-browserify": "^5.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-typescript-preprocessor": "^0.3.1",
"phantomjs": "^2.1.7",
"protractor": "~5.1.2",
"stringify": "^5.1.0",
"ts-node": "~3.1.0",
"tslint": "~5.4.3",
"typescript": "~2.3.4",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
},
"engines": {
"node": ">= 6",
"npm": ">= 3"
}
}
我的測試如下:
describe('universal truths',() => {
it('should do math',() => {
expect(1 + 1).toEqual(2);
expect(5).toBeGreaterThan(4);
});
xit('should skip this',() => {
expect(4).toEqual(40);
});
});
但是我得到一個意外標記「)」當測試中使用的業力的conf文件下面的「文件」配置phantomJS
是否錯誤顯示文件,行號? – onetwo12
它確實與我的測試有關,但是行號在進行預處理時並不存在。 – mangusbrother
加入;在karma-conf.js函數的結尾處? :) – Refilon