diff --git a/.jshintrc b/.jshintrc index 7107d278..65692088 100644 --- a/.jshintrc +++ b/.jshintrc @@ -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, @@ -41,6 +19,7 @@ "plusplus": false, "regexp": false, "undef": true, + "unused": true, "sub": true, "strict": false, "white": false, diff --git a/bower.json b/bower.json index cd854a91..567fbcf2 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/lib/ember-qunit.js b/lib/ember-qunit.js index c0b0e373..a5b9ec96 100644 --- a/lib/ember-qunit.js +++ b/lib/ember-qunit.js @@ -1,17 +1,12 @@ -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 { setResolver } from 'ember-test-helpers'; +export { test, skip, only } from 'qunit'; export { moduleFor, moduleForComponent, moduleForModel, - test, - only, - skip, setResolver }; diff --git a/lib/ember-qunit/only.js b/lib/ember-qunit/only.js deleted file mode 100644 index 1ebd1d9c..00000000 --- a/lib/ember-qunit/only.js +++ /dev/null @@ -1,7 +0,0 @@ -import testWrapper from 'ember-qunit/test-wrapper'; -import { only as qunitOnly } from 'qunit'; - -export default function only(...args) { - args.unshift(qunitOnly); - testWrapper.apply(null, args); -} diff --git a/lib/ember-qunit/qunit-module.js b/lib/ember-qunit/qunit-module.js index 630fbb6f..3e70cd79 100644 --- a/lib/ember-qunit/qunit-module.js +++ b/lib/ember-qunit/qunit-module.js @@ -6,11 +6,6 @@ function beforeEachCallback(callbacks) { var beforeEach; - if (callbacks.setup) { - beforeEach = callbacks.setup; - delete callbacks.setup; - } - if (callbacks.beforeEach) { beforeEach = callbacks.beforeEach; delete callbacks.beforeEach; @@ -25,11 +20,6 @@ function afterEachCallback(callbacks) { var afterEach; - if (callbacks.teardown) { - afterEach = callbacks.teardown; - delete callbacks.teardown; - } - if (callbacks.afterEach) { afterEach = callbacks.afterEach; delete callbacks.afterEach; @@ -45,25 +35,23 @@ 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) { - beforeEach.call(module.context, assert); + beforeEach.apply(this, arguments); } - })['finally'](done); + }); }, - teardown: function(assert) { + afterEach() { if (afterEach) { - afterEach.call(module.context, assert); + afterEach.apply(this, arguments); } - var done = assert.async(); - return module.teardown()['finally'](done); + + return module.teardown(...arguments); } }); } diff --git a/lib/ember-qunit/skip.js b/lib/ember-qunit/skip.js deleted file mode 100644 index 4058f616..00000000 --- a/lib/ember-qunit/skip.js +++ /dev/null @@ -1,7 +0,0 @@ -import testWrapper from 'ember-qunit/test-wrapper'; -import { skip as qunitSkip } from 'qunit'; - -export default function skip(...args) { - args.unshift(qunitSkip); - testWrapper.apply(null, args); -} diff --git a/lib/ember-qunit/test-wrapper.js b/lib/ember-qunit/test-wrapper.js deleted file mode 100644 index 20392f75..00000000 --- a/lib/ember-qunit/test-wrapper.js +++ /dev/null @@ -1,43 +0,0 @@ -import Ember from 'ember'; -import { getContext } from 'ember-test-helpers'; - -export default function testWrapper(qunit /*, testName, expected, callback, async */) { - var callback; - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; ++_key) { - args[_key - 1] = arguments[_key]; - } - - function wrapper() { - var context = getContext(); - - var result = callback.apply(context, arguments); - - function failTestOnPromiseRejection(reason) { - var message; - if (reason instanceof Error) { - message = reason.stack; - if (reason.message && message && message.indexOf(reason.message) < 0) { - // PhantomJS has a `stack` that does not contain the actual - // exception message. - message = Ember.inspect(reason) + "\n" + message; - } - } else { - message = Ember.inspect(reason); - } - ok(false, message); - } - - Ember.run(function(){ - QUnit.stop(); - Ember.RSVP.Promise.resolve(result)['catch'](failTestOnPromiseRejection)['finally'](QUnit.start); - }); - } - - if (args.length === 2) { - callback = args.splice(1, 1, wrapper)[0]; - } else { - callback = args.splice(2, 1, wrapper)[0]; - } - - qunit.apply(null, args); -} diff --git a/lib/ember-qunit/test.js b/lib/ember-qunit/test.js deleted file mode 100644 index 6c90b68c..00000000 --- a/lib/ember-qunit/test.js +++ /dev/null @@ -1,7 +0,0 @@ -import testWrapper from 'ember-qunit/test-wrapper'; -import { test as qunitTest } from 'qunit'; - -export default function test(...args) { - args.unshift(qunitTest); - testWrapper.apply(null, args); -} diff --git a/lib/qunit.js b/lib/qunit.js index 6535af67..c66a4d51 100644 --- a/lib/qunit.js +++ b/lib/qunit.js @@ -1,4 +1,4 @@ -/* globals test:true */ +/* globals QUnit */ export var module = QUnit.module; export var test = QUnit.test; diff --git a/tests/module-for-component-test.js b/tests/module-for-component-test.js index c4bdfef5..78d34ed1 100644 --- a/tests/module-for-component-test.js +++ b/tests/module-for-component-test.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import $ from 'jquery'; import { moduleForComponent, test } from 'ember-qunit'; import { setResolverRegistry } from 'tests/test-support/resolver'; @@ -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'); }); /////////////////////////////////////////////////////////////////////////////// @@ -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'); }); diff --git a/tests/module-for-model-test.js b/tests/module-for-model-test.js index 7cc8198f..008c0ee1 100644 --- a/tests/module-for-model-test.js +++ b/tests/module-for-model-test.js @@ -1,11 +1,12 @@ import Ember from 'ember'; +import DS from 'ember-data'; import { moduleForModel, test } from 'ember-qunit'; import { setResolverRegistry } from 'tests/test-support/resolver'; var Whazzit = DS.Model.extend({ gear: DS.attr('string') }); var whazzitAdapterFindAllCalled = false; var WhazzitAdapter = DS.FixtureAdapter.extend({ - findAll: function(store, type) { + findAll: function() { whazzitAdapterFindAllCalled = true; return this._super.apply(this, arguments); } @@ -28,29 +29,29 @@ moduleForModel('whazzit', 'model:whazzit without adapter', { setupRegistry(); }, - setup: function() { + beforeEach: function() { Whazzit.FIXTURES = []; } }); -test('store exists', function() { +test('store exists', function(assert) { var store = this.store(); - ok(store instanceof DS.Store); + assert.ok(store instanceof DS.Store); }); -test('model exists as subject', function() { +test('model exists as subject', function(assert) { var model = this.subject(); - ok(model); - ok(model instanceof DS.Model); - ok(model instanceof Whazzit); + assert.ok(model); + assert.ok(model instanceof DS.Model); + assert.ok(model instanceof Whazzit); }); -test('FixtureAdapter is registered for model', function() { +test('FixtureAdapter is registered for model', function(assert) { var model = this.subject(), store = this.store(); - ok(store.adapterFor(model.constructor) instanceof DS.FixtureAdapter); - ok(!(store.adapterFor(model.constructor) instanceof WhazzitAdapter)); + assert.ok(store.adapterFor(model.constructor) instanceof DS.FixtureAdapter); + assert.notOk(store.adapterFor(model.constructor) instanceof WhazzitAdapter); }); /////////////////////////////////////////////////////////////////////////////// @@ -68,22 +69,22 @@ moduleForModel('whazzit', 'model:whazzit with custom adapter', { } }); -test('WhazzitAdapter is registered for model', function() { +test('WhazzitAdapter is registered for model', function(assert) { var model = this.subject(), store = this.store(); - ok(store.adapterFor(model.constructor) instanceof WhazzitAdapter); + assert.ok(store.adapterFor(model.constructor) instanceof WhazzitAdapter); }); -test('WhazzitAdapter is used for `find`', function() { - expect(2); - ok(!whazzitAdapterFindAllCalled, 'precond - custom adapter has not yet been called'); +test('WhazzitAdapter is used for `find`', function(assert) { + assert.expect(2); + assert.notOk(whazzitAdapterFindAllCalled, 'precond - custom adapter has not yet been called'); var store = this.store(); return Ember.run(function() { return store.find('whazzit').then(function() { - ok(whazzitAdapterFindAllCalled, 'uses the custom adapter'); + assert.ok(whazzitAdapterFindAllCalled, 'uses the custom adapter'); }); }); }); @@ -102,10 +103,10 @@ moduleForModel('whazzit', 'model:whazzit with application adapter', { } }); -test('ApplicationAdapter is registered for model', function() { +test('ApplicationAdapter is registered for model', function(assert) { var model = this.subject(), store = this.store(); - ok(store.adapterFor(model.constructor) instanceof ApplicationAdapter); - ok(!(store.adapterFor(model.constructor) instanceof WhazzitAdapter)); + assert.ok(store.adapterFor(model.constructor) instanceof ApplicationAdapter); + assert.notOk(store.adapterFor(model.constructor) instanceof WhazzitAdapter); }); \ No newline at end of file diff --git a/tests/module-for-test.js b/tests/module-for-test.js index 65e2a81b..a2e5593a 100644 --- a/tests/module-for-test.js +++ b/tests/module-for-test.js @@ -1,3 +1,4 @@ +import Ember from 'ember'; import { moduleFor, test } from 'ember-qunit'; import { setResolverRegistry } from 'tests/test-support/resolver'; @@ -17,33 +18,33 @@ moduleFor('component:x-foo', 'TestModule callbacks', { setupRegistry(); }, - setup: function() { + beforeEach: function(assert) { setupContext = this; callbackOrder.push('setup'); - ok(setupContext !== beforeSetupContext); + assert.ok(setupContext !== beforeSetupContext); }, - teardown: function() { + afterEach: function(assert) { teardownContext = this; callbackOrder.push('teardown'); - deepEqual(callbackOrder, [ 'beforeSetup', 'setup', 'teardown']); - equal(setupContext, teardownContext); + assert.deepEqual(callbackOrder, [ 'beforeSetup', 'setup', 'teardown']); + assert.equal(setupContext, teardownContext); }, - afterTeardown: function() { + afterTeardown: function(assert) { afterTeardownContext = this; callbackOrder.push('afterTeardown'); - deepEqual(callbackOrder, [ 'beforeSetup', 'setup', 'teardown', 'afterTeardown']); - equal(afterTeardownContext, beforeSetupContext); - ok(afterTeardownContext !== teardownContext); + assert.deepEqual(callbackOrder, [ 'beforeSetup', 'setup', 'teardown', 'afterTeardown']); + assert.equal(afterTeardownContext, beforeSetupContext); + assert.ok(afterTeardownContext !== teardownContext); } }); -test("setup callbacks called in the correct order", function() { - deepEqual(callbackOrder, [ 'beforeSetup', 'setup' ]); +test("setup callbacks called in the correct order", function(assert) { + assert.deepEqual(callbackOrder, [ 'beforeSetup', 'setup' ]); }); moduleFor('component:x-foo', 'beforeEach/afterEach callbacks', { @@ -53,24 +54,24 @@ moduleFor('component:x-foo', 'beforeEach/afterEach callbacks', { callbackOrder = [ 'beforeSetup' ]; }, - beforeEach: function() { + beforeEach: function(assert) { setupContext = this; callbackOrder.push('beforeEach'); - ok(setupContext !== beforeSetupContext); + assert.ok(setupContext !== beforeSetupContext); }, - afterEach: function() { + afterEach: function(assert) { teardownContext = this; callbackOrder.push('afterEach'); - deepEqual(callbackOrder, [ 'beforeSetup', 'beforeEach', 'afterEach']); - equal(setupContext, teardownContext); + assert.deepEqual(callbackOrder, [ 'beforeSetup', 'beforeEach', 'afterEach']); + assert.equal(setupContext, teardownContext); } }); -test("setup callbacks called in the correct order", function() { - deepEqual(callbackOrder, [ 'beforeSetup', 'beforeEach' ]); +test("setup callbacks called in the correct order", function(assert) { + assert.deepEqual(callbackOrder, [ 'beforeSetup', 'beforeEach' ]); }); moduleFor('component:x-foo', { @@ -81,10 +82,10 @@ moduleFor('component:x-foo', { } }); -test('works properly without description with beforeEach', function() { - expect(1); +test('works properly without description with beforeEach', function(assert) { + assert.expect(1); - equal(setupContext, this, 'beforeEach was called properly'); + assert.equal(setupContext, this, 'beforeEach was called properly'); }); moduleFor('component:x-foo', 'test callback argument', { diff --git a/tests/test-support/resolver.js b/tests/test-support/resolver.js index a6b8912f..2fa33d09 100644 --- a/tests/test-support/resolver.js +++ b/tests/test-support/resolver.js @@ -1,3 +1,4 @@ +import Ember from 'ember'; import { setResolver } from 'ember-test-helpers'; var Resolver = Ember.DefaultResolver.extend({