如何在IntelliJ IDEA 13(或WebStorm)上远程运行mocha测试? [英] How can I run mocha tests remotely on IntelliJ IDEA 13 (or WebStorm)?

查看:566
本文介绍了如何在IntelliJ IDEA 13(或WebStorm)上远程运行mocha测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IntelliJ IDEA 13通过Node.js插件为Mocha测试提供了非常出色的支持: https://www.jetbrains.com/idea/webhelp/running-mocha-unit-tests.html

IntelliJ IDEA 13 has really excellent support for Mocha tests through the Node.js plugin: https://www.jetbrains.com/idea/webhelp/running-mocha-unit-tests.html

问题是当我在本地机器上编辑代码时,我有一个VM(流浪者),我在其中运行并测试代码,因此它尽可能像生产一样。

The problem is, while I edit code on my local machine, I have a VM (vagrant) in which I run and test the code, so it's as production-like as possible.

我写了一个小的bash脚本,每当我从IntelliJ中调用Run时,在这个VM上远程运行我的测试,并且结果在控制台中弹出得足够好,但是我喜欢使用Mocha时出现的优秀界面调用测试运行器。

I wrote a small bash script to run my tests remotely on this VM whenever I invoke "Run" from within IntelliJ, and the results pop up in the console well enough, however I'd love to use the excellent interface that appears whenever the Mocha test runner is invoked.

任何想法?

推荐答案

更新:现在有更好的方法可以做到这一点。请参阅 https://github.com/TechnologyAdvice/fake-mocha

Update: There's a much better way to do this now. See https://github.com/TechnologyAdvice/fake-mocha

成功!!

以下是我的表现方式。这特定于连接回流浪者,但可以针对任何具有基于密钥的SSH权限的远程服务器进行调整。

Here's how I did it. This is specific to connecting back to vagrant, but can be tweaked for any remote server to which you have key-based SSH privileges.


  1. 某处在您的远程计算机上,甚至在您的代码库中,存储NodeJS插件的mocha报告器(撰写本文时为6.js文件)。这些可以在主IntelliJ配置文件夹下的 NodeJS / js / mocha 中找到,在OSX上是〜/ Library / Application Support / IntelliJIdea13 。了解放置它们的绝对路径。

  2. 编辑运行配置

  3. 使用Mocha添加新的

  4. 将节点解释器设置为ssh可执行文件的完整路径。在我的机器上,它是 / usr / bin / ssh

  5. 将节点选项设置为此庞然大物,根据需要进行调整你自己的配置:
    -i /Users/USERNAME/.vagrant.d/insecure_private_key vagrant @ MACHINE_IPcd / vagrant; node_modules / mocha / bin / _mocha --recursive --timeout 2000 - -ui bdd --reporter /vagrant/tools/mocha_intellij/mochaIntellijReporter.js test#

    记住!最后的是重要的,因为它将取消Mocha运行配置添加到此命令的所有其他内容。另外,请记住在我所拥有的地方使用绝对路径。

  6. 将工作目录,Mocha包和测试目录设置为它们应该是什么样的在本地运行mocha测试。这些不会影响测试执行,但是这个界面会检查以确保它们是有效的路径。

  7. 命名,保存并运行!

  1. Somewhere on your remote machine, or even within your codebase, store the NodeJS plugin's mocha reporter (6 .js files at the time of this writing). These are found in NodeJS/js/mocha under your main IntelliJ config folder, which on OSX is ~/Library/Application Support/IntelliJIdea13. Know the absolute path to where you put them.
  2. Edit your 'Run Configurations'
  3. Add a new one using 'Mocha'
  4. Set 'Node interpreter' to the full path to your ssh executable. On my machine, it's /usr/bin/ssh.
  5. Set the 'Node options' to this behemoth, tweaking as necessary for your own configuration: -i /Users/USERNAME/.vagrant.d/insecure_private_key vagrant@MACHINE_IP "cd /vagrant; node_modules/mocha/bin/_mocha --recursive --timeout 2000 --ui bdd --reporter /vagrant/tools/mocha_intellij/mochaIntellijReporter.js test" # REMEMBER! The # at the end is IMPORTANT, as it will cancel out everything else the Mocha run config adds to this command. Also, remember to use an absolute path everywhere that I have one.
  6. Set 'Working directory', 'Mocha package', and 'Test directory' to exactly what they should be if you were running mocha tests locally. These will not impact the test execution, but this interface WILL check to make sure these are valid paths.
  7. Name it, save, and run!

完全集成的远程测试幸福。

Fully integrated, remote testing bliss.

这篇关于如何在IntelliJ IDEA 13(或WebStorm)上远程运行mocha测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