简体   繁体   English

travis-ci karma singleRun

[英]travis-ci karma singleRun

On my local machine I want npm test to watch files and re-test on change, so I use singleRun: false in karma.conf.js . 在我的本地计算机上,我希望npm test监视文件并重新测试更改,因此我在karma.conf.js使用singleRun: false

On travis-ci this causes a timeout error. 在travis-ci上,这将导致超时错误。 How do I override the singleRun option for travis-ci environment only? 如何仅在travis-ci环境中覆盖singleRun选项?

Given that the cli can also be used to enable/disable singleRun, adding "--no-single-run" to the karma cli run might override the config file... 鉴于cli也可用于启用/禁用singleRun,因此在业力cli运行中添加“ --no-single-run” 可能会覆盖配置文件...

Alternately, given the karma.conf.js is a Javascript file, can you write the setting of singleRun as a function (eg which detects one of the Travis environment variables) and spit out "false" or "true" appropriately? 或者,假设karma.conf.js是一个Javascript文件,您可以将singleRun的设置写为一个函数(例如,它检测到Travis环境变量之一)并适当地吐出“ false”或“ true”吗?

I use the following solution (inspired by @palfrey). 我使用以下解决方案(受@palfrey启发)。 Travis runs will have CI=true set as an environment variable. Travis运行会将CI=true设置为环境变量。

Use node's process.env function to set a local var to the value of CI (or false if unset), then use this as the value for singleRun in the config: 使用节点的process.env函数将局部变量设置为CI的值(如果未设置,则为false),然后将其用作配置中singleRun的值:

karma.conf.js karma.conf.js

const ci = process.env.CI || false

module.exports = function(config) {
  config.set({
    singleRun: ci,
    ...
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM