开发Discourse插件——第6部分——添加验收测试

LOAD_PLUGINS=1 QUNIT_SKIP_CORE=1 QUNIT_SINGLE_PLUGIN='discouse-humble-box' /home/ravenstorm/.rbenv/versions/2.5.3/bin/rake qunit:test
Chrome is not installed. Download from https://www.google.com/chrome/browser/desktop/index.html
rake aborted!
Command failed with status (1): [LOAD_PLUGINS=1 QUNIT_SKIP_CORE=1 QUNIT_SIN...]
/home/ravenstorm/discourse/lib/tasks/plugin.rake:117:in `block in <main>'
Tasks: TOP => plugin:qunit
1 个赞

Install Chrome and then give it another try.

1 个赞

Oh sorry i’ve pasted an old error code which i had stored in a pastebin :frowning_face:

navigate to http://localhost:60099/qunit?qunit_single_plugin=discouse-humble-box&qunit_skip_core=1&seed=187998423095278311109560784485973475676
Tests timed out
rake aborted!
Command failed with status (124): [node /home/ravenstorm/discourse/vendor/ass...]
/home/ravenstorm/discourse/lib/tasks/qunit.rake:89:in `block in <main>'
Tasks: TOP => qunit:test
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [LOAD_PLUGINS=1 QUNIT_SKIP_CORE=1 QUNIT_SIN...]
/home/ravenstorm/discourse/lib/tasks/plugin.rake:117:in `block in <main>'
Tasks: TOP => plugin:qunit

Try running the test in the browser as David suggested earlier. So, in your browser, when the server is running, go to your-local-site/qunit. Very often, for me, timeouts in the Terminal have errors in JS that I could see and fix after visiting /qunit on the browser.

Thats one of the problems :smiley:

I can’t find acceptance tests on my /qunit

Even after turning on all modules and filtering it with box and humble nothing is here :slightly_frowning_face:

Try renaming the folder to test/javascripts/acceptance - that extra s is quite important!

https://github.com/discourse/discourse/blob/cd0403174dd88b0d1619ee7a53b42bc600bd69d1/lib/plugin/instance.rb#L463

You might need to do rm -rf tmp, and then restart your development server for the changes to take effect.

1 个赞

Do what David said above (rename the folder to javascripts), but ALSO, change the name of your plugin in plugin.rb to discourse-humble-box to match the folder name. I did these two changes, and I see tests locally:

4 个赞

Yea i’ve seen those as well now, but these aren’t really eye-opening results tbh.

But gotta dig deeper and lookup why these errors are shown.

Thanks for the help guys.
For example the second test case… if i am testing it myself by hand… it works, but running it on qunit it fails :frowning:

Ok, got a brief idea whats bringing me the errors and it confuses me:
http://localhost:9292/ in my browser has the plugin installed and working
http://localhost:9292/qunit the test shows, that the plugin is not even installed

I thought these two are using the same enviroment ?
Could this be caused by my local dev-enviroment since it’s not using docker and I’m not able to install the plugin like Install Plugins in Discourse ? It’s just sitting in the plugins folder like the others.

Any idea how this is possible ?

我正在尝试遵循本指南,但在开始时就遇到了困难:我根本无法访问 /qunit。(这似乎也与 Install Discourse on Ubuntu or Debian for Development 相关,我基本上是采用这种方法在本地计算机上部署 Discourse 以学习开发,但本指南是触发我障碍的提示,所以我想把它放在这里。)尝试访问它会得到“该页面不存在或已私密”的响应。

/qunit 路由的控制器 (discourse/app/controllers/qunit_controller.rb at 166fe3bb34f99bd0baa613726486ce0f13c7a992 · discourse/discourse · GitHub) 提到它“仅用于非 ember-cli 测试/开发”(该方法之前的注释),因此我尝试使用 RAILS_ENV=test bundle exec rails server 运行实例,但 EmberCli.enabled? 仍然是 true

你们使用什么方法来运行本地开发服务器,以便我们能够实际访问 /qunit(这可能涉及禁用 EmberCLI)?(我肯定可能忽略了一些显而易见的东西。)

2 个赞

新路径是 /tests。我将更新 OP - 谢谢!

4 个赞

太好了,谢谢!下一个障碍:

这个直接指向特定验收测试的链接会报错(并附有堆栈跟踪):

Error: No tests matched the module "Acceptance: Purple Tentacle".

确实,当我通过“Module:”选择列表搜索时,我没有看到任何与“purple”或“Purple”匹配的内容。系统是否有新的部分用于注册插件或它们的测试,而这里可能遗漏了?

如果我使用“Filter:”文本框搜索“purple”,它会带我到以下 URL:http://localhost:4200/tests?filter=purple,这会给我另一个错误:

Error: Could not find module `helpers/qunit-helpers` imported from `discourse/plugins//acceptance/purple-tentacle-test`
    at missingModule (http://localhost:4200/assets/vendor.js:259:11)

您有什么关于哪里可能出错的想法吗?

顺便问一下,/tests URL 是否使用了“catch-all” get \"*url\", to: 'permalinks#show' 路由,因此使用 Permalink.find_by_url 来实际解析?如果是这样,/tests URL 映射是在 Discourse 初始化过程的哪个阶段加载到数据库中的?

@jlc,非常感谢您试用我们的指南并及时向我们更新信息。:meow_heart:

我对 OP 的示例验收测试进行了一些更改,以反映我们为验收测试使用的一些新更改。本质上,这两个更改是:

  • 导入,以及
  • acceptance 中使用 needs 常量

这应该可以解决您提到的大部分问题。您还可以利用此处的一些 needs 选项:

通读整个 qunit-helpers 文件也会非常有帮助!

1 个赞