Skip to content

Commit

Permalink
Add a (not working) test for addons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 committed Mar 21, 2016
1 parent 0bd369f commit 11d56f5
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/services/dependency-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CHANNEL_FILENAME_MAP = {

const CHANNELS = ['release', 'beta', 'canary'];

const { computed } = Ember;
const { computed, RSVP } = Ember;

export default Ember.Service.extend({
resolveDependencies: function(dependencies) {
Expand All @@ -49,7 +49,7 @@ export default Ember.Service.extend({
addonPromises[name] = this.resolveAddon(name, value);
});

return Ember.RSVP.hash(addonPromises).then(hash => {
return RSVP.hash(addonPromises).then(hash => {
Object.keys(addons).forEach((name) => {
let addon = hash[name];
if(addon.status === 'build_success') {
Expand All @@ -67,15 +67,14 @@ export default Ember.Service.extend({
console.log(`Joost will have to implement some sort of error logic here..`);
}
});
return RSVP.resolve(dependencies);
});
},

resolveAddon(name, value) {
return new Ember.RSVP.Promise(function(resolve) {
let url = `https://nl1fctyzr7.execute-api.us-east-1.amazonaws.com/staging/addon?addon=${name}&addon_version=${value}&ember_version=1.13.15`;
Ember.$.getJSON(url, function(data){
resolve(data);
});
return new RSVP.Promise(function(resolve) {
const url = `https://nl1fctyzr7.execute-api.us-east-1.amazonaws.com/staging/addon?addon=${name}&addon_version=${value}&ember_version=1.13.15`;
resolve(Ember.$.getJSON(url).then(data => RSVP.resolve(data)));
});
},

Expand Down
2 changes: 1 addition & 1 deletion app/services/ember-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export default Ember.Service.extend({
const dependencyResolver = this.get('dependencyResolver');
dependencyResolver.resolveDependencies(twiddleJson.dependencies);
if ('addons' in twiddleJson) {
dependencyResolver.resolveAddons(twiddleJson.addons, twiddleJson.dependencies).then(() => {
return dependencyResolver.resolveAddons(twiddleJson.addons, twiddleJson.dependencies).then(() => {
return RSVP.resolve(twiddleJson);
}).catch(() => {
return RSVP.reject();
Expand Down
65 changes: 65 additions & 0 deletions tests/acceptance/addons-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'ember-twiddle/tests/helpers/start-app';

module('Acceptance | addons', {
beforeEach: function() {
this.application = startApp();
this.cachePrompt = window.prompt;
window.prompt = (text, defaultResponse) => defaultResponse;
},

afterEach: function() {
Ember.run(this.application, 'destroy');
window.prompt = this.cachePrompt;
}
});

test('Addons work', function(assert) {

const files = [
{
filename: "application.template.hbs",
content: `{{#if (gt appName.length 3)}}
Welcome to {{appName}}
{{/if}}`
},
{
filename: "application.controller.js",
content: `import Ember from "ember";
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});`
},
{
filename: "twiddle.json",
content: `{
"version": "0.7.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": true,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.2/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember-template-compiler.js"
},
addons: {
"ember-truth-helpers": "1.2.0"
}
}`
}
];

runGist(files);

andThen(function() {
const outputDiv = 'div';

assert.equal(outputContents(outputDiv), 'Welcome to Ember Twiddle');
});
});

0 comments on commit 11d56f5

Please sign in to comment.