Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSHint to project. #128

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 5 additions & 2 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---
Expand Down Expand Up @@ -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 ---

Expand Down
2 changes: 2 additions & 0 deletions lib/ember-test-helpers/build-registry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals global, self */

import Ember from 'ember';

function exposeRegistryMethodsWithoutDeprecations(container) {
Expand Down
2 changes: 2 additions & 0 deletions lib/ember-test-helpers/test-module-for-model.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
26 changes: 14 additions & 12 deletions lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,32 +239,34 @@ 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 || {};

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) {
Expand Down
5 changes: 4 additions & 1 deletion lib/ember-test-helpers/test-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
}
2 changes: 2 additions & 0 deletions lib/ember-test-helpers/wait.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals jQuery, self */

import Ember from 'ember';

var requests;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 13 additions & 5 deletions tests/test-module-for-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
},
Expand All @@ -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 });
Expand All @@ -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', {
Expand Down
4 changes: 2 additions & 2 deletions tests/test-module-for-integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions tests/test-module-for-model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 })];
});
});
Expand Down
5 changes: 0 additions & 5 deletions tests/test-module-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
5 changes: 3 additions & 2 deletions tests/test-support/qunit-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Ember from 'ember';
import { getContext } from 'ember-test-helpers';

export default function test(testName, callback) {
Expand All @@ -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);
});
}

Expand Down
1 change: 1 addition & 0 deletions tests/test-support/resolver.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Ember from 'ember';
import { setResolver } from 'ember-test-helpers';

var Resolver = Ember.DefaultResolver.extend({
Expand Down
12 changes: 6 additions & 6 deletions tests/wait-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');

Expand All @@ -70,15 +70,15 @@ 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');

Ember.run(component, 'set', 'internalValue', value + data);

Ember.run.later(function() {

jQuery.ajax('/whazzits', { cache: false })
$.ajax('/whazzits', { cache: false })
.then(function(data) {
if (component.isDestroyed) { return; }

Expand All @@ -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" },
Expand Down