当前位置: 首页 > 软件库 > 程序开发 > >

ember-fastboot-addon-tests

Addon testing support for Fastboot compatibility
授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 宗政法
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

ember-fastboot-addon-tests

This is an ember-cli addon that makes testing your own addon for compatibility with FastBoot easy and straightforward!

It works by using ember-cli-addon-tests to create a (temporary) app thatconsumes your addon, builds it and spins up a local FastBoot server using ember-cli-fastboot,and then runs your Mocha-based end-to-end tests to assert that your addon works as expected or atleast does not break things up in a FastBoot environment.

Note that this is for Ember addons only. For testing apps you can use this related project: ember-fastboot-app-tests.

Installation

This addon depends on ember-cli-fastboot, so make sure you have it installed:

ember install ember-cli-fastboot 

Then, install the addon:

ember install ember-fastboot-addon-tests

Note that this addon needs at least node.js 4.x (mainly because of FastBoot itself).

After installing the addon you should find a new folder fastboot-tests which will hold your test files. The defaultblueprint will have installed some essential things there automatically, some "fixtures" for your temporary app and a firstsimple test.

Testing principles

Before we get our hands dirty let's make some important things clear first! Because there are some significant differencesbetween the FastBoot tests that this addon adds support for, and the usual Ember.js tests as you might know them.

Ember.js tests

The normal Ember.js tests, no matter whether these are unit, integration or acceptance tests, all run in the same browser(a real or a headless one like PhantomJS) and process as the actual code you test. So you can import any module from yourapp/addon, you have a DOM available (where your integration or acceptance tests render into), you have jQuery and so on.

FastBoot tests

Contrary to that for your FastBoot tests, your test and the code to test for run in two separate processes. The FastBootserver runs your (temporarily created) app (including the code from your addon like your components), but you can onlyaccess that through FastBoot's HTTP server. Your test itself also runs in a node.js environment, not a browser! You can send a HTTP GETrequest to your FastBoot server, and it gives you a response, that is some HTTP headers and basically a plain string of HTML.

So this is a real end to end test, like the tests you do with tools like Selenium/WebDriver. Your running app is a blackbox, and you have no information about what is happening inside it, except for the HTML it returns. So no import, nodocument, no DOM, no jQuery (ok, wait, I might be proven wrong there!).

Testing basics

Let's say your addon features a component, that you want to test for FastBoot compatibility. Using that component in an appmight break the app running under FastBoot, e.g. if you access the DOM (that does not exist in FastBoot) in a hook thatFastBoot will execute, like init (as opposed to didInsertElement which FastBoot will ignore). For detailed informationon how to make your code FastBoot compatible, please consult FastBoot's Addon Author Guide!

So our goal here is to create and run an app with FastBoot that uses our component, and make sure that it works as expected...

Fixtures

As said in the introduction, this addon will create a temporary app with the help of ember-cli-addon-tests. But this appwill just be a barebones Ember.js app as ember new would have created it. To add any custom code to, in this case probablya template that uses your component, so called fixtures are used. These are files in the fastboot-tests/fixtures folder.These files will get copied into the created app.

Upon first installation of this addon, two fixture files will already have been created for you:

  • app/router.js: the default router definition, to be able to amend that file later with additional routes
  • app/templates/index.hbs: a simple index template file

Tests

Together with those two fixtures files a simple test file to start with will have been created. It will look like this:

const expect = require('chai').expect;
const setupTest = require('ember-fastboot-addon-tests').setupTest;

describe('index', function() {
  setupTest('fastboot'/*, options */);

  it('renders', function() {
    return this.visit('/')
      .then(function(res) {
        let $ = res.jQuery;
        let response = res.response;

        // add your real tests here
        expect(response.statusCode).to.equal(200);
        expect($('body').length).to.equal(1);
        expect($('h1').text().trim()).to.equal('ember-fastboot-addon-tests');
      });
  });

});

This Mocha test file defines a simple test that asserts that your app's index route returns the expected HTML that thedefault index.hbs defines. Although this might seem not worth testing at first sight, your addon still can easily breakthat, e.g. by importing some external JavaScript that can only run on a browser.

You may wonder here where all the necessary bootstrap code is, for building the app and spinning up the FastBoot server. Thegood news is, you do not have to care about this, this addon takes care of this for you! All the setup and tear down code isadded to your test suite in some before and after Mocha hooks.

But you still may have stumbled upon the use of jQuery in the above test, although a chapter before it was said that you have noDOM and no jQuery available to your tests. This is where the visit helper comes into play...

The visit helper

