Giter VIP home page Giter VIP logo

ember-fastboot-app-tests's Introduction

Unmaintained

This addon is considered deprecated and unmaintained. We would recommend other testing solution, like ember-cli-fastboot-testing instead!

ember-fastboot-app-tests

npm version Build Status Ember Observer Score Greenkeeper badge

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-fastboot, and then runs your Mocha-based end-to-end tests to assert that your app works as expected in a FastBoot environment.

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

Installation

ember install ember-fastboot-app-tests

After installing the addon you should find a new folder fastboot-tests which will hold your test files. The default blueprint will have installed a first simple test to start with.

Testing principles

Before we get our hands dirty let's make some important things clear first! Because there are some significant differences between 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 your app/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 FastBoot server runs your app, but you can only access that through FastBoot's HTTP server. Your test itself runs in a node.js environment, not a browser! You can send a HTTP GET request 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 black box, and you have no information about what is happening inside it, except for the HTML it returns. So no import, no document, no DOM, no jQuery (ok, wait, I might be proven wrong there!).

Testing basics

A test file generated by this addon will look like this:

const expect = require('chai').expect;

describe('index', function() {

  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);
      });
  });

});

This Mocha test file defines a simple test that asserts that your app's index route returns the expected HTML that the default index.hbs defines. Although this might seem not worth testing at first sight, your app still can easily break that, e.g. by importing some external JavaScript that can only run on a browser or accessing the DOM in a component from within init.

You may wonder here where all the necessary bootstrap code is, for building the app and spinning up the FastBoot server. The good 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 is added 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 no DOM 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 it with the visit helper in an acceptance test) to make a request to. It then makes a HTTP request to your FastBoot server for that route, and returns a Promise. If the request was successfull, it resolves 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 - a kind 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.

Adding tests

Besides the already generated test file for you index route, adding a new route is easy:

ember g fastboot-test foo

This will add a foo-test.js file with the boilerplate for your new test.

Running your tests

ember fastboot:test

This will run all your FastBoot tests.

Contributions

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

Authors

Simon Ihmig @simonihmig

ember-fastboot-app-tests's People

Contributors

dajk avatar ember-tomster avatar greenkeeper[bot] avatar simonihmig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ember-fastboot-app-tests's Issues

An in-range update of eslint-plugin-ember is breaking the build 🚨

The devDependency eslint-plugin-ember was updated from 5.2.0 to 5.3.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-ember is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of chalk is breaking the build 🚨

The dependency chalk was updated from 2.4.1 to 2.4.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

chalk is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v2.4.2

This release is done from the v2-release branch, as master branch targets the work-in-progress v3 release.

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Allow passing through --host option

I want to be able to do ember fastboot:test --host localhost. Currently, it uses whatever is configured in the .ember-cli file.

Looks like a couple things need to happen:

  1. host needs to be added to available options here
  2. host needs to be passed into app.startServer() here
  3. ember-cli-addon-tests needs to use that host config when starting the ember server here

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of ember-cli-sri is breaking the build 🚨

The devDependency ember-cli-sri was updated from 2.1.0 to 2.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ember-cli-sri is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 4 commits.

  • 25a6506 release v2.1.1
  • 11eb96d Merge pull request #27 from alobaidizt/whitelist-files
  • 1c7b65d Whitelist in package.json only required files
  • da9910f Merge pull request #22 from jonathanKingston/bump-version/2.1.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Simplify testing apps using HTTPS

I have an application that only accepts requests made over https. I wanted to test fastboot with this addon and, while possible, has a couple rough corners.

this.visit('/my/path') doesn't work because it default to http. It's ok, I think it's the right default, but looking at the code I found that you can use https if you use fully qualified urls:

this.visit('https://localhost:4200/my/url') This doesn't work because the addon uses a different port, that at the moment is hardcoded to 49741.

This is the first rough corner, because this using this hardcoded port feels brittle.

this.visit('https://localhost:49741/my/url') almost works, but chances are that if you are using https, you're using a self-signed certificate in development, which is not accepted by default in the request package used underneath. This is the second rough edge.

Finally, this approach does works: this.visit({ url: 'https://localhost:49741/my/path', strictSSL: false })

I leave this here to check if there could be a more amicable approach, or, at the very least, an entry in the docs.

Ideas:

this.visit('/my/path', { https: true }) // and accept self-signed certs by default.

New release

Can we have a new release with the deps updated by greenkeeper?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.