diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..0e4e31cad --- /dev/null +++ b/.jshintrc @@ -0,0 +1,40 @@ +{ + "predef": [ + "document", + "window", + "-Promise", + "ok", + "deepEqual", + "equal", + "notEqual", + "expect", + "throws", + "QUnit", + "Pretender" + ], + "browser": true, + "boss": true, + "curly": true, + "debug": false, + "devel": true, + "eqeqeq": true, + "evil": true, + "forin": false, + "immed": false, + "laxbreak": false, + "newcap": true, + "noarg": true, + "noempty": false, + "nonew": false, + "nomen": false, + "onevar": false, + "plusplus": false, + "regexp": false, + "undef": true, + "sub": true, + "strict": false, + "white": false, + "eqnull": true, + "esnext": true, + "unused": true +} diff --git a/ember-cli-build.js b/ember-cli-build.js index 882235a98..c3c8d1485 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -2,7 +2,7 @@ var Funnel = require('broccoli-funnel'); var mergeTrees = require('broccoli-merge-trees'); var Babel = require('broccoli-babel-transpiler'); var concat = require('broccoli-sourcemap-concat'); - +var JSHint = require('broccoli-jshint'); module.exports = function() { // --- Dependencies --- @@ -32,7 +32,10 @@ module.exports = function() { destDir: '/tests' }); - var main = mergeTrees([klassy, lib, tests]); + var libJSHint = new JSHint(lib); + var testJSHint = new JSHint(tests); + + var main = mergeTrees([klassy, lib, tests, libJSHint, testJSHint]); // --- Compile ES6 modules --- diff --git a/lib/ember-test-helpers/build-registry.js b/lib/ember-test-helpers/build-registry.js index 6ddef8bcb..71370fd36 100644 --- a/lib/ember-test-helpers/build-registry.js +++ b/lib/ember-test-helpers/build-registry.js @@ -1,3 +1,5 @@ +/* globals global, self */ + import Ember from 'ember'; function exposeRegistryMethodsWithoutDeprecations(container) { diff --git a/lib/ember-test-helpers/test-module-for-model.js b/lib/ember-test-helpers/test-module-for-model.js index 2a9e3b701..769fd03de 100644 --- a/lib/ember-test-helpers/test-module-for-model.js +++ b/lib/ember-test-helpers/test-module-for-model.js @@ -1,3 +1,5 @@ +/* global DS */ // added here to prevent an import from erroring when ED is not present + import TestModule from './test-module'; import Ember from 'ember'; diff --git a/lib/ember-test-helpers/test-module.js b/lib/ember-test-helpers/test-module.js index 64e5fa24b..e0bdbde91 100644 --- a/lib/ember-test-helpers/test-module.js +++ b/lib/ember-test-helpers/test-module.js @@ -239,10 +239,8 @@ export default Klass.extend({ // allow arbitrary named factories, like rspec let contextualizeCallbacks: function() { - var _this = this; var callbacks = this.callbacks; var context = this.context; - var factory = context.factory; this.cache = this.cache || {}; this.cachedCalls = this.cachedCalls || {}; @@ -250,21 +248,25 @@ export default Klass.extend({ var keys = (Object.keys || Ember.keys)(callbacks); for (var i = 0, l = keys.length; i < l; i++) { - (function(key) { + this._contextualizeCallback(context, keys[i]); + } + }, - context[key] = function(options) { - if (_this.cachedCalls[key]) { return _this.cache[key]; } + _contextualizeCallback: function(context, key) { + var _this = this; + var callbacks = this.callbacks; + var factory = context.factory; - var result = callbacks[key].call(_this, options, factory()); + context[key] = function(options) { + if (_this.cachedCalls[key]) { return _this.cache[key]; } - _this.cache[key] = result; - _this.cachedCalls[key] = true; + var result = callbacks[key].call(_this, options, factory()); - return result; - }; + _this.cache[key] = result; + _this.cachedCalls[key] = true; - })(keys[i]); - } + return result; + }; }, _setupContainer: function(isolated) { diff --git a/lib/ember-test-helpers/test-resolver.js b/lib/ember-test-helpers/test-resolver.js index 593f4e887..1ce70e59e 100644 --- a/lib/ember-test-helpers/test-resolver.js +++ b/lib/ember-test-helpers/test-resolver.js @@ -5,6 +5,9 @@ export function setResolver(resolver) { } export function getResolver() { - if (__resolver__ == null) throw new Error('you must set a resolver with `testResolver.set(resolver)`'); + if (__resolver__ == null) { + throw new Error('you must set a resolver with `testResolver.set(resolver)`'); + } + return __resolver__; } diff --git a/lib/ember-test-helpers/wait.js b/lib/ember-test-helpers/wait.js index bb1ae4c65..ae77ea0f3 100644 --- a/lib/ember-test-helpers/wait.js +++ b/lib/ember-test-helpers/wait.js @@ -1,3 +1,5 @@ +/* globals jQuery, self */ + import Ember from 'ember'; var requests; diff --git a/package.json b/package.json index 2035e0839..31fb8017d 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "devDependencies": { "broccoli-babel-transpiler": "^5.4.5", "broccoli-funnel": "^0.2.13", + "broccoli-jshint": "^1.1.1", "broccoli-merge-trees": "^0.1.4", "broccoli-sourcemap-concat": "^0.4.3", "ember-cli": "1.13.13", diff --git a/tests/test-module-for-component-test.js b/tests/test-module-for-component-test.js index 047c3c864..42ea60cc6 100644 --- a/tests/test-module-for-component-test.js +++ b/tests/test-module-for-component-test.js @@ -5,6 +5,8 @@ import test from 'tests/test-support/qunit-test'; import qunitModuleFor from 'tests/test-support/qunit-module-for'; import { setResolverRegistry } from 'tests/test-support/resolver'; +var $ = Ember.$; + function moduleForComponent(name, description, callbacks) { var module = new TestModuleForComponent(name, description, callbacks); qunitModuleFor(module); @@ -174,7 +176,8 @@ test("template", function(){ }); test("$", function(){ - var component = this.subject({name: 'green'}); + this.subject({name: 'green'}); + equal($.trim(this.$('.color-name').text()), 'green'); equal($.trim(this.$().text()), 'Pretty Color: green'); }); @@ -237,7 +240,11 @@ test('can handle click', function() { }); moduleForComponent('changing-color', 'component:changing-color -- handles closure actions', { - integration: true + integration: true, + + beforeSetup: function() { + setupRegistry(); + } }); if (hasEmberVersion(1,13)) { @@ -249,9 +256,10 @@ if (hasEmberVersion(1,13)) { } var testModule; -module('moduleForComponent: can be invoked with only the component name', { +QUnit.module('moduleForComponent: can be invoked with only the component name', { beforeEach: function(assert) { var done = assert.async(); + setupRegistry(); testModule = new TestModuleForComponent('pretty-color', { unit: true }); testModule.setup()['finally'](done); }, @@ -267,7 +275,7 @@ test('it allows missing callbacks', function() { }); var testModule; -module('moduleForComponent: can be invoked with the component name and description', { +QUnit.module('moduleForComponent: can be invoked with the component name and description', { beforeEach: function(assert) { var done = assert.async(); testModule = new TestModuleForComponent('pretty-color', 'PrettyColor', { unit: true }); @@ -284,7 +292,7 @@ test('it allows missing callbacks', function() { ok(true, 'no errors are thrown'); }); -module('moduleForComponent: handles errors thrown during setup', { +QUnit.module('moduleForComponent: handles errors thrown during setup', { beforeEach: function(assert) { var done = assert.async(); testModule = new TestModuleForComponent('x-bad', { diff --git a/tests/test-module-for-integration-test.js b/tests/test-module-for-integration-test.js index d503eb135..8a9780743 100644 --- a/tests/test-module-for-integration-test.js +++ b/tests/test-module-for-integration-test.js @@ -289,8 +289,8 @@ if (! hasEmberVersion(2,0)) { } }); - test('it can render components semantically equivalent to v0.4.3', function(assert) { - var component = this.subject({ + test('it can render components semantically equivalent to v0.4.3', function() { + this.subject({ name: 'Charles XII', }); this.render(); diff --git a/tests/test-module-for-model-test.js b/tests/test-module-for-model-test.js index 5d4d4732a..9eeb74e47 100644 --- a/tests/test-module-for-model-test.js +++ b/tests/test-module-for-model-test.js @@ -2,6 +2,8 @@ import { TestModuleForModel } from 'ember-test-helpers'; import test from 'tests/test-support/qunit-test'; import qunitModuleFor from 'tests/test-support/qunit-module-for'; import { setResolverRegistry } from 'tests/test-support/resolver'; +import Ember from 'ember'; +import DS from 'ember-data'; function moduleForModel(name, description, callbacks) { var module = new TestModuleForModel(name, description, callbacks); @@ -15,7 +17,7 @@ var adapter = DS.JSONAPIAdapter || DS.FixtureAdapter; var Whazzit = DS.Model.extend({ gear: DS.attr('string') }); var whazzitAdapterFindAllCalled = false; var WhazzitAdapter = adapter.extend({ - findAll: function(store, type) { + findAll: function() { whazzitAdapterFindAllCalled = true; return this._super.apply(this, arguments); } @@ -108,7 +110,7 @@ moduleForModel('whazzit', 'model:whazzit with custom adapter', { if (DS.JSONAPIAdapter && adapter === DS.JSONAPIAdapter) { server = new Pretender(function() { - this.get('/whazzits', function(request) { + this.get('/whazzits', function() { return [200, {"Content-Type": "application/json"}, JSON.stringify({ data: Whazzit.FIXTURES })]; }); }); diff --git a/tests/test-module-test.js b/tests/test-module-test.js index d4e2f50f6..0b56bc44b 100644 --- a/tests/test-module-test.js +++ b/tests/test-module-test.js @@ -24,11 +24,6 @@ function setupRegistry() { }); } -var a = 0; -var b = 0; -var beforeSetupOk = false; -var afterTeardownOk = false; - var callbackOrder, setupContext, teardownContext, beforeSetupContext, afterTeardownContext; moduleFor('component:x-foo', 'TestModule callbacks', { diff --git a/tests/test-support/qunit-test.js b/tests/test-support/qunit-test.js index f6723041c..d2b2fd180 100644 --- a/tests/test-support/qunit-test.js +++ b/tests/test-support/qunit-test.js @@ -1,3 +1,4 @@ +import Ember from 'ember'; import { getContext } from 'ember-test-helpers'; export default function test(testName, callback) { @@ -11,8 +12,8 @@ export default function test(testName, callback) { } Ember.run(function(){ - stop(); - Ember.RSVP.Promise.cast(result)['catch'](failTestOnPromiseRejection)['finally'](start); + QUnit.stop(); + Ember.RSVP.Promise.cast(result)['catch'](failTestOnPromiseRejection)['finally'](QUnit.start); }); } diff --git a/tests/test-support/resolver.js b/tests/test-support/resolver.js index a6b8912ff..2fa33d095 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({ diff --git a/tests/wait-test.js b/tests/wait-test.js index 0e2842bfd..6bfc5d5e3 100644 --- a/tests/wait-test.js +++ b/tests/wait-test.js @@ -2,10 +2,10 @@ import Ember from 'ember'; import { TestModuleForComponent } from 'ember-test-helpers'; import test from 'tests/test-support/qunit-test'; import qunitModuleFor from 'tests/test-support/qunit-module-for'; -import { setResolverRegistry } from 'tests/test-support/resolver'; - import wait from 'ember-test-helpers/wait'; +var $ = Ember.$; + function moduleForComponent(name, description, callbacks) { var module = new TestModuleForComponent(name, description, callbacks); qunitModuleFor(module); @@ -49,7 +49,7 @@ moduleForComponent('wait helper tests', { click: function() { var component = this; - jQuery.ajax('/whazzits', { cache: false }) + $.ajax('/whazzits', { cache: false }) .then(function(data) { var value = component.get('internalValue'); @@ -70,7 +70,7 @@ moduleForComponent('wait helper tests', { Ember.run(component, 'set', 'internalValue', 'Local Data!'); }, 10); - jQuery.ajax('/whazzits', { cache: false }) + $.ajax('/whazzits', { cache: false }) .then(function(data) { var value = component.get('internalValue'); @@ -78,7 +78,7 @@ moduleForComponent('wait helper tests', { Ember.run.later(function() { - jQuery.ajax('/whazzits', { cache: false }) + $.ajax('/whazzits', { cache: false }) .then(function(data) { if (component.isDestroyed) { return; } @@ -94,7 +94,7 @@ moduleForComponent('wait helper tests', { this.register('template:components/x-test-4', Ember.Handlebars.compile("{{internalValue}}")); this.server = new Pretender(function() { - this.get('/whazzits', function(request) { + this.get('/whazzits', function() { return [ 200, { "Content-Type": "text/plain" },