Skip to content

Commit

Permalink
Setup addon tests
Browse files Browse the repository at this point in the history
use npm run instead of yarn in travis to work around
tomdale/ember-cli-addon-tests#198
  • Loading branch information
xg-wang committed Dec 1, 2018
1 parent 046f8f7 commit fcf0c9a
Show file tree
Hide file tree
Showing 25 changed files with 385 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try

test/fixtures
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
script:
- yarn lint:js
- yarn test
- yarn test:node
- npm run test:node

- name: "Floating Dependencies"
script:
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
"broccoli-asset-rev": "^3.0.0",
"broccoli-test-helper": "^2.0.0",
"chai": "^4.1.2",
"chai-fs": "^2.0.0",
"co": "^4.6.0",
"ember-cli": "~3.5.1",
"ember-cli-addon-tests": "^0.11.0",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-htmlbars": "^3.0.1",
"ember-cli-fastboot": "^2.0.0",
Expand All @@ -58,6 +60,8 @@
"eslint": "^5.9.0",
"eslint-plugin-ember": "^6.0.1",
"eslint-plugin-node": "^8.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"lerna-changelog": "^0.8.2",
"loader.js": "^4.2.3",
"mocha": "^5.2.0"
Expand Down
63 changes: 63 additions & 0 deletions test/fastboot-build-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';
const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-fs'));

const glob = require('glob');

const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;

describe('it builds with ember-cli-fastboot', function() {
this.timeout(300000);

let app;

beforeEach(function() {
app = new AddonTestApp();

return app
.create('dummy', { skipNpm: true })
.then(app =>
app.editPackageJSON(pkg => {
pkg.devDependencies['ember-cli-fastboot'] = '*';
})
)
.then(() => app.run('npm', 'install'));
});

it('builds into dist/ember-fetch/fetch-fastboot.js', function() {
return app.runEmberCommand('build').then(function() {
expect(app.filePath('dist/index.html')).to.be.a.file();
expect(app.filePath('dist/ember-fetch/fastboot-fetch.js')).to.be.a.file();
expect(app.filePath('dist/assets/dummy-fastboot.js')).to.be.a.file();
});
});

it('produces a production build with --environment=production', function() {
return app
.runEmberCommand('build', '--environment=production')
.then(function() {
expect(app.filePath('dist/index.html')).to.be.a.file();
expect(find('dist/ember-fetch/fastboot-fetch-*.js')).to.be.a.file();
expect(find('dist/ember-fetch/fastboot-fetch-*.js')).to.match(
/fastboot-fetch-\w{32}/,
'file name should contain MD5 fingerprint'
);

expect(find('dist/assets/dummy-fastboot-*.js')).to.be.a.file();
expect(find('dist/assets/dummy-fastboot-*.js')).to.match(
/dummy-fastboot-\w{32}/,
'file name should contain MD5 fingerprint'
);
});
});

function find(globPath) {
globPath = app.filePath(globPath);
let files = glob.sync(globPath);

expect(files.length).to.equal(1, globPath);

return files[0];
}
});
52 changes: 52 additions & 0 deletions test/fastboot-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';
const request = require('request');
const get = require('rsvp').denodeify(request);
const chai = require('chai');
const expect = chai.expect;
chai.use(require('chai-fs'));

const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp;

describe('renders in fastboot build', function() {
this.timeout(300000);

let app;

beforeEach(function() {
app = new AddonTestApp();

return app
.create('dummy', { skipNpm: true })
.then(app =>
app.editPackageJSON(pkg => {
pkg.devDependencies['ember-cli-fastboot'] = '*';
// These 2 are in ember-fetch's package.json, symlinking to dummy won't help resolve
pkg.devDependencies['abortcontroller-polyfill'] = '*';
pkg.devDependencies['node-fetch'] = '*';
})
)
.then(function() {
return app.run('npm', 'install');
})
.then(function() {
return app.startServer({
command: 'serve'
});
});
});

afterEach(function() {
return app.stopServer();
});

it('fetches in fastboot mode', function() {
return get({
url: 'http://localhost:49741/',
headers: {
Accept: 'text/html'
}
}).then(function(response) {
expect(response.body).to.contain('Hello World! fetch');
});
});
});
14 changes: 14 additions & 0 deletions test/fixtures/dummy/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;
Empty file.
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions test/fixtures/dummy/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/dummy.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/dummy.js"></script>

{{content-for "body-footer"}}
</body>
</html>
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/dummy/app/resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Resolver from 'ember-resolver';

export default Resolver;
12 changes: 12 additions & 0 deletions test/fixtures/dummy/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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;
Empty file.
15 changes: 15 additions & 0 deletions test/fixtures/dummy/app/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Route from '@ember/routing/route';
import { hash } from 'rsvp';
import fetch from 'fetch';
import ajax from 'ember-fetch/ajax';

export default Route.extend({
model: function() {
return hash({
fetch: fetch('/omg.json').then(function(request) {
return request.json();
}),
ajax: ajax('/omg.json')
});
}
});
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2 id="title">Welcome to Ember</h2>

{{outlet}}
Empty file.
7 changes: 7 additions & 0 deletions test/fixtures/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="fetch">
Hello {{model.fetch.name}}! fetch
</div>

<div class="ajax">
Hello {{model.ajax.name}}! ajax
</div>
55 changes: 55 additions & 0 deletions test/fixtures/dummy/config/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

module.exports = function(environment) {
let ENV = {
modulePrefix: 'dummy',
environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. 'with-controller': true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false
}
},

APP: {
// Here you can pass flags/options to your application instance
// when it is created
},

fastboot: {
hostWhitelist: [/^localhost:\d+$/]
}
};

if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}

if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';

// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;

ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}

if (environment === 'production') {
// here you can enable a production-specific feature
}

return ENV;
};
18 changes: 18 additions & 0 deletions test/fixtures/dummy/config/targets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const browsers = [
'last 1 Chrome versions',
'last 1 Firefox versions',
'last 1 Safari versions'
];

const isCI = !!process.env.CI;
const isProduction = process.env.EMBER_ENV === 'production';

if (isCI || isProduction) {
browsers.push('ie 11');
}

module.exports = {
browsers
};
12 changes: 12 additions & 0 deletions test/fixtures/dummy/ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Add options here
'ember-fetch': {
}
});
return app.toTree();
};
3 changes: 3 additions & 0 deletions test/fixtures/dummy/public/omg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "World"
}
3 changes: 3 additions & 0 deletions test/fixtures/dummy/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# http://www.robotstxt.org
User-agent: *
Disallow:
Loading

0 comments on commit fcf0c9a

Please sign in to comment.