- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
运行以下 gulp 任务以启动 karma 服务器:
gulp.task('unit-test', function () {
// Be sure to return the stream
return gulp.src(['random text because gulp is weird'])
.pipe(debug({verbose: true}))
.pipe(new Server({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: true
})
.start())
.on('error', function (err) {
throw err;
});
});
抛出一些错误:
[17:24:50] 'unit-test' errored after 81 ms
[INFO] [17:24:50] TypeError: Cannot read property 'on' of undefined
[INFO] at DestroyableTransform.Readable.pipe (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp-debug/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:516:7)
[INFO] at Gulp.<anonymous> (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/gulpfile.js:185:14)
[INFO] at module.exports (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
[INFO] at Gulp.Orchestrator._runTask (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
[INFO] at Gulp.Orchestrator._runStep (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
[INFO] at Gulp.Orchestrator.start (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
[INFO] at runNextSet (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:79:16)
[INFO] at Gulp.onTaskEnd (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:68:5)
[INFO] at Gulp.emit (events.js:129:20)
[INFO] at Gulp.Orchestrator._emitTaskDone (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:264:8)
[INFO] at /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:275:23
[INFO] at finish (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
[INFO] at cb (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:29:3)
[INFO] at finish (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:53:5)
[INFO] at runNextSet (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:81:5)
[INFO] at Gulp.onTaskEnd (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:68:5)
[INFO] [17:24:50] 'clean-build-test' errored after 290 ms
[INFO] [17:24:50] Error: [object Object]
[INFO] at formatError (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/bin/gulp.js:169:10)
[INFO] at Gulp.<anonymous> (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/bin/gulp.js:195:15)
[INFO] at Gulp.emit (events.js:129:20)
[INFO] at Gulp.Orchestrator._emitTaskDone (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:264:8)
[INFO] at /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:275:23
[INFO] at finish (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
[INFO] at cb (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:29:3)
[INFO] at finish (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:53:5)
[INFO] at Gulp.onError (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/run-sequence/index.js:60:4)
[INFO] at Gulp.emit (events.js:129:20)
[INFO] at Gulp.Orchestrator._emitTaskDone (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:264:8)
[INFO] at /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:275:23
[INFO] at finish (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
[INFO] at module.exports (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:36:10)
[INFO] at Gulp.Orchestrator._runTask (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
[INFO] at Gulp.Orchestrator._runStep (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
[INFO] [17:24:50] gulp-debug: 0 items
虽然有趣的是 karma 测试仍然通过:
...
...
20 07 2015 17:25:34.934:DEBUG [karma]: List of files has changed, trying to execute
20 07 2015 17:25:34.935:WARN [karma]: No captured browser, open http://localhost:9876/
20 07 2015 17:25:34.937:DEBUG [watcher]: Watching "/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/webapp/js/lib.js"
20 07 2015 17:25:34.938:DEBUG [watcher]: Watching "/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/webapp/js/app.js"
20 07 2015 17:25:34.938:DEBUG [watcher]: Watching "/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/test/unit"
20 07 2015 17:25:34.940:INFO [karma]: Karma v0.13.2 server started at http://localhost:9876/
20 07 2015 17:25:34.943:INFO [launcher]: Starting browser PhantomJS
20 07 2015 17:25:34.944:DEBUG [temp-dir]: Creating temp dir at /var/folders/43/yyskpwq91b3b_qjxpj5nsqkh0000gn/T/karma-97139922
20 07 2015 17:25:34.946:DEBUG [launcher]: /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/phantomjs/lib/phantom/bin/phantomjs /var/folders/43/yyskpwq91b3b_qjxpj5nsqkh0000gn/T/karma-97139922/capture.js
20 07 2015 17:25:35.982:DEBUG [web-server]: serving: /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma/static/client.html
20 07 2015 17:25:35.991:DEBUG [web-server]: serving: /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma/static/karma.js
20 07 2015 17:25:36.008:DEBUG [karma]: A browser has connected on socket Rwzn4QBMQ6mTGcBFAAAA
20 07 2015 17:25:36.011:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=Rwzn4QBMQ6mTGcBFAAAA
20 07 2015 17:25:36.028:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket Rwzn4QBMQ6mTGcBFAAAA with id 97139922
20 07 2015 17:25:36.028:DEBUG [launcher]: PhantomJS (id 97139922) captured in 1.088 secs
20 07 2015 17:25:36.029:DEBUG [karma]: All browsers are ready, executing
20 07 2015 17:25:36.034:DEBUG [web-server]: serving: /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma/static/context.html
20 07 2015 17:25:36.036:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma-chai-plugins/node_modules/sinon/pkg/sinon.js
20 07 2015 17:25:36.037:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma-chai-plugins/function-bind-polyfill.js
20 07 2015 17:25:36.038:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/webapp/js/lib.js
20 07 2015 17:25:36.048:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/chai/chai.js
20 07 2015 17:25:36.048:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma-chai-plugins/chai-adapter.js
20 07 2015 17:25:36.048:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/mocha/mocha.js
20 07 2015 17:25:36.049:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma-mocha/lib/adapter.js
20 07 2015 17:25:36.050:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/test/unit/authenticationService.spec.js
20 07 2015 17:25:36.050:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/test/unit/homepage.spec.js
20 07 2015 17:25:36.050:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/chai-as-promised/lib/chai-as-promised.js
20 07 2015 17:25:36.050:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma-chai-plugins/node_modules/sinon-chai/lib/sinon-chai.js
20 07 2015 17:25:36.051:DEBUG [web-server]: serving (cached): /Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/webapp/js/app.js
....
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 4 of 4 SUCCESS (0.001 secs / 0.003 secs)
尝试更紧密地遵循示例(在服务器调用中添加回调):
gulp.task('unit-test', function (cb) {
// Be sure to return the stream
return gulp.src(['random text because gulp is weird'])
.pipe(debug({verbose: true}))
.pipe(new Server({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: true
}, cb)
.start())
.on('error', function (err) {
throw err;
});
});
导致如下错误:
21:48:36] Error: task completion callback called too many times
at finish (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:15:10)
at cb (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:29:3)
at removeAllListeners (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma/lib/server.js:311:7)
at Server.<anonymous> (/Users/karianna/Documents/workspace/AdoptOpenJDK_Projects/betterrev_project/betterrev/src/main/angularjsapp/node_modules/karma/lib/server.js:322:9)
at Server.g (events.js:199:16)
at Server.emit (events.js:129:20)
at net.js:1419:10
at process._tickCallback (node.js:355:11)
我认为这是因为我有嵌套回调(任务是运行序列的一部分,即)
gulp.task('clean-build-test', function (callback) {
runSequence('clean-build', 'unit-test', 'integration-test', callback);
});
我是 Node 和 Javascript 的新手,很高兴被告知离开并提供更好的信息:-)。
最佳答案
一般来说,Gulp 只负责创建和引导一个流。同时,每个中间人,如您的新服务器
-调用负责从pipe
函数返回一个流。来自 Java,我认为在类型系统的上下文中思考是最容易理解的。将 Gulp 想象成一个类,它实现了:
interface GulpTask {
Stream pipe(Stream stream);
}
当到达调用 new Server
的函数时,您会收到一个流,但不会返回一个。事实上,您不会返回任何返回值默认为 undefined
的东西。因此,错误消息通知您不能在 undefined
上调用 on
。这就像您实现了:
class BrokenStream implements GulpTask {
@Override
public Stream pipe(Stream stream) {
new Server(<something>);
return null;
}
}
发生这种情况的原因是您直接使用 karma 而不知道 Gulp 的流。通常,这不是问题,因为在管道的末端使用了 Karma。
同时,你的错误处理器没有生效。您需要在潜在应用程序之前注册错误处理程序,即:
gulp.task('unit-test', function () {
return gulp
.src(['https://www.youtube.com/watch?v=6Xywqv1cDH8'])
.on('error', function (err) { <do something> }) // Returns a handled stream.
.pipe(<something>); // The received stream now has an error handler.
});
这样,您的流在被下一个管道指令处理时会附加一个错误处理程序。一旦以下任何管道指令发出错误,就会触发此处理程序。
相比之下,您的代码的错误处理程序只会在没有错误发生的情况下附加(假设 new Server
管道返回了一个流)。这也是您的测试运行但最终收到错误处理程序的原因。错误处理程序仅在处理之前的管道之后附加。
也许您正在尝试将错误处理程序附加到您的 Karma 服务器?然后您需要在新创建的服务器上使用不同的参数调用 on
而在 Gulp 流上不。 official Karma API告诉你怎么做。
至于将回调附加到 Karma 服务器:我假设您以此为起点:https://github.com/karma-runner/gulp-karma
请注意,您是在流中使用 Karma 服务器。这不是您通常的做法。
使用管道,Karma 服务器正在接收每个单独的测试并为每个单独的测试触发创建!同时,一旦每个单独的测试运行,每个服务器实例都会收到整个任务的完成回调。因此,您收到第二条错误消息。
您可以通过执行自己的简单步骤来跟踪此行为:
var mapStream = require('map-stream');
gulp.task('unit-test', function () {
return gulp.src(['random text because gulp is weird'])
.pipe(debug({verbose: true}))
.pipe(mapStream(function (file, cb) {
console.log(file);
return cb(null, file)
}))
.pipe(new Server({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: true
}).start())
}
我想知道您为什么要为此目的使用流。只需将 Karma 服务器定义为它自己的任务,就像在前一个插件的示例中所做的那样。或者,您需要像这样包装您的服务器:
.pipe(mapStream(function (file, cb) {
new Server({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: true
}, cb).start()
}))
这样,服务器触发文件步骤的回调而不是任务之一,并且您的应用程序还会返回一个可以由 Gulp 跟踪的回调,以便与您的运行序列进行互操作。
关于javascript - karma -类型错误 : Cannot read property 'on' of undefined (alternative 'task completion callback called too many times' in runsequence),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31521757/
这个问题在这里已经有了答案: Why use async and return await, when you can return Task directly? (8 个答案) 关闭 6 年前。
这个问题在这里已经有了答案: Are the days of passing const std::string & as a parameter over? (13 个答案) 关闭 8 年前。 我
我有一组标记为执行的通用任务。当任务完成时(使用 Task.WaitAny ),我将其添加到 ObservableCollection 中. 但是,问题出在 Task.WaitAny(...)行,上面
经过几个小时的努力,我在我的应用程序中发现了一个错误。我认为下面的 2 个函数具有相同的行为,但事实证明它们没有。 谁能告诉我引擎盖下到底发生了什么,以及为什么它们的行为方式不同? public as
这也与 Python 的导入机制有关,特别是与在函数内使用 import 有关。使用 Python 2.7.9 和 Fabric 1.10.0,创建以下三个文件: fabfile.py: from a
我有一个 Web API Controller (ASP.NET Core 5)。我的一些 API 是异步的,而其中一些不是。我接下来的问题是:使用 public **Task** WebApiMet
我们有类似下面的内容 List uncheckItems = new List(); for (int i = 0; i new Task(async () => await Process
我的代码没问题,但我想知道哪种风格更好,你会怎么看,我正在玩异步方法。 让我建立上下文: Parallel.ForEach(xmlAnimalList, async xml => {
这两种使用 await 的形式在功能上有什么区别吗? string x = await Task.Factory.StartNew(() => GetAnimal("feline")); Task m
我刚刚看到 3 个关于 TPL 使用的例程,它们做同样的工作;这是代码: public static void Main() { Thread.CurrentThread.Name = "Ma
考虑以下代码: public void CacheData() { Task.Run((Action)CacheExternalData); Task.Run(() => CacheE
Task> GetTaskDict() { return Task.FromResult(new Dictionary () ); } 此代码无法编译,因为我们无法在 Task> 到 Tas
我正在使用 ASP.NET 5 RC1 _MyPartial @model MyViewModel @using (Html.BeginForm())
当我尝试在 VS Code 中构建 C 任务时,它显示以下消息: 输出仅显示:The task provider for "C/C++" tasks unexpectedly provided a t
一些背景: 基本上归结为我希望能够在当前线程中“执行”任务。为什么? -我有一个任务创建程序例程,有一次我希望任务在后台任务中立即执行,而其他时候我希望使用 IOmniThreadPool 安排任务。
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我试图将run-sequence添加到我的gulp工作流程中,但是每次尝试执行使用run-sequence的任务时,都会出现此错误: 任务未配置为gulp上的任务。 根据运行序列的来源,这是由以下te
此代码在VS2015中给出了编译时错误 Error CS0266 Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'Sy
我正在尝试通过我的代码通过Google登出: suspend fun signOut(context: Context): Boolean = with(Dispatchers.IO) { t
谁能解释一下这两种说法的区别: Task bTask = backup.BackupCurrentDatabaseAsync() .ContinueWith(_ => CompressArch
我是一名优秀的程序员,十分优秀!