Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
test: add FastBoot test
Browse files Browse the repository at this point in the history
Related to #72
  • Loading branch information
alexlafroscia committed Jun 18, 2018
1 parent 2f58087 commit b96b65f
Show file tree
Hide file tree
Showing 15 changed files with 747 additions and 35 deletions.
15 changes: 13 additions & 2 deletions .eslintrc.js
Expand Up @@ -22,16 +22,23 @@ module.exports = {
rules: {
'prettier/prettier': 'error',

'ember/no-global-jquery': 'off',

'no-console': 'off'
},
overrides: [
// tests
{
env: {
mocha: true
},
files: [
'fastboot-tests/*-test.js',
'tests/**/*.js'
],
excludedFiles: [
'tests/dummy/**/*.js'
'tests/dummy/**/*.js',
'fastboot-tests/fixtures/**/*.js'
],
rules: {
'ember/avoid-leaking-state-in-ember-objects': 'off'
Expand All @@ -46,12 +53,15 @@ module.exports = {
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'fastboot-tests/*-test.js',
'fastboot-tests/helpers/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'addon/**',
'app/**',
'fastboot-tests/fixtures/**/*.js',
'tests/dummy/app/**'
],
parserOptions: {
Expand All @@ -65,6 +75,7 @@ module.exports = {
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
'node/no-unpublished-require': 'off'
})
}
]
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -31,6 +31,7 @@ env:
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=fastboot-addon-tests

matrix:
fast_finish: true
Expand Down
4 changes: 4 additions & 0 deletions config/ember-try.js
Expand Up @@ -90,6 +90,10 @@ module.exports = function() {
'ember-source': urls[2]
}
}
},
{
name: 'fastboot-addon-tests',
command: 'ember fastboot:test'
}
]
};
Expand Down
11 changes: 11 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/router.js
@@ -0,0 +1,11 @@
import EmberRouter from '@ember/routing/router';
import config from './config/environment';

const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {});

export default Router;
16 changes: 16 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/routes/index.js
@@ -0,0 +1,16 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';

export default Route.extend({
ajax: service(),

model() {
return get(this, 'ajax').request('http://localhost:3000/posts', {
dataType: 'json',
headers: {
'Content-Type': 'application/json'
}
});
}
});
@@ -0,0 +1 @@
{{outlet}}
7 changes: 7 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/templates/index.hbs
@@ -0,0 +1,7 @@
<ul>
{{#each model as |post|}}
<li>
{{post.title}}
</li>
{{/each}}
</ul>
12 changes: 12 additions & 0 deletions fastboot-tests/helpers/fixtures.js
@@ -0,0 +1,12 @@
var POSTS = [
{
title: 'First Post'
},
{
title: 'Second Post'
}
];

module.exports = {
POSTS
};
24 changes: 24 additions & 0 deletions fastboot-tests/helpers/server.js
@@ -0,0 +1,24 @@
var express = require('express');
var posts = require('./fixtures').POSTS;

var app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.header(
'Access-Control-Allow-Headers',
'Content-Type, Authorization, Content-Length, X-Requested-With'
);

if ('OPTIONS' === req.method) {
res.sendStatus(200);
} else {
next();
}
});

app.get('/posts', (req, res) => {
res.json(posts);
});

module.exports = app;
29 changes: 29 additions & 0 deletions fastboot-tests/index-test.js
@@ -0,0 +1,29 @@
'use strict';

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

var expressApp = require('./helpers/server');
var POSTS = require('./helpers/fixtures').POSTS;

describe('ember-ajax', function() {
setupTest('fastboot' /*, options */);

beforeEach(function() {
this.server = expressApp.listen(3000);
});

afterEach(function() {
this.server.close();
});

it('works in a FastBoot environment', function() {
return this.visit('/').then(function(res) {
var $ = res.jQuery;
var response = res.response;

expect(response.statusCode).to.equal(200);
expect($('li').length).to.equal(POSTS.length);
});
});
});
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -42,9 +42,11 @@
"@commitlint/config-conventional": "^7.0.1",
"@commitlint/travis-cli": "^7.0.0",
"broccoli-asset-rev": "^2.7.0",
"chai": "^4.1.2",
"ember-cli": "~3.1.4",
"ember-cli-chai": "^0.5.0",
"ember-cli-dependency-checker": "^2.1.1",
"ember-cli-fastboot": "^1.1.4-beta.1",
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
"ember-cli-inject-live-reload": "^1.4.1",
Expand All @@ -58,6 +60,7 @@
"ember-cli-uglify": "^2.1.0",
"ember-data": "^3.1.1",
"ember-export-application-global": "2.0.0",
"ember-fastboot-addon-tests": "^0.4.0",
"ember-load-initializers": "1.1.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-mocha": "0.14.0",
Expand All @@ -70,6 +73,7 @@
"eslint-plugin-ember": "^5.2.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-prettier": "^2.6.0",
"express": "^4.16.3",
"husky": "^1.0.0-rc.9",
"lint-staged": "^7.2.0",
"loader.js": "^4.7.0",
Expand Down
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Expand Up @@ -7,6 +7,7 @@ const Router = EmberRouter.extend({
});

Router.map(function() {
this.route('commits');
this.route('ember-data-test');
});

Expand Down
18 changes: 18 additions & 0 deletions tests/dummy/app/routes/commits.js
@@ -0,0 +1,18 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';

export default Route.extend({
ajax: service(),

model() {
return get(this, 'ajax').request(
'https://api.github.com/repos/ember-cli/ember-ajax/commits',
{
headers: {
'User-Agent': 'Ember AJAX Testing'
}
}
);
}
});
9 changes: 9 additions & 0 deletions tests/dummy/app/templates/commits.hbs
@@ -0,0 +1,9 @@
<ul>
{{#each model as |record|}}
<li>
<a href={{record.commit.url}}>
{{record.commit.message}}
</a>
</li>
{{/each}}
</ul>

0 comments on commit b96b65f

Please sign in to comment.