英文:
Kotlin JavaScript Karma test fails
问题
在运行测试时出现以下错误:
错误:超过2000毫秒的超时。对于异步测试和挂钩,请确保调用“done()”;如果返回Promise,请确保它已解决。
build.gradle.kts
js(IR) {
useCommonJs()
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
binaries.executable()
}
在karma.config.d/karma.conf.js
中增加超时时间没有帮助:
module.exports = function (config) {
config.set({
crossOriginAttribute: false,
processKillTimeout: 90000,
browserDisconnectTimeout: 90000,
browserNoActivityTimeout: 90000,
frameworks: ['mocha'],
client: {
timeout: "9s",
mocha: {
timeout: "9s",
reporter: "spec",
args: ['timeout', '9s']
},
}
});
};
我可以看到配置已合并到build/js/packages/project-name-test/karma.conf.js
中,但似乎没有产生任何效果。
英文:
Getting the following error when running the test
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
build.gradle.kts
js(IR) {
useCommonJs()
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
binaries.executable()
}
Increasing timeouts in karma.config.d/karma.conf.js
didn't help:
module.exports = function (config) {
config.set({
crossOriginAttribute: false,
processKillTimeout: 90000,
browserDisconnectTimeout: 90000,
browserNoActivityTimeout: 90000,
frameworks: ['mocha'],
client: {
timeout: "9s",
mocha: {
timeout: "9s",
reporter: "spec",
args: ["timeout", "9s"]
},
}
});
};
I can see that the config is merged into build/js/packages/project-name-test/karma.conf.js
but looks like it doesn't have any effect.
答案1
得分: 2
使用整数而不是字符串来指定 Mocha 的超时时间:
config.set({
client: {
mocha: {
timeout: 9000
}
}
})
然后对于 JsBrowser,这对我有用,但对于 JsNode,我还需要在 build.gradle(.kts)
中设置:
kotlin {
js(IR) {
nodejs {
testTask {
useMocha {
timeout = "9s"
}
}
}
}
// ...
}
英文:
Use an integer instead of a string to specify Mocha's timeout:
config.set({
client: {
mocha: {
timeout: 9000
}
}
})
It then worked for me for JsBrowser, but for JsNode I had to also set in build.gradle(.kts)
:
kotlin {
js(IR) {
nodejs {
testTask {
useMocha {
timeout = "9s"
}
}
}
}
// ...
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论