Kotlin JavaScript Karma测试失败

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

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"
                }
            }
        }
    }

    // ...
}

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:

确定