dont-break

授权协议 Readme
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 麻鸿熙
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

dont-break

Checks if the node module in the current folder breaks unit tests for specified dependent projects.

Relevant discussion at npm,Do not break dependant modules.

Install

npm install -g dont-break

Use

  • Create .dont-break.json file in the root of your package,list module names that you would like to test as an array.
  • Run dont-break any time to test latest version of each dependent moduleagainst the curent code

Example

2 projects.

  1. First project foo only exports single variable module.exports = 'foo';
  2. Second project foo-user depends on foo.

foo-user only works if it gets string foo from the module it depends on, like this:

var str = require('foo');
console.assert(str === 'foo', 'value of foo should be "foo", but is ' + str);

foo has only a single release 0.1.0 that works for foo-user project.

The author of foo changes code to be module.exports = 'bar'; and releases it as 0.2.0.foo-user wants to use the latest foo so it updates its dependency, not expecting anythingbad - foo's minor version number has been upgraded. In semantic versioning it means no breaking APIchanges.

foo-user is now broken!

Instead, before publishing new version to NPM, project foo can create a file in itsproject folder .dont-break.json with names of dependent projects to test

echo '["foo-user"]' > .dont-break.json

You can check if the current code breaks listed dependent project by running

dont-break

This will install each dependent project from .dont-break.json file into /tmp/dont-break... folder,will run the dependent's unit tests using npm test to make sure they work initially, thenwill copy the current project into the temp folder, overwriting the previous working version.Then it will run the tests again, throwing an exception if they stopped working.

In the example case, it will report something like this

$ dont-break
dependents [ 'foo-user' ]
testing foo-user
  installing foo-user
installed into /tmp/foo@0.0.0-against-foo-user
  npm test
