Skip to content

Commit

Permalink
Merge pull request #234 from trentmwillis/qunit-2
Browse files Browse the repository at this point in the history
Upgrade QUnit to 2.0
  • Loading branch information
rwjblue authored Aug 17, 2016
2 parents f1e80f7 + 3b5c985 commit d3c44ad
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 192 deletions.
23 changes: 1 addition & 22 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
{
"predef": [
"document",
"window",
"location",
"setTimeout",
"Ember",
"Em",
"DS",
"$",
"ok",
"moduleFor",
"moduleForModel",
"moduleForComponent",
"expect",
"equal",
"strictEqual",
"deepEqual",
"test",
"emq",
"setResolver",
"QUnit"
],
"node" : false,
"browser" : false,
"boss" : true,
Expand All @@ -41,6 +19,7 @@
"plusplus": false,
"regexp": false,
"undef": true,
"unused": true,
"sub": true,
"strict": false,
"white": false,
Expand Down
5 changes: 1 addition & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
"ember": "^1.13.13"
},
"devDependencies": {
"qunit": "^1.23.1",
"qunit": "^2.0.1",
"loader": "ember-cli/loader.js#1.0.1",
"ember-cli-shims": "0.0.3",
"ember-cli-test-loader": "0.0.4",
"jquery": "~2.1.4",
"ember-data": "~1.0.0-beta.10"
},
"resolutions": {
"ember-data": "~1.0.0-beta.10"
}
}
19 changes: 8 additions & 11 deletions lib/ember-qunit.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import moduleFor from 'ember-qunit/module-for';
import moduleForComponent from 'ember-qunit/module-for-component';
import moduleForModel from 'ember-qunit/module-for-model';
import test from 'ember-qunit/test';
import only from 'ember-qunit/only';
import skip from 'ember-qunit/skip';
import { setResolver } from 'ember-test-helpers';
import moduleFor from 'ember-qunit/module-for';
import moduleForComponent from 'ember-qunit/module-for-component';
import moduleForModel from 'ember-qunit/module-for-model';
import QUnitAdapter from 'ember-qunit/adapter';
import { setResolver } from 'ember-test-helpers';
export { test, skip, only } from 'qunit';

export {
moduleFor,
moduleForComponent,
moduleForModel,
test,
only,
skip,
setResolver
setResolver,
QUnitAdapter
};
20 changes: 20 additions & 0 deletions lib/ember-qunit/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Ember from 'ember';
import QUnit from 'qunit';

export default Ember.Test.Adapter.extend({
init() {
this.doneCallbacks = [];
},

asyncStart() {
this.doneCallbacks.push(QUnit.config.current.assert.async());
},

asyncEnd() {
this.doneCallbacks.pop()();
},

exception(error) {
QUnit.config.current.assert.ok(false, Ember.inspect(error));
}
});
7 changes: 0 additions & 7 deletions lib/ember-qunit/only.js

This file was deleted.

