Kotlin JavaScript Karma测试失败

huangapple go评论75阅读模式
英文:

Kotlin JavaScript Karma test fails

问题

在运行测试时出现以下错误:

  1. 错误:超过2000毫秒的超时。对于异步测试和挂钩,请确保调用“done()”;如果返回Promise,请确保它已解决。

build.gradle.kts

  1. js(IR) {
  2. useCommonJs()
  3. browser {
  4. testTask {
  5. useKarma {
  6. useChromeHeadless()
  7. }
  8. }
  9. }
  10. binaries.executable()
  11. }

karma.config.d/karma.conf.js中增加超时时间没有帮助:

  1. module.exports = function (config) {
  2. config.set({
  3. crossOriginAttribute: false,
  4. processKillTimeout: 90000,
  5. browserDisconnectTimeout: 90000,
  6. browserNoActivityTimeout: 90000,
  7. frameworks: ['mocha'],
  8. client: {
  9. timeout: "9s",
  10. mocha: {
  11. timeout: "9s",
  12. reporter: "spec",
  13. args: ['timeout', '9s']
  14. },
  15. }
  16. });
  17. };

我可以看到配置已合并到build/js/packages/project-name-test/karma.conf.js中,但似乎没有产生任何效果。

英文:

Getting the following error when running the test

  1. Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

build.gradle.kts

  1. js(IR) {
  2. useCommonJs()
  3. browser {
  4. testTask {
  5. useKarma {
  6. useChromeHeadless()
  7. }
  8. }
  9. }
  10. binaries.executable()
  11. }

Increasing timeouts in karma.config.d/karma.conf.js didn't help:

  1. module.exports = function (config) {
  2. config.set({
  3. crossOriginAttribute: false,
  4. processKillTimeout: 90000,
  5. browserDisconnectTimeout: 90000,
  6. browserNoActivityTimeout: 90000,
  7. frameworks: ['mocha'],
  8. client: {
  9. timeout: "9s",
  10. mocha: {
  11. timeout: "9s",
  12. reporter: "spec",
  13. args: ["timeout", "9s"]
  14. },
  15. }
  16. });
  17. };

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 的超时时间:

  1. config.set({
  2. client: {
  3. mocha: {
  4. timeout: 9000
  5. }
  6. }
  7. })

然后对于 JsBrowser,这对我有用,但对于 JsNode,我还需要在 build.gradle(.kts) 中设置:

  1. kotlin {
  2. js(IR) {
  3. nodejs {
  4. testTask {
  5. useMocha {
  6. timeout = "9s"
  7. }
  8. }
  9. }
  10. }
  11. // ...
  12. }
英文:

Use an integer instead of a string to specify Mocha's timeout:

  1. config.set({
  2. client: {
  3. mocha: {
  4. timeout: 9000
  5. }
  6. }
  7. })

It then worked for me for JsBrowser, but for JsNode I had to also set in build.gradle(.kts):

  1. kotlin {
  2. js(IR) {
  3. nodejs {
  4. testTask {
  5. useMocha {
  6. timeout = "9s"
  7. }
  8. }
  9. }
  10. }
  11. // ...
  12. }

huangapple
  • 本文由 发表于 2023年2月16日 19:29:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定