简体   繁体   English

ember-cli从in-repo插件运行测试

[英]ember-cli run tests from in-repo addons

I have an ember-cli project with some addons created with ember generate in-repo-addon foo 我有一个ember-cli项目,其中一些插件使用ember generate in-repo-addon foo

When I run ember serve , ember-cli serves up my addon assets by combining /app and /lib/foo/app into /dist/assets/app.js . 当我运行ember serve ,ember-cli通过将/app/lib/foo/app/dist/assets/app.js提供我的插件资产。

I expected something similar to happen with tests. 我期望测试会发生类似的事情。 When I run ember test or browse to http://localhost:4200/tests , I only see generated JSHint tests for the main app. 当我运行ember test或浏览到http://localhost:4200/tests ,我只看到为主应用程序生成的JSHint测试。 Anything I create in /lib/foo/tests is ignored. 我在/lib/foo/tests创建的任何内容都将被忽略。

Where do I create tests for the addon, and how do I run them? 我在哪里为插件创建测试,以及如何运行它们?

There is a feature of Ember-CLI that isn't well documented (good luck finding it) that I used for our in-repo-addon which involves adding a 'test-support' folder to your addon. 有一个Ember-CLI的功能没有很好地记录(祝你好运找到它)我用于我们的in-repo-addon,其中包括在你的插件中添加一个'test-support'文件夹。

In your case you could do something like this in your addon 在你的情况下,你可以在你的插件中做这样的事情

foo
|-- test-support
    |-- helpers
    |   |-- common-helper.js
    |   |-- anther-common-helper.js
    |-- unit
        |-- models
            |-- user-test.js

I'm using something very similar with no issues at all. 我使用的东西非常相似,没有任何问题。 This has save a bunch of time for us, hope this helps 这为我们节省了很多时间,希望这会有所帮助

If you use the ember generator to create your tests in the addon you'll see where the files get created - it's the same file-structure as in a regular ember-cli project: 如果您使用ember生成器在插件中创建测试,您将看到文件的创建位置 - 它与常规ember-cli项目中的文件结构相同:

my-addon
|-- tests
    |-- integration
        |-- my-integration-test

You also run the tests for the addon the same way you would for a regular ember-cli project using ember test or starting an ember server within your addon's root directory and navigating to http://localhost:4200/tests . 您还可以像使用ember test的常规ember-cli项目一样运行插件的ember test或者在插件的根目录中启动一个ember服务器并导航到http://localhost:4200/tests

The addon creates a dummy app to host your addon for tests. 插件创建了一个虚拟应用程序来托管您的插件以进行测试。 You can find out more on the official Ember-cli documentation: http://www.ember-cli.com/extending/#testing-the-addon-with-qunit 您可以在官方Ember-cli文档中找到更多信息: http//www.ember-cli.com/extending/#testing-the-addon-with-qunit

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

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