This addon gives you a visit helper that makes testing pretty easy. You give it a route of your app (as you would do itwith the visit helper in an acceptance test) to make a request to. It then makes a HTTP request to your FastBoot serverfor that route, and returns a Promise. The Promise will resolve with a response object, which is a POJO with the following properties:

  • response: the node.js response (an instance of http.IncomingMessage).You can use that e.g. to check the HTTP headers received by accessing response.headers.
  • jQuery: although the tests run in node-land and have no real DOM available, with the help of jsdom - a JavaScript implementation of the DOM standard - akind of faked DOM is available that jQuery can operate upon. So you can express your DOM assertions in a way you are used to from normal Ember tests.

Instead of a simple URL, you can also supply an object to the visit helper with any options that requestwould accept. For example to check for a redirect response you can do this liek this:

describe('secure', function() {
  setupTest('fastboot'/*, options */);

  it('redirects /secure to /', function() {
    return this.visit({
      uri: '/secure',
      followRedirect: false
    })
      .then(function(res) {
        let response = res.response;

        expect(response.statusCode).to.equal(307);
        expect(response.headers.location).to.match(/^http:\/\/localhost:\d+\/);
      });
  });
});

Adding tests

Given the example that your addon features some components that you want to test, you should write separate routes (in your temporary FastBoot app) for each component to isolate the differentcomponents, as a failing component would break the whole render process. Adding a new route is easy:

ember g fastboot-test foo

This will add a new foo.hbs template file and register that route to your router.js (all in your fastboot-tests/fixtures/fastboot/app folder). So pretty similar to what ember g route foo would dofor a real app. And it would add a foo-test.js file with the boilerplate for your new test.

You could then add the component you want to test to your new template file, and add the DOM assertions to your test file, to check that your component will render as expected in a FastBoot environment!

If you have the need to setup different apps to test with, e.g. to add different configs to your config/environments.js,you can run the blueprint with the --app-name option:

ember g fastboot-test foo --app-name my-app

This will add a separate set of fixtures in fastboot-tests/fixtures/my-app/ and a test file that calls setupTestwith that app name to run this test against the my-app app.

You can find some simple real world testing examples in the ember-bootstrap repository.

Test options

The second parameter to the setupTest function allows you to set the following options:

  • installPackages: install additional packages to the app. Use a hash of package name and version specifier pairs,just as you would in the app's package.json
  • emberCliFastbootVersion: specify the version of ember-cli-fastboot that you wnat to test your addon with. Defaultsto 'latest'

Running your tests

ember fastboot:test

This will run all your FastBoot tests. Note that this will take some time, as creating the app, installing all its dependencies and starting the FastBoot server is a slow process!

You might want to add that command to your npm test script in your package.json, to run your FastBoot tests along your normal (ember-try) tests.

"scripts": {
    "start": "ember server",
    "build": "ember build",
    "test": "ember try:each && ember fastboot:test"
}

Specifying the Ember.js or Ember-Data version

By default the FastBoot app will be created with the same Ember.js version you have specified in your addon's bower.json. But you can override this with an additional option:

ember fastboot:test --ember-version <version> --ember-data-version <version>

You can use any version you would also specify in your bower.json, e.g. release or 2.4.0. Note that FastBoot itself requires at least Ember.js 2.4!

See ember help fastboot:test for additional options.

Debugging your test app

You can use the following command to serve your test app, e.g. to check your test selectors or how the fixtures behave:

 ember fastboot:serve

If you have other apps defined with other names as the default fastboot in your setupTest call, you can serve them as well:

ember fastboot:serve --app-name <app-name>

Working with ember-try

By default, addons use ember-try to run tests against multiple versions of dependencies simultaneously on Travis CI. This system can also be leveraged to run your FastBoot tests in parallel with your browser tests. It just takes two small changes:

1. Update your config/ember-try.js

Add a new entry to the file like so:

module.exports = [
+  {
+    name: 'fastboot-addon-tests',
+    command: 'ember fastboot:test',
+    bower: {
+      dependencies: { }
+    }
+  }
];

This will define a new ember-try task that runs your FastBoot tests

2. Update your .travis.yml config

The .travis.yml file in the root of the addon includes a list of ember-try tasks to run. Just add the new one to your list:

env:
+  - EMBER_TRY_SCENARIO=fastboot-addon-tests

Now, you'll get a separate Travis CI job that runs just the FastBoot tests. This way, all of your test runs are not slowed down by how long they take to run. As an added bonus, running ember try:each will now run your FastBoot tests as well.

To see this configuration in action, check out ember-steps.

