diff --git a/.jshintrc b/.jshintrc index b9b9f7c81e4..3317474ba89 100644 --- a/.jshintrc +++ b/.jshintrc @@ -31,7 +31,22 @@ "PreloadStore", "Handlebars", "I18n", - "bootbox"], + "bootbox", + "module", + "integration", + "test", + "ok", + "expect", + "equal", + "blank", + "present", + "visit", + "count", + "exists", + "asyncTest", + "find", + "resolvingPromise", + "sinon"], "browser":true, "rhino":false, "devel":true, diff --git a/config/jshint.yml b/config/jshint.yml index 5f75dc0a21f..74439de04aa 100644 --- a/config/jshint.yml +++ b/config/jshint.yml @@ -77,6 +77,21 @@ predef: - bootbox - moment - _ + - module + - integration + - test + - ok + - expect + - equal + - blank + - present + - visit + - count + - exists + - asyncTest + - find + - resolvingPromise + - sinon browser: true # true if the standard browser globals should be predefined rhino: false # true if the Rhino environment globals should be predefined diff --git a/lib/discourse_iife.rb b/lib/discourse_iife.rb index 867c11b947a..c79bff4eeee 100644 --- a/lib/discourse_iife.rb +++ b/lib/discourse_iife.rb @@ -8,8 +8,9 @@ class DiscourseIIFE < Sprockets::Processor # Only discourse or admin paths return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/) - # Ignore the js helper + # Ignore the js helpers return data if (path =~ /test\_helper\.js/) + return data if (path =~ /javascripts\/helpers\//) # Ignore translations return data if (path =~ /\/translations/) diff --git a/test/javascripts/components/bbcode_test.js b/test/javascripts/components/bbcode_test.js index ee8253329c0..20b9ed117dc 100644 --- a/test/javascripts/components/bbcode_test.js +++ b/test/javascripts/components/bbcode_test.js @@ -1,4 +1,4 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true present:true md5:true */ +/*global md5:true */ module("Discourse.BBCode"); diff --git a/test/javascripts/components/click_track_test.js b/test/javascripts/components/click_track_test.js index e5af1a84c74..6cab96c7d81 100644 --- a/test/javascripts/components/click_track_test.js +++ b/test/javascripts/components/click_track_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true sinon:true blank:true */ - module("Discourse.ClickTrack", { setup: function() { diff --git a/test/javascripts/components/formatter_test.js b/test/javascripts/components/formatter_test.js index 1895ca24638..85b1b137ef1 100644 --- a/test/javascripts/components/formatter_test.js +++ b/test/javascripts/components/formatter_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true */ - module("Discourse.Formatter"); var format = "tiny"; diff --git a/test/javascripts/components/key_value_store_test.js b/test/javascripts/components/key_value_store_test.js index e6137a56efd..0ddf9652db0 100644 --- a/test/javascripts/components/key_value_store_test.js +++ b/test/javascripts/components/key_value_store_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true */ - var store = Discourse.KeyValueStore; module("Discourse.KeyValueStore", { diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index 19599f6bde2..4096e24fb7c 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -1,4 +1,4 @@ -/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true sanitizeHtml:true */ +/*global sanitizeHtml:true */ module("Discourse.Markdown"); diff --git a/test/javascripts/components/onebox_test.js b/test/javascripts/components/onebox_test.js index 3fcb376400c..63159c7442b 100644 --- a/test/javascripts/components/onebox_test.js +++ b/test/javascripts/components/onebox_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true resolvingPromise:true */ - module("Discourse.Onebox", { setup: function() { this.anchor = $("")[0]; diff --git a/test/javascripts/components/preload_store_test.js b/test/javascripts/components/preload_store_test.js index 36c056a7f7c..c6576380e4e 100644 --- a/test/javascripts/components/preload_store_test.js +++ b/test/javascripts/components/preload_store_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true equal:true count:true present:true asyncTest:true blank:true */ - module("Discourse.PreloadStore", { setup: function() { PreloadStore.store('bane', 'evil'); diff --git a/test/javascripts/components/utilities_test.js b/test/javascripts/components/utilities_test.js index 227af03096f..2f1d8ef1054 100644 --- a/test/javascripts/components/utilities_test.js +++ b/test/javascripts/components/utilities_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */ - module("Discourse.Utilities"); var utils = Discourse.Utilities; diff --git a/test/javascripts/helpers/assertions.js b/test/javascripts/helpers/assertions.js new file mode 100644 index 00000000000..3740920a208 --- /dev/null +++ b/test/javascripts/helpers/assertions.js @@ -0,0 +1,32 @@ +// Test helpers +var resolvingPromise = Ember.Deferred.promise(function (p) { + p.resolve(); +}) + +function exists(selector) { + return !!count(selector); +} + +function count(selector) { + return find(selector).length; +} + +function objBlank(obj) { + if (obj === undefined) return true; + + switch (typeof obj) { + case "string": + return obj.trim().length === 0; + case "object": + return $.isEmptyObject(obj); + } + return false; +} + +function present(obj, text) { + equal(objBlank(obj), false, text); +} + +function blank(obj, text) { + equal(objBlank(obj), true, text); +} \ No newline at end of file diff --git a/test/javascripts/helpers/qunit_helpers.js b/test/javascripts/helpers/qunit_helpers.js new file mode 100644 index 00000000000..b219aa79421 --- /dev/null +++ b/test/javascripts/helpers/qunit_helpers.js @@ -0,0 +1,11 @@ +function integration(name) { + module(name, { + setup: function() { + Ember.run(Discourse, Discourse.advanceReadiness); + }, + + teardown: function() { + Discourse.reset(); + } + }); +} \ No newline at end of file diff --git a/test/javascripts/integration/header_test.js b/test/javascripts/integration/header_test.js index 23a95a59024..3ed5d24905a 100644 --- a/test/javascripts/integration/header_test.js +++ b/test/javascripts/integration/header_test.js @@ -1,14 +1,4 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true */ - -module("Header", { - setup: function() { - Ember.run(Discourse, Discourse.advanceReadiness); - }, - - teardown: function() { - Discourse.reset(); - } -}); +integration("Header"); test("/", function() { diff --git a/test/javascripts/integration/list_topics_test.js b/test/javascripts/integration/list_topics_test.js index 5b94fdad4e8..4dda40d996b 100644 --- a/test/javascripts/integration/list_topics_test.js +++ b/test/javascripts/integration/list_topics_test.js @@ -1,14 +1,4 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true */ - -module("List Topics", { - setup: function() { - Ember.run(Discourse, Discourse.advanceReadiness); - }, - - teardown: function() { - Discourse.reset(); - } -}); +integration("List Topics"); test("/", function() { diff --git a/test/javascripts/mixins/presence_test.js b/test/javascripts/mixins/presence_test.js index abaf493c0ee..6ae3c48da56 100644 --- a/test/javascripts/mixins/presence_test.js +++ b/test/javascripts/mixins/presence_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true */ - module("Discourse.Presence"); var testObj = Em.Object.createWithMixins(Discourse.Presence, { diff --git a/test/javascripts/mixins/selected_posts_count_test.js b/test/javascripts/mixins/selected_posts_count_test.js index b6450b4adad..313da9e6362 100644 --- a/test/javascripts/mixins/selected_posts_count_test.js +++ b/test/javascripts/mixins/selected_posts_count_test.js @@ -1,4 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */ module("Discourse.SelectedPostsCount"); var buildTestObj = function(params, topicParams) { diff --git a/test/javascripts/models/category_test.js b/test/javascripts/models/category_test.js index c38da838651..9fd9d3037dc 100644 --- a/test/javascripts/models/category_test.js +++ b/test/javascripts/models/category_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */ - module("Discourse.Category"); test('slugFor', function(){ diff --git a/test/javascripts/models/composer_test.js b/test/javascripts/models/composer_test.js index 4cf15fac0be..17f415a18c5 100644 --- a/test/javascripts/models/composer_test.js +++ b/test/javascripts/models/composer_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */ - module("Discourse.Composer"); diff --git a/test/javascripts/models/nav_item_test.js b/test/javascripts/models/nav_item_test.js index 23f0a75c478..ecc6763c036 100644 --- a/test/javascripts/models/nav_item_test.js +++ b/test/javascripts/models/nav_item_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */ - module("Discourse.NavItem", { setup: function() { this.site = Discourse.Site.instance(); diff --git a/test/javascripts/models/report_test.js b/test/javascripts/models/report_test.js index 2544d2e1c1c..58d8e9ca78b 100644 --- a/test/javascripts/models/report_test.js +++ b/test/javascripts/models/report_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true blank:true */ - module("Discourse.Report"); function reportWithData(data) { diff --git a/test/javascripts/models/site_test.js b/test/javascripts/models/site_test.js index 9a9e96ceb54..7f08c211cbb 100644 --- a/test/javascripts/models/site_test.js +++ b/test/javascripts/models/site_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true present:true equal:true */ - module("Discourse.Site"); test('instance', function(){ diff --git a/test/javascripts/models/user_action_test.js b/test/javascripts/models/user_action_test.js index 567c0271620..49a5c030a0c 100644 --- a/test/javascripts/models/user_action_test.js +++ b/test/javascripts/models/user_action_test.js @@ -1,5 +1,3 @@ -/*global module:true test:true ok:true visit:true expect:true exists:true count:true present:true equal:true */ - module("Discourse.UserAction"); test("collapsing likes", function () { diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index 7689a0ad317..d40c4903348 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -36,11 +36,12 @@ //= require sinon-1.7.1.js //= require sinon-qunit-1.0.0.js +//= require helpers/qunit_helpers +//= require helpers/assertions +//= require_tree ./fixtures //= require_tree . //= require_self -//= require_tree ./fixtures - // sinon settings sinon.config = { injectIntoThis: true, @@ -65,35 +66,3 @@ Discourse.Router.map(function() { return Discourse.routeBuilder.call(this); }); -// Test helpers -var resolvingPromise = Ember.Deferred.promise(function (p) { - p.resolve(); -}) - -function exists(selector) { - return !!count(selector); -} - -function count(selector) { - return find(selector).length; -} - -function objBlank(obj) { - if (obj === undefined) return true; - - switch (typeof obj) { - case "string": - return obj.trim().length === 0; - case "object": - return $.isEmptyObject(obj); - } - return false; -} - -function present(obj, text) { - equal(objBlank(obj), false, text); -} - -function blank(obj, text) { - equal(objBlank(obj), true, text); -}