在过去的几天里,我一直在为使报道有效而斗争,我遇到了一个我无法解决的问题。我正在接收的堆栈跟踪,加上几行周围的调试代码,是
15 07 2016 14:41:53.413:DEBUG [middleware:source-files]: Requesting /jspm_packages/npm/process@0.11.5/browser.js /
15 07 2016 14:41:53.413:DEBUG [middleware:source-files]: Fetching /jspm_packages/npm/process@0.11.5/browser.js
15 07 2016 14:41:53.415:DEBUG [proxy]: proxying request - /jspm_packages/npm/process@0.11.5/browser.js to localhost:9876
15 07 2016 14:41:53.417:DEBUG [middleware:source-files]: Requesting /base/jspm_packages/npm/process@0.11.5/browser.js /
15 07 2016 14:41:53.417:DEBUG [middleware:source-files]: Fetching /home/administrator/assist-2.0/client/jspm_packages/npm/process@0.11.5/browser.js
15 07 2016 14:41:53.419:DEBUG [web-server]: serving: /home/administrator/assist-2.0/client/jspm_packages/npm/process@0.11.5/browser.js
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
Error: (SystemJS) /home/administrator/assist-2.0/client/jspm_packages/system.src.js:3047:137
/home/administrator/assist-2.0/client/jspm_packages/system.src.js:3756:33
/home/administrator/assist-2.0/client/jspm_packages/system.src.js:4251:37
/home/administrator/assist-2.0/client/jspm_packages/system.src.js:1508:27
/home/administrator/assist-2.0/client/jspm_packages/system.src.js:2738:28
register@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:2998:23
eval code
eval@[native code]
__exec@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:1544:18
execute@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:3723:20
linkDynamicModule@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:3281:36
link@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:3124:28
execute@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:3491:17
doDynamicExecute@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:774:32
link@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:972:36
doLink@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:631:11
updateLinkSetOnLoad@/home/administrator/assist-2.0/client/jspm_packages/system.src.js:677:24
/home/administrator/assist-2.0/client/jspm_packages/system.src.js:493:30
invoke@/home/administrator/assist-2.0/client/node_modules/zone.js/dist/zone.js:323:34
runGuarded@/home/administrator/assist-2.0/client/node_modules/zone.js/dist/zone.js:230:54
/home/administrator/assist-2.0/client/node_modules/zone.js/dist/zone.js:206:40
Evaluating http://localhost:9876/dist/src/components/widgets/nested-table/nested-table.component.js
Error loading http://localhost:9876/dist/tests/unit/components/nested-table.spec.js
PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (1.095 secs / 0 secs)
15 07 2016 14:41:53.436:DEBUG [karma]: Run complete, exiting.
15 07 2016 14:41:53.437:DEBUG [launcher]: Disconnecting all browsers
15 07 2016 14:41:53.441:DEBUG [launcher]: Process PhantomJS2 exited with code 0
15 07 2016 14:41:53.442:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-88547336
15 07 2016 14:41:53.449:DEBUG [launcher]: Finished all browserskarma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jspm', 'jasmine'],
basePath: '.',
files: [
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/reflect-metadata/Reflect.js',
'node_modules/es6-shim/es6-shim.js',
'jspm_packages/system-polyfills.js'
],
jspm: {
loadFiles: [
'dist/tests/**/*.js',
],
serveFiles: [
'dist/src/**/*.js',
// 'src/**/*.ts'
]
},
proxies: {
// '/src/': '/base/src/',
'/dist/src/': '/base/dist/src/',
'/dist/tests/': '/base/dist/tests/',
'/jspm_packages/': '/base/jspm_packages/',
},
port: 9876,
logLevel: config.LOG_INFO,
colors: true,
autoWatch: true,
browsers: [
// 'PhantomJS',
'PhantomJS2',
],
plugins: [
'karma-jasmine',
'karma-jspm',
'karma-phantomjs-launcher',
'karma-phantomjs2-launcher',
'karma-junit-reporter',
'karma-coverage',
'karma-sourcemap-loader',
// 'karma-typescript-preprocessor'
],
reporters: [
'coverage',
'junit',
'dots',
],
junitReporter: {
outputDir: '.',
outputFile: "./reports/client-test-results.xml",
useBrowserName: false
},
preprocessors: {
'dist/src/**/!(*.spec).js!(.map)': [
'sourcemap',
// 'typescript',
'coverage'
],
// 'src/**/*.ts': [
// 'sourcemap',
// 'typescript',
// 'coverage',
// ],
},
coverageReporter: {
dir: 'reports',
subdir: 'coverage',
includeAllSources: true,
reporters: [
{
type: 'json',
file: 'coverage.json'
},
// {
// type: 'cobertura',
// file: 'coverage.xml'
// },
// {
// type: 'html',
// subdir: 'coverage/html'
// }
],
instrumenterOptions: {
istanbul: {
noCompact: true
}
}
},
// typescriptPreprocessor: {
// options: {
// inlineSourceMap: true,
// inlineSources: true,
// "target": "es5",
// "module": "system",
// "sourceMap": true,
// "emitDecoratorMetadata": true,
// "experimentalDecorators": true,
// "removeComments": false,
// "noImplicitAny": false,
// },
// transformPath: function(path) {
// return path.replace(/\.ts$/, '.js');
// }
// },
singleRun: true
})
};nested-table.spec.ts
import {NestedTableComponent} from '../../../src/components/widgets/nested-table/nested-table.component';
import {beforeEach, describe, expect, it} from '@angular/core/testing';
import {DEBUG_VIEW_TEST_DATA, DEBUG_VIEW_TEST_HEADERS} from '../../../src/db/mockdata';
import { ImmutableMatchers } from '../helpers/jasmine-immutable-matchers';
describe('Nested Table Component', () => {
let ntable, data, headers;
beforeEach(function() {
jasmine.addMatchers(ImmutableMatchers);
ntable = new NestedTableComponent();
data = DEBUG_VIEW_TEST_DATA[0].data;
headers = DEBUG_VIEW_TEST_HEADERS[0].headers;
});
it('should return an array of keys', () => {
expect(ntable.keys(data)).toEqualImmutable(data.keySeq());
});
it('should calculate the widths of columns', () => {
let expected = {
"Element Property": 4,
"Key": 2,
"Property Value": 2,
"Last Refresh": 2,
"Element Definition": 2
}
expect(ntable.getColWidths(headers)).toEqual(expected);
});
});当我将预处理程序更改为
preprocessors: {
'dist/src/!(*.spec).js!(.map)': [
'sourcemap',
// 'typescript',
'coverage'
],
// 'src/**/*.ts': [
// 'sourcemap',
// 'typescript',
// 'coverage',
// ],
},我没有收到堆栈跟踪,它给了我覆盖,但显然不是在我的其他组件和诸如此类。这似乎是SystemJS模块加载的一个问题,但我不知道发生了什么,或者这是否是实际的问题。
当我从记者列表中删除报道时,测试通过的很好。
我还试图使用业力-类型记录-预处理程序(参考karma.conf.js中注释掉的代码),并且我得到了一个覆盖报告,但是源文件无法正确映射,这一点我也找不出来。
有没有人经历过类似的事情,并找到了克服这个问题的方法?
发布于 2016-08-16 16:07:26
我也在为业力,系统和记录的工作设置而挣扎。我找到了一个可行的设置,但它有点丑陋,它依赖于通过吞咽重新生成覆盖报告,因为重发的业力插件在业力内部不能正确工作,而只是在吞咽中工作。我使用了systemjs插件而不是jspm插件,因为它可以更好地工作。
// Karma configuration
// Generated on Sat Aug 13 2016 18:33:27 GMT+0200 (CEST)
module.exports = function (config) {
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: ['systemjs', 'jasmine'],
// list of files / patterns to load in the browser
files: [
'node_modules/core-js/client/shim.min.js',
'node_modules/reflect-metadata/Reflect.js',
'node_modules/zone.js/dist/zone.js',
// {pattern: 'node_modules/systemjs/dist/system.src.js', included: false, watched: false},
// {pattern: 'jspm_packages/**/*.js', included: false, watched: false},
{pattern: 'jspm_packages/npm/@angular/**/*.js', included: false, watched: false},
{pattern: 'jspm_packages/npm/rxjs@5.0.0-beta.10/**/*.js', included: false, watched: false},
'jspm_packages/npm/lodash@4.13.1/lodash.js',
'jspm_packages/npm/angular2-swiper@0.4.0/dist/ks-swiper.js',
'jspm_packages/npm/swiper@3.3.1/dist/js/swiper.js',
'jspm_packages/npm/jquery@2.2.4/dist/jquery.js',
'jspm_packages/npm/foundation-sites@6.2.3/dist/foundation.js',
'jspm_packages/npm/symbol-observable@1.0.1/index.js',
{pattern: 'jspm_packages/npm/symbol-observable@1.0.1/lib/*.js', included: false, watched: false},
{pattern: 'jspm_packages/npm/rxjs@5.0.0-beta.6/**/*.js', included: false, watched: false},
{pattern: 'jspm_packages/npm/crypto-js@3.1.6/*.js', included: false, watched: false},
{pattern: 'jspm_packages/github/**/*.js', included: false, watched: false},
{pattern: 'jspm_packages/npm/*.js', included: false, watched: false},
{pattern: 'dev/**/*.js', included: true, watched: true},
{pattern: 'test/*.spec.js', included: true, watched: true},
{pattern: 'templates/*.html', included: true, watched: true}
],
// list of files to exclude
exclude: [],
proxies: {
// '/jspm_packages/': '/base/jspm_packages/'
// '/templates/': '/base/templates/'
},
systemjs: {
configFile: 'dev/systemjs.config.js',
// serveFiles: ['test/**/*.spec.js'],
config: {
paths: {
// "github:*": "./jspm_packages/github/*",
// "npm:*": "./jspm_packages/npm/*"
},
map: {
'systemjs': 'node_modules/systemjs/dist/system.js',
'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js'
},
meta: {
'dev/app/*': {format: 'register'}
}
}
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'dev/app/**/*.js': ['coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
// reporters: ['spec', 'coverage', 'karma-remap-istanbul'],
reporters: ['spec', 'coverage'],
coverageReporter: {
reporters: [{
type: 'json',
subdir: '.'
}, {
type: 'text-summary'
}/*, {
type: 'html'
}*/]
},
/*
remapIstanbulReporter: {
src: 'coverage/coverage-final.json',
reports: {
html: 'coverage'
},
dest: './coverage-source'
}, */
// 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_WARN,
// 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: ['PhantomJS', '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
})
};这对我有用。另外,我的任务就在我的档案里。
gulp.task('coverage', ['test'], function () {
return gulp.src('coverage/**/coverage-final.json')
.pipe(remapIstanbul({
reports: {
'json': 'reports/coverage/coverage.json',
'html': 'reports/coverage/html'
}
}))
.pipe(gulp.dest('reports/coverage/'));
});这个设置仍然存在一些问题。例如,一些空的或未“执行”的文件可能会破坏它,因为SystemJS抱怨注册和不执行。测试仅通过*.spec.js包含,因为使用**/*.spec.js不加载任何测试。
我已经填写了一份关于因果报应的错误报告-重新映射-伊斯坦布尔插件。https://github.com/marcules/karma-remap-istanbul/issues/21也许有机会得到业力内部的工作。
我希望这可能有助于改善您的设置,也许我们甚至可以找到一个更好的解决方案与一切工作。
顺便说一句:我尝试使用类似于您的设置,并得到了以下错误,我已经看到了很多时间使用jspm和systemjs扩展:
模块http://localhost:9876/src/common/modules/product/product.js被解释为全局模块格式,但称为System.register。
https://stackoverflow.com/questions/38404476
复制相似问题