27 changes: 7 additions & 20 deletions lib/ember-qunit/qunit-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ function beforeEachCallback(callbacks) {

var beforeEach;

if (callbacks.setup) {
beforeEach = callbacks.setup;
delete callbacks.setup;
}

if (callbacks.beforeEach) {
beforeEach = callbacks.beforeEach;
delete callbacks.beforeEach;
Expand All @@ -26,11 +21,6 @@ function afterEachCallback(callbacks) {

var afterEach;

if (callbacks.teardown) {
afterEach = callbacks.teardown;
delete callbacks.teardown;
}

if (callbacks.afterEach) {
afterEach = callbacks.afterEach;
delete callbacks.afterEach;
Expand All @@ -46,28 +36,25 @@ export function createModule(Constructor, name, description, callbacks) {
var module = new Constructor(name, description, callbacks);

qunitModule(module.name, {
setup: function(assert) {
var done = assert.async();

beforeEach() {
// provide the test context to the underlying module
module.setContext(this);

return module.setup().then(function() {
return module.setup(...arguments).then(() => {
if (beforeEach) {
return beforeEach.call(module.context, assert);
return beforeEach.apply(this, arguments);
}
})['finally'](done);
});
},

teardown: function(assert) {
afterEach() {
let result;

if (afterEach) {
result = afterEach.call(module.context, assert);
result = afterEach.apply(this, arguments);
}

var done = assert.async();
return Ember.RSVP.resolve(result).then(() => module.teardown()['finally'](done));
return Ember.RSVP.resolve(result).then(() => module.teardown(...arguments));
}
});
}
7 changes: 0 additions & 7 deletions lib/ember-qunit/skip.js

This file was deleted.

43 changes: 0 additions & 43 deletions lib/ember-qunit/test-wrapper.js

This file was deleted.

7 changes: 0 additions & 7 deletions lib/ember-qunit/test.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/qunit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals test:true */
/* globals QUnit */

export var module = QUnit.module;
export var test = QUnit.test;
Expand Down
29 changes: 29 additions & 0 deletions tests/adapter-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global setTimeout */

import { module, test } from 'qunit';
import { QUnitAdapter } from 'ember-qunit';

module('QUnitAdapter');

test('asyncStart waits for asyncEnd to finish a test', function(assert) {
const adapter = QUnitAdapter.create();

adapter.asyncStart();
setTimeout(function() {
assert.ok(true);
adapter.asyncEnd();
}, 50);
});

test('asyncStart waits for equal numbers of asyncEnd to finish a test', function(assert) {
const adapter = QUnitAdapter.create();

adapter.asyncStart();
adapter.asyncStart();
adapter.asyncEnd();

setTimeout(function() {
assert.ok(true);
adapter.asyncEnd();
}, 50);
});
57 changes: 29 additions & 28 deletions tests/module-for-component-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import $ from 'jquery';
import { moduleForComponent, test } from 'ember-qunit';
import { setResolverRegistry } from 'tests/test-support/resolver';

Expand Down Expand Up @@ -26,50 +27,50 @@ moduleForComponent('x-foo', {
}
});

test('renders', function() {
expect(2);
test('renders', function(assert) {
assert.expect(2);
var component = this.subject();
equal(component._state, 'preRender');
assert.equal(component._state, 'preRender');
this.render();
equal(component._state, 'inDOM');
assert.equal(component._state, 'inDOM');
});

test('append', function() {
expect(2);
test('append', function(assert) {
assert.expect(2);
var component = this.subject();
equal(component._state, 'preRender');
assert.equal(component._state, 'preRender');
this.append();
equal(component._state, 'inDOM');
assert.equal(component._state, 'inDOM');
// TODO - is there still a way to check deprecationWarnings?
// ok(Ember.A(Ember.deprecationWarnings).contains('this.append() is deprecated. Please use this.render() instead.'));
// assert.ok(Ember.A(Ember.deprecationWarnings).contains('this.append() is deprecated. Please use this.render() instead.'));
});

test('yields', function() {
expect(2);
test('yields', function(assert) {
assert.expect(2);
var component = this.subject({
layout: Ember.Handlebars.compile("yield me")
});
equal(component._state, 'preRender');
assert.equal(component._state, 'preRender');
this.render();
equal(component._state, 'inDOM');
assert.equal(component._state, 'inDOM');
});

test('can lookup components in its layout', function() {
expect(1);
test('can lookup components in its layout', function(assert) {
assert.expect(1);
var component = this.subject({
layout: Ember.Handlebars.compile("{{x-foo id='yodawg-i-heard-you-liked-x-foo-in-ur-x-foo'}}")
});
this.render();
equal(component._state, 'inDOM');
assert.equal(component._state, 'inDOM');
});

test('clears out views from test to test', function() {
expect(1);
test('clears out views from test to test', function(assert) {
assert.expect(1);
this.subject({
layout: Ember.Handlebars.compile("{{x-foo id='yodawg-i-heard-you-liked-x-foo-in-ur-x-foo'}}")
});
this.render();
ok(true, 'rendered without id already being used from another test');
assert.ok(true, 'rendered without id already being used from another test');
});

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -80,25 +81,25 @@ moduleForComponent('pretty-color', {
}
});

test("className", function(){
test("className", function(assert){
// first call to this.$() renders the component.
ok(this.$().is('.pretty-color'));
assert.ok(this.$().is('.pretty-color'));
});

test("template", function(){
test("template", function(assert){
var component = this.subject();

equal($.trim(this.$().text()), 'Pretty Color:');
assert.equal($.trim(this.$().text()), 'Pretty Color:');

Ember.run(function(){
component.set('name', 'green');
});

equal($.trim(this.$().text()), 'Pretty Color: green');
assert.equal($.trim(this.$().text()), 'Pretty Color: green');
});

test("$", function(){
var component = this.subject({name: 'green'});
equal($.trim(this.$('.color-name').text()), 'green');
equal($.trim(this.$().text()), 'Pretty Color: green');
test("$", function(assert){
this.subject({ name: 'green' });
assert.equal($.trim(this.$('.color-name').text()), 'green');
assert.equal($.trim(this.$().text()), 'Pretty Color: green');
});
Loading

0 comments on commit d3c44ad

Please sign in to comment.