在使用Karma的角度2应用程序中设置测试时遇到一些问题。我一直在关注ng-cli和ng2-test-seed repo(https://github.com/juliemr/ng2-test-seed/)创建的类似模式。模式是像正常一样运行业力,包含文件,然后使用system.js导入并运行测试文件。一切都是最新的,karma @ current,angular @当前发布候选人(1)
我一直得到一个非常无益的错误,似乎与找不到的文件有关;起初它是我的systemjs.config.js文件,但现在是一些角度测试组件:
create or replace trigger
after insert on cars
for each row
declare
cursor c_trigger is
select p.name, c.license_plate
from people p, cars c
where p.ID=c.ID
and c.license_plate=:new.licenseplate;
v_trigger c_trigger%rowtype;
begin
open c_trigger;
dbms_output.put_line('The client' || v_trigger.name || 'has bought the car whose license plate is' || v_trigger.license_plate);
fetch c_trigger into v_trigger;
close c_trigger;
end trigger;
/
这是我的karma-test-shim.js文件,除了过滤要包含的规范文件之外,它还包括并帮助支架构建,以便它可以运行
这是我的karma.conf.js文件
19 05 2016 11:34:51.324:DEBUG [middleware:source-files]: Requesting /base/client/vendor/@angular/core/testing.js /
19 05 2016 11:34:51.324:DEBUG [middleware:source-files]: Fetching /<path to project>client/vendor/@angular/core/testing.js
19 05 2016 11:34:51.325:DEBUG [middleware:source-files]: Requesting /base/client/vendor/@angular/platform-browser-dynamic/testing.js /
19 05 2016 11:34:51.325:DEBUG [middleware:source-files]: Fetching /<path to project>client/vendor/@angular/platform-browser-dynamic/testing.js
19 05 2016 11:34:51.325:WARN [web-server]: 404: /base/client/vendor/@angular/core/testing.js
19 05 2016 11:34:51.325:WARN [web-server]: 404: /base/client/vendor/@angular/platform-browser-dynamic/testing.js
Missing error handler on `socket`.
TypeError: (msg || "").replace is not a function
at /<path to project>node_modules/karma/lib/reporter.js:45:23
at onBrowserError (/<path to project>node_modules/karma/lib/reporters/base.js:58:60)
at .<anonymous> (/<path to project>node_modules/karma/lib/events.js:13:22)
at emitTwo (events.js:106:13)
at emit (events.js:191:7)
at onKarmaError (/<path to project>node_modules/karma/lib/browser.js:95:13)
at Socket.<anonymous> (/<path to project>node_modules/karma/lib/events.js:13:22)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at Socket.onevent (/<path to project>node_modules/socket.io/lib/socket.js:335:8)
at Socket.onpacket (/<path to project>node_modules/socket.io/lib/socket.js:295:12)
at Client.ondecoded (/<path to project>node_modules/socket.io/lib/client.js:193:14)
at Decoder.Emitter.e19 05 2016 11:34:51.333:DEBUG [Chrome 50.0.2661 (Mac OS X 10.11.4)]: Disconnected during run, waiting 2000ms for reconnecting.
mit (/<path to project>node_modules/component-emitter/index.js:134:20)
at Decoder.add (/<path to project>node_modules/socket.io-parser/index.js:247:12)
at Client.ondata (/<path to project>node_modules/socket.io/lib/client.js:175:18)
at emitOne (events.js:96:13)
19 05 2016 11:34:53.337:WARN [Chrome 50.0.2661 (Mac OS X 10.11.4)]: Disconnected (1 times)
我的karma-test-shim.js文件:
module.exports = function configureKarma(config) {
config.set({
basePath: '.',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
],
customLaunchers: {
// chrome setup for travis CI using chromium
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox'],
},
},
files: [
{ pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: false },
{ pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: false },
{ pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: false },
{ pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: false },
{ pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false },
{ pattern: 'node_modules/zone.js/dist/async-test.js', included: true, watched: false },
//
// // include karma shim
{ pattern: 'karma-test-shim.js', included: true, watched: true },
//
// // include app
{ pattern: '.dev/client/**/*', included: false, watched: true },
],
exclude: [
// Vendor packages might include spec files. We don't want to use those.
'node_modules/**/*.spec.js',
],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.DEBUG,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
});
};