What else?

ToDo

  • Feature to run tests with many different Ember versions (like ember-try)
  • Anything else?

Contributions

To make this addon useful for as many addon authors as possible, please contribute, by giving some feedback, submitting issues or pull requests!

Authors

Simon Ihmig @simonihmig

  • fastboot介绍 fastboot是uboot中用来快速下载镜像的一个命令,fastboot同时还是一个windows上的软件。 fastboot下载时要注意1:fastboot是使用USB线进行数据传输的,所以fastboot执行之前要先连接开发板和主机之间的usb线。 fastboot下载时要注意2:需要安装驱动。 fastboot常用命令: fastboot devices 命令用来查看

  • 参考:   http://blog.csdn.net/geniusmen/article/details/7892398   http://www.cnblogs.com/eastnapoleon/p/3270857.html   http://www.omappedia.org/wiki/Android_Fastboot#Updating_system_image_on_NAND fastboo

  • fastboot 卡在 waiting for device $ fastboot flash boot boot.img < waiting for device > 看看devices $ fastboot devices no permissions fastboot 唔…… $ sudo chown root:root /bin/fastboot $ sudo chmod +s /b

  • 转载来自:http://blog.csdn.net/ic_soc_arm_robin/article/details/16341625 1. 手机进入fastboot模式 先关机,开机时,同时按power键+camera或power + Home键,进入fastboot,红色字体 然后将手机和HOST,用USB线连接 2. 查看fastboot用法 $  sudo ./fastboot -h us

  • fastboot帮助文档 本文主要是对window版fastboot --help的中文翻译 C:\Users>fastboot --version fastboot version 32.0.0-8006631 Installed as C:\Users\fastboot.exe C:\Users>fastboot --help usage: fastboot [OPTION...] COMM

  • 注:这篇文章是在网上参考了众多大神的文章之后,结合自己的微末认知总结出来的。 fastboot之前一直不知道它是个什么东东,最近因为工作需要,实际的使用了一下,发现它有点类似于uboot的命令行。在uboot命令行,你可以对flash进行读写等操作,fastboot也可以实现类似的操作。 注:我的理解可能有点片面,欢迎大佬多多指正。 正文开始: 1、首先,我们怎么进入fastboot模式: 我的b

  • 分区解释: ramdisk.img,system.img,userdata.img以及它们对应的目录树root,system,data。 ramdisk.img是根文件系统,system.img包括了主要的包、库等文件,userdata.img包括了一些用户数据,android加载 这3个映像文件后,会把 system和 userdata分别加载到 ramdisk文件系统中的system和 dat

  •  1、检查开机log:      [    6.482185] EXT4-fs (mmcblk0p57): VFS: Can't find ext4 filesystem   2、adb shell mount     /dev/block/mmcblk0p57 on /metadata type ext4 (rw,seclabel,nosuid,nodev,noatime,discard)  

 相关资料
  • ember-fastboot-docker Dockerized Node.js server for running Ember FastBoot apps. Based on Ember FastBoot for AWS Elastic Beanstalk by @tomdale. Usage $ docker run \ --rm -it \ -p 8080:3000 \ -v $(p

  • ember-fastboot-app-tests This is an ember-cli addon that makes writing FastBoot tests for your Ember app easy and straightforward! It works by spinning up a local FastBoot server using ember-cli-fastb

  • ember-cli-addon-docs Compatibility Ember.js v3.20 or above Ember CLI v3.20 or above Node.js v12 or above 2/28/20 Update: AddonDocs is in Maintenace Mode. AddonDocs is still actively being used by many

  • ember-cli-deploy-fastboot-api-lambda An ambitious ember-cli-deploy plugin for serving Ember FastBoot Applications entirely from within AWS Lambda/API Gateway (assets and all!). Background API Gateway

  • Addon Domains是您帐户中托管的附加域,存储在子文件夹中。 系统将这些域视为系统的子域。 如果您想在同一主机方案下运行完全不同的网站,则可以使用cPanel的此功能。 这是在单个cPanel帐户上运行多个网站的最佳选择。 例如,您有一个托管博客网站,并且您想要一个不同的网站为您的简历,您不需要购买不同的托管帐户,但您可以使用相同的托管为您的简历网站。 要使用此功能,您需要从cPanel

  • Addon-sdk 即 Add-on SDK 开发包。使用它的话,你可以使用标准的网络技术(如:JavaScript, HTML, CSS)来创建火狐加载组件。这个 SDK 包括了 JavaScript APIs,允许你创建插件和工具用来运行、测试和加载开发工具。