Skip to content

Commit

Permalink
Merge pull request #65 from stefanpenner/smoke-test
Browse files Browse the repository at this point in the history
adding smoke tests to catch initializer logic
  • Loading branch information
jasonmit committed Jul 23, 2015
2 parents e953bcf + b90ab60 commit 3f2287e
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ env:
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=ember-1.10.0
- EMBER_TRY_SCENARIO=ember-1.11.3
- EMBER_TRY_SCENARIO=ember-1.12.0

matrix:
fast_finish: true
Expand Down
2 changes: 1 addition & 1 deletion addon/computeds/ago.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function computedAgo(date, maybeInputFormat) {
let momentArgs = [get(this, date)];

if (arguments.length > 1) {
let desc = isDescriptor(this[maybeInputFormat]);
let desc = isDescriptor.call(this, maybeInputFormat);
let input = desc ? get(this, maybeInputFormat) : maybeInputFormat;

if (desc && computed._dependentKeys.indexOf(maybeInputFormat) === -1) {
Expand Down
2 changes: 1 addition & 1 deletion addon/computeds/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function computedDuration(val, maybeUnits) {
momentArgs = [get(this, val)];

if (numArgs > 1) {
desc = isDescriptor(this[maybeUnits]);
desc = isDescriptor.call(this, maybeUnits);
input = desc ? get(this, maybeUnits) : maybeUnits;

if (desc && computed._dependentKeys.indexOf(maybeUnits) === -1) {
Expand Down
3 changes: 1 addition & 2 deletions addon/computeds/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default function computedMoment(date, outputFormat, maybeInputFormat) {
let momentArgs = [get(this, date)];

let propertyValues = EnumerableUtils.map(args, (arg) => {
let desc = isDescriptor(this[arg]);

let desc = isDescriptor.call(this, arg);
if (desc && result._dependentKeys.indexOf(arg) === -1) {
result.property(arg);
}
Expand Down
2 changes: 1 addition & 1 deletion addon/helpers/ago.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (Ember.Helper) {
});
}
else {
ago = Ember.HTMLBars.makeBoundHelper(buildHelper());
ago = buildHelper();
}

export default ago;
3 changes: 1 addition & 2 deletions addon/helpers/duration.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Ember from 'ember';
import moment from 'moment';

function durationHelper(params) {
Expand All @@ -11,4 +10,4 @@ function durationHelper(params) {
return moment.duration.apply(this, params).humanize();
}

export default Ember.HTMLBars.makeBoundHelper(durationHelper);
export default durationHelper;
3 changes: 1 addition & 2 deletions addon/helpers/moment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Ember from 'ember';
import moment from 'moment';

function momentHelper(params) {
Expand All @@ -24,4 +23,4 @@ function momentHelper(params) {
return moment.apply(this, args).format(output);
}

export default Ember.HTMLBars.makeBoundHelper(momentHelper);
export default momentHelper;
9 changes: 8 additions & 1 deletion addon/utils/is-descriptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import Ember from 'ember';
let { typeOf, Descriptor } = Ember;

// credit: https://github.com/cibernox/ember-cpm/blob/master/addon/utils.js#L17-L20
function isDescriptor(prop) {
function isDescriptor(propertyName) {
const meta = Ember.meta(this);

if (meta && meta.descs && meta.descs[propertyName]) {
return true;
}

const prop = this[propertyName];
return typeOf(prop) === 'object' && (prop.constructor === Descriptor || // Ember < 1.11
prop.isDescriptor); // Ember >= 1.11.0
}
Expand Down
9 changes: 9 additions & 0 deletions addon/utils/make-bound-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';

export default function(helper) {
if (Ember.Helper && Ember.Helper.detect(helper)) {
return helper;
}

return Ember.HTMLBars.makeBoundHelper(helper);
}
5 changes: 4 additions & 1 deletion app/helpers/ago.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default } from 'ember-moment/helpers/ago';
import agoHelper from 'ember-moment/helpers/ago';
import makeBoundHelper from 'ember-moment/utils/make-bound-helper';

export default makeBoundHelper(agoHelper);
5 changes: 4 additions & 1 deletion app/helpers/duration.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default } from 'ember-moment/helpers/duration';
import durationHelper from 'ember-moment/helpers/duration';
import makeBoundHelper from 'ember-moment/utils/make-bound-helper';

export default makeBoundHelper(durationHelper);
5 changes: 4 additions & 1 deletion app/helpers/moment.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default } from 'ember-moment/helpers/moment';
import momentHelper from 'ember-moment/helpers/moment';
import makeBoundHelper from 'ember-moment/utils/make-bound-helper';

export default makeBoundHelper(momentHelper);
7 changes: 5 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "ember-moment",
"dependencies": {
"ember": "1.13.3",
"ember": "1.10.0",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
"ember-qunit": "0.4.1",
"ember-qunit-notifications": "0.0.7",
"ember-resolver": "~0.1.18",
"jquery": "^1.11.1",
"loader.js": "ember-cli/loader.js#3.2.0",
"moment-timezone": "~0.2.5",
"qunit": "~1.17.1"
},
"resolutions": {
"ember": "release"
}
}
20 changes: 20 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
module.exports = {
scenarios: [
{
name: 'ember-1.10.0',
dependencies: {
'ember': '1.10.0',
'ember-load-initializers': 'ember-cli/ember-load-initializers#0.0.2'
}
},
{
name: 'ember-1.11.3',
dependencies: {
'ember': '1.11.3',
'ember-load-initializers': 'ember-cli/ember-load-initializers#0.0.2'
}
},
{
name: 'ember-1.12.0',
dependencies: {
'ember': '1.12.0'
}
},
{
name: 'default',
dependencies: { }
Expand Down
40 changes: 40 additions & 0 deletions tests/acceptance/smoke-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Ember from 'ember';
import { module } from 'qunit';
import startApp from '../helpers/start-app';

let application;

module('Acceptance: Smoke', {
beforeEach() {
application = startApp();
},
afterEach() {
if (application) {
Ember.run(application, 'destroy');
}
}
});

test('moment', (assert) => {
assert.expect(1);
visit('/smoke');
andThen(function() {
assert.equal(find('.moment-independence-day').text(), 'Jul 04, 1776');
});
});

test('ago', (assert) => {
assert.expect(1);
visit('/smoke');
andThen(function() {
assert.equal(find('.ago-now').text(), 'a few seconds ago');
});
});

test('duration', (assert) => {
assert.expect(1);
visit('/smoke');
andThen(function() {
assert.equal(find('.duration-seven-minutes').text(), '7 minutes');
});
});
6 changes: 6 additions & 0 deletions tests/dummy/app/controllers/smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Ember from 'ember';

export default Ember.Controller.extend({
now: new Date(),
usIndependenceDay: new Date(1776, 6, 4, 12, 0, 0)
});
2 changes: 2 additions & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var Router = Ember.Router.extend({
});

Router.map(function() {
this.route('index', { path: '/' });
this.route('smoke', { path: '/smoke' });
});

export default Router;
9 changes: 9 additions & 0 deletions tests/dummy/app/routes/smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';
import moment from 'moment';

export default Ember.Route.extend({
setupController: function (controller, model) {
moment.locale('en');
return this._super(controller, model);
}
});
Empty file removed tests/dummy/app/templates/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions tests/dummy/app/templates/smoke.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="moment-independence-day">{{moment usIndependenceDay 'MMM DD, YYYY'}}</div>
<div class="ago-now">{{ago now}}</div>
<div class="duration-seven-minutes">{{duration 420000}}</div>

0 comments on commit 3f2287e

Please sign in to comment.