tests work in /tmp/foo@0.0.0-against-foo-user/lib/node_modules/foo-user
copied /Users/gleb/git/foo/* to /tmp/foo@0.0.0-against-foo-user/lib/node_modules/foo-user/node_modules/foo
  npm test
npm test returned 1
test errors:
AssertionError: value of foo should be "foo", but is bar
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0
tests did not work in /tmp/foo@0.0.0-against-foo-user/lib/node_modules/foo-user
code 1
FAIL: Current version break dependents

The message clearly tells you that the dependent projects as they are right now cannotupgrade to the version you are about to release.

Dependencies

You can specify GitHub repos as dependencies, because they most likely willhave tests. For example in .dont-break.json

// you can use JavaScript comments in this file .dont-break.json
[
  "https://github.com/bahmutov/dont-break-bar"
]

Picking projects to test manually is a judgement call.Dont-break can fetch top N most downloadedor most starred dependent modules and save the list.

  • run dont-break --top-downloads <N> to find top N most downloaded dependent modules,save to .dont-break.json and check.
  • run dont-break --top-starred <N> to find top N most starred dependent modules,save to .dont-break.json and check.

The above commands overwrite .dont-break.json file.

Configuration options

Global vs. project-level configuration

You can specify different configuration options on global level or on project level. Following configs are equivalent.Project level:

[
  {
    "name": "project-a",
    "test": "grunt test"
  },
  {
    "name": "https://github.com/bahmutov/dont-break-bar",
    "test": "grunt test"
  },
  {
    "name": "project-c",
    "test": "npm test:special"
  }
]

Global level:

{
  "test": "grunt test",
  "projects": [
    "project-a", 
    "https://github.com/bahmutov/dont-break-bar", 
    {
      "name": "project-c",
      "test": "npm test:special"
    }
  ]
}

Global level will simplify dont-break config if dependent projects share the same options. Also, options can beoverriden on project level as in case of "project-c" here.

Execution flow overview

Dont-break performs folowing steps for each dependent project:

Sections below describe how you can customize these steps.

Name

Serves to identify the dependent module by either a NPM module name (possibly with scope and version range) or Github URL.

[
  {
    "name": "foo-module-name"
  }, {
    "name": "@my-scope/bar-module-name@^1.0.1-pre.1"
  }, {
    "name": "https://github.com/bahmutov/dont-break-bar"
  }
]

The above config is equivalent to its shorter version:

[
  "foo-module-name", "@my-scope/bar-module-name@^1.0.1-pre.1", "https://github.com/bahmutov/dont-break-bar"
]

Test command

You can specify a custom test command per dependent module. For example, to run grunt test for foo-module-name,but default command for module bar-name, list in .dont-break.json the following:

[
  {
    "name": "foo-module-name",
    "test": "grunt test"
  },
  "bar-name"
]

Install command

You can specify a custom install command per dependent module. By default it's npm install. For example, this will useyarn add for foo-module-name, but keep default npm install for module bar-name:

[
  {
    "name": "foo-module-name",
    "install": "yarn add"
  },
  "bar-name"
]

The name of dependent module will be added to given command, e.g. for above it will run yarn add foo-module-name.

Post-install command

Before testing the dependent package dont-break installs its dev dependencies via npm install command run from thedependency directory. If you need something more you can specify it via "postinstall" config parameter like this:

[
  {
    "name": "packageA",
    "postinstall": "npm run update"
  }, {
    "name": "packageB"
  }
]

If specified this command will run first before pretesting the old version of lib (if pretest isn't disabled), thenafter installing current version of lib to dependent package. You can use $CURRENT_MODULE_DIR variable here whichwill be replaced with a path to current module:

[
  {
    "name": "packageA",
    "postinstall": "$CURRENT_MODULE_DIR/install-all-deps.sh",
  }
]

Pre-testing with previous package version

By default dont-break first tests dependent module with its published version of current module, to make sure that itwas working before the update. If this sounds excessive to you you can disable it with {"pretest": false} option:

[
  {
    "name": "foo-module-name",
    "test": "grunt test",
    "pretest": false
  }
]

Here "foo-module-name" module will be tested only once, and "bar-name" twise: first with its published version ofcurrent module, and then with the updated version.

The "pretest" property can also accept custom script to run for pretesting:

[
  {
    "name": "foo-module-name",
    "test": "grunt test",
    "pretest": "grunt test && ./ci/after-pretesting-by-dont-break"
  }
]

By default it equals to "test" command.

Current module installation method

To test dependent package dont-break installs current module inside the dependent package directory. By default it usesnpm install $CURRENT_MODULE_DIR. You can enter your command there, e.g. yarn add $CURRENT_MODULE_DIR. There arealso pre-configured options npm-link andyarn-link. They can be helpful in some cases, e.g. if you need to usenpm install or yarn in postinstall command. To use npm link method specify {"currentModuleInstall": "npm-link"}:

{
  "currentModuleInstall": "npm-link",
  "projects": ["packageA", "packageB"]
}

Env vars exported to called scripts

Following env vars are available for use in scripts called by executed steps:

  • $CURRENT_MODULE_DIR - directory of current module
  • $CURRENT_MODULE_NAME - name of current module as stated in its package.json

Installation timeout

You can specify a longer installation time out, in seconds, using CLI option

dont-break --timeout 30

Related

dont-break is the opposite of next-updatethat one can use to safely upgrade dependencies.

Setting up second CI for dont-break

I prefer to use a separate CI service specifically to test the current codeagainst the dependent projects using dont-break. For example, the projectboggle is setup this way. The unit testsare run on TravisCI usingpretty standard .travis.yml file

language: node_js
node_js:
  - "0.12"
  - "4"
branches:
  only:
    - master
before_script:
  - npm install -g grunt-cli

Then I setup a separate build service on CircleCijust to run the npm run dont-break command from the package.json

"scripts": {
    "dont-break": "dont-break --timeout 30"
}

We are assuming a global installation of dont-break, and the project liststhe projects to check in the.dont-break file.At the present there is only a single dependent projectboggle-connect.

To run dont-break on CircleCI, I created thecircle.yml file.It should be clear what it does - installs dont-break, and runs the npm script command.

machine:
  node:
    version: "0.12"
dependencies:
  post:
    - npm install -g dont-break
test:
  override:
    - npm run dont-break

To make the status visible, I included the CircleCI badges in the README file.

[![Dont-break][circle-ci-image] ][circle-ci-url]
[circle-ci-image]: https://circleci.com/gh/bahmutov/boggle.svg?style=svg
[circle-ci-url]: https://circleci.com/gh/bahmutov/boggle

which produces the following:

Breaking dependencies? usingdont-break

Development and testing

This project is tested end to end using two small projects:boggle and its dependentboggle-connect.

To see open github issues, use command npm run issues

To see verbose log message, run with DEBUG=dont-break ... environmentvariable.

Small print

Author: Gleb Bahmutov © 2014

License: MIT - do anything with the code, but don't blame me if it does not work.

Spread the word: tweet, star on github, etc.

Support: if you find any problems with this module, email / tweet /open issue on Github

Implemented using npm-registry,lazy-ass and npm-utils.

MIT License

Copyright (c) 2014 Gleb Bahmutov

Permission is hereby granted, free of charge, to any personobtaining a copy of this software and associated documentationfiles (the "Software"), to deal in the Software withoutrestriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom theSoftware is furnished to do so, subject to the followingconditions:

The above copyright notice and this permission notice shall beincluded in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIESOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISINGFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.

  • package com.zhao.struct; public class BreakDemo { public static void main(String[] args) { int i = 0; while (i<100){ i++; System.out.println(i);

  • source linke: https://lifehacker.com/281626/jerry-seinfelds-productivity-secret Editor: When software developer Brad Isaac told us he had productivity advice from Jerry Seinfeld, we couldn’t turn down

  • break作用(在 switch 或 loop外部中断): 1.break用于switch语句的作用是结束一个switch语句。 2.break用于循环语句中的作用是结束当前所在的循环语句。 笔试题目:break目前位于内层的for循环,如何才能让break作用于外层的for循环,可以 标记 解决(标记的命名只要符合标识符的命名规则即可) 使用细节: 不要再break语句之后,编写其他语句,永远都

  • 突然想到一句话: “每天清晨,你都会离开我;每天黄昏,我都会把你追回来,就这样,一天一天爱下去……”

  • while True: axis=input('你是哪里人: ') word=input('Enter string to capitalize[type q to quit]') if word =='q': break print(word) while True: value = input('请输入偶数,输入q 退出:') if value == 'q': break number =in

  • do while break do while(false) + break 可以模拟 goto语句,遇到break直接跳转。 @RequestMapping ("/add") @ResponseBody @Override public Map<String, Serializable> addComment(Comment comment, String token)

  • PB这个片子还是很看滴,监狱体裁一直受大众喜爱.第二季出来啦,也要仔细看看啦. 十一过的很充实啦,给自己的时间不多啦,下次争取能远行一次. 下面给出整理的PB介绍和我的人物介绍:) 【介绍】  名    称:prison break 类    型:监狱、逃亡、剧情、犯罪、惊怵、淡爱情 播出单位:fox 导   演:brett ratner 当    前:season.2 播出时间:星期一 官方网站

  • break     语句用于终止最近的封闭循环或它所在的 switch 语句。               控制传递给终止语句后面的语句(如果有的话)。 continue 语句将控制权传递给它所在的封闭迭代语句的下一次迭代。 goto      语句将程序控制直接传递给标记语句。              goto 的一个通常用法是将控制传递给                       特定的

  • // break 在循环中的功能测试 # include <stdio.h> int main(void) {  int i, j;  for (i = 0; i<3; ++i)  {   j = i;   break;   printf("HHH\n");  }  printf("%d", j);    return 0;    }    /*     运行结果:      0   ------

  • package year2014.round2 import scala.io.Source object DontBreakTheNile extends App { val file = "src/scala/codejam/year2014/round2/C-small-practice.in" val lines = Source.fromFile(file).getLin

  • 目录 一、break语句和continue语句 1.break 语句 2.continue语句 二、goto语句 一、break语句和continue语句 有时,需要在循环体中提前跳出循环,或者在满足某种条件下,不执行循环中剩下的违句而立即从头开始新的一轮循环,这时就要用到 break 和 continue 语句。 1.break 语句 在前面学习 switch 语句时,已经接触到 break语句

  • 举个例子吧: ....... sum = 0 for(i = 0;i < 10; ++i) { if(i == 4) break; if(i == 2) continue; sum += i; } ....... 结果为:sum 为 0+1+3=4 循环计算累加和,放在sum中 过程如下:i从0开始循环,每次i++。当i == 2的时候,执行continue,跳过sum += i这句,继续循环,也

  • break在任何循环语句的主体部分,均可用break控制循环的流程。break用于强行退出循环,不执行循环中剩余的语句。(break语句也在switch语句中使用) continue语句用在循环语句体中,用于终止某次循环过程,即跳过循环体中尚未执行的语句,接着进行下一次是否执行循环的判定。 关于goto关键字 (1) goto关键字很早就在程序设计语言中出现。尽管goto仍是Java的一个保留字,

  • break、Continue、goto的用法 break:(之前在Swictch里就用过),就是跳出循环,但是不会影响到整个程序的执行,程序再跳出循环之后还是会继续执行。 int i = 0; while (i<100){ i++; System.out.println(i); if (i==30){ break;//跳出循环,但是不会影响程序继续执行

  • break 语句 break 在语法上只会出现于 for 或 while 循环所嵌套的代码。 它会终结最近的外层循环,如果循环有可选的 else 子句,也会跳过该子句。 如果一个 for 循环被 break 所终结,该循环的控制变量会保持其当前值。 当 break 将控制流传出一个带有 finally 子句的 try 语句时,该 finally 子句会先被执行然后再真正离开该循环。 for i i

 相关资料
  • You Don't Need GUI 中文版请看这里 It's for noobs :) Graphical user interfaces are super friendly to computer users. They were introduced in reaction to the perceived steep learning curve of command-line inte

  • You Don't Need JavaScript Please note these demos should be considered as CSS "Proofs of Concepts". They may have serious issues from accessibility point of view (keyboard navigation, speech synthesis

  • 问题内容: 很难说出这里的要求。这个问题是模棱两可的,模糊的,不完整的,过于广泛的或修辞性的,不能以目前的形式合理地回答。如需帮助澄清此问题以便可以重新打开, 请访问帮助中心。 8年前关闭。 有哪些DO和DONT使用索引来提高数据库性能? DO应该是应该创建索引的情况,或者是与索引相关的,可以提高性能的技巧。 当不应该创建索引或其他可能影响性能的索引相关操作时,就不要使用DONT了。 问题答案:

  • 问题内容: 假设我有这个: 问题: break语句会将我带出两个循环还是仅从内部循环带出?谢谢。 问题答案: 在您的示例中,break语句将使您退出while(b)循环

  • 问题内容: 我正在寻找一种合适且健壮的方法来查找和替换独立于任何OS平台的所有或char 。 这是我尝试过的,但效果并不理想。 例: 输入字符串: 预期的输出字符串: 但是,它返回了相同的输入String。像这样放置\ n并再次将其解释为换行符。请注意,如果您想知道为什么有人要在那里,这是用户的特殊要求,需要将String放在XML后缀中。 问题答案: 如果您想使用文字,则应执行以下操作:

  • 问题内容: 我已经在Jquery中完成了此操作,但希望在Javascript中实现而不依赖任何库。 问题答案: 以下代码应该执行与您的函数完全相同的操作。 不过,我要指出的是,如果是包裹在任何元素,你只得到的的该元素,因此,如果它是一个简单的标签,你会只换行文本节点内与(那是什么,顺便说一下? )。 你也有一个bug,你是分配text到node.textContent ? node.textCon