简体   繁体   English

如何自动测试用户版本的npm软件包,而不是在持续集成上运行开发版本?

[英]How to automate testing user-version of npm package instead of running the development version on continious integration?

It happens occasionally that the development version of a module works in my development workspace and passes on Travis-CI but after publishing to npm it turns-out the end-user package is broken. 偶尔会出现模块的开发版本在我的开发工作区中运行并传递到Travis-CI上的情况,但是发布到npm后,结果证明最终用户软件包已损坏。

For example if you use a sub module that should be in dependencies but had it in devDependencies then CI will pass (but there are plenty other possible breakages). 例如,如果您使用应该在dependencies但在devDependencies的子模块,则CI将通过(但是还有很多其他可能的损坏)。

How do you automate testing this? 您如何自动化测试呢? Do you use external rigging? 您是否使用外部索具? Is there a secret module? 是否有秘密模块? Do you have a user acceptance test suite? 您有用户接受度测试套件吗?

I use Github with Travis-CI but the standard setup uses the development install. 我将Github与Travis-CI结合使用,但是标准设置使用开发安装。

Once upon a time I discovered that npm would let me publish packages that are uninstallable. 曾几何时,我发现npm将使我发布可卸载的软件包。 So I've added a target to my Gruntfile that does this: 因此,我将一个目标添加到我的Gruntfile ,以执行以下操作:

  1. Issue npm pack to create a package from my source. 发出npm pack以从我的源创建一个包。

  2. Into a directory created (automatically by my Gruntfile ) just for testing install the new package using npm install <path to the package created in the previous step> . 进入仅用于测试的目录(由我的Gruntfile自动创建),使用npm install <path to the package created in the previous step>安装新软件包。

I have a target for publishing a new version that will publish only if the steps above are successful. 我有一个发布新版本的目标,该版本只有在上述步骤成功后才能发布。

The steps above would not catch the dependency problem you mentioned in the question but they could easily be extended to catch it. 上面的步骤不能解决您在问题中提到的依赖问题,但是可以轻松地对其进行扩展以解决它。 To do this, I'd add one or more tests that cause the package installed in step 2 above to call require with all that it depends on. 为此,我将添加一个或多个测试,以使上面第2步中安装的软件包调用require及其所有依赖项。

I would suggest to set up your own CI server that does essentially one thing, npm install package ; cd node_modules/package ; npm test 我建议设置您自己的CI服务器,该服务器本质上做一件事, npm install package ; cd node_modules/package ; npm test npm install package ; cd node_modules/package ; npm test npm install package ; cd node_modules/package ; npm test . npm install package ; cd node_modules/package ; npm test This would ensure that your package is installable at least on your server. 这样可以确保您的软件包至少可以在服务器上安装。

I heard that Jenkins is good for this (at least, that's what node.js core team seems to be using), but don't have any first hand experience yet. 我听说Jenkins对此非常有帮助(至少,这就是node.js核心团队正在使用的东西),但是还没有任何直接的经验。 We're just planning to set in up in a couple of weeks. 我们正计划在几周内进行设置。

Also, having some external module that depends on you and testing it helps a bit. 另外,拥有一些依赖于您的外部模块并对其进行测试会有所帮助。 :) :)

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

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