根据环境禁用Jasmine的fdescribe()和fit()

fdescribe()fit()对于减less工作在testing子集上的噪音非常fdescribe() 。 我有时忘记把它们改回来describe() / it()然后再把我的分支合并到master中。 (在编写代码的时候可以把它们放在单独的分支里,也就是说,预先提交的检查对我来说是行不通的。)

我的CI环境是Codeship。 有没有解决这个问题,如果遇到任何重点方法将会在Codeship中的testing失败?

使用像没有专注的testing就可以了。 任何想法如何启用这个规则Codeship中的错误,并在本地禁用它?

使用像没有专注的testing就可以了。 任何想法如何启用这个规则Codeship中的错误,并在本地禁用它?

您可以使用环境variables的组合并重新定义fdescribe / fit全局函数:

  1. npm i --save cross-env

  2. 的package.json:

     "scripts": { "test": "jasmine", "test-safe": "cross-env FOCUSED_TESTS=off jasmine" }, 
  3. disableFocusedTestsIfNecessary.js( jasmine定义其全局variables包含):

     if (process.env.FOCUSED_TESTS === "off") { console.log("Focused tests must be off"); global.fdescribe = global.fit = function() { throw new Error("fdescribe and fit are disabled in this environment"); }; } else { console.log("Focused tests enabled"); } 
  4. 告诉codeship运行npm run test-safe而不是npm run test

对于那些有兴趣的,如果你使用茉莉花和eslint,你可以使用这个插件,以确保没有重点testing: https : //github.com/tlvince/eslint-plugin-jasmine 。

  1. 首先安装eslint全局npm install -g eslint
  2. 然后安装eslint-plugin-jasmine库npm install --save-dev eslint-plugin-jasmine
  3. 创build一个.eslintrc文件:

     { "rules": { "semi": 2 }, "plugins": ["jasmine"], "env": { "jasmine": true }, "extends": "plugin:jasmine/recommended", } 
  4. 然后,您就可以运行eslint -c ./.eslintrc app.js