diff --git a/app/assets/javascripts/discourse/initializers/auto-load-modules.js.es6 b/app/assets/javascripts/discourse/initializers/auto-load-modules.js.es6 index b793cb742c6..943c330a107 100644 --- a/app/assets/javascripts/discourse/initializers/auto-load-modules.js.es6 +++ b/app/assets/javascripts/discourse/initializers/auto-load-modules.js.es6 @@ -2,10 +2,10 @@ import { registerHelpers } from 'discourse-common/lib/helpers'; export function autoLoadModules(container, registry) { Object.keys(requirejs.entries).forEach(entry => { - if ((/\/helpers\//).test(entry)) { + if ((/\/helpers\//).test(entry) && !(/-test/).test(entry)) { requirejs(entry, null, null, true); } - if ((/\/widgets\//).test(entry)) { + if ((/\/widgets\//).test(entry) && !(/-test/).test(entry)) { requirejs(entry, null, null, true); } }); diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index bb525b8f518..80af4e74d74 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -2,28 +2,29 @@ # running it anywhere else will likely fail # # Environment Variables (specific to this rake task) -# => SKIP_CORE set to 1 to skip core rspec tests +# => SKIP_CORE set to 1 to skip core tests (rspec and qunit) +# => SKIP_PLUGINS set to 1 to skip plugin tests (rspec and qunit) # => INSTALL_OFFICIAL_PLUGINS set to 1 to install all core plugins before running tests -# => JS_ONLY set to 1 to skip all rspec tests # => RUBY_ONLY set to 1 to skip all qunit tests -# => SINGLE_PLUGIN set to plugin name to skip eslint, and only run plugin-specific rspec tests -# => BISECT set to 1 to run rspec --bisect -# => RSPEC_SEED set to seed to use for rspec tests +# => JS_ONLY set to 1 to skip all rspec tests +# => SINGLE_PLUGIN set to plugin name to only run plugin-specific rspec tests (you'll probably want to SKIP_CORE as well) +# => BISECT set to 1 to run rspec --bisect (applies to core rspec tests only) +# => RSPEC_SEED set to seed to use for rspec tests (applies to core rspec tests only) # # Other useful environment variables (not specific to this rake task) -# => LOAD_PLUGINS set to 1 to load all plugins when running tests -# => MODULE set to a qunit module name to run only those tests -# => FILTER set to a qunit filter string to run only those tests # => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse # this can also be set to a branch, e.g. "origin/tests-passed" # # Example usage: -# Run all core tests: +# Run all core and plugin tests: # docker run discourse/discourse_test:release # Run only rspec tests: # docker run -e RUBY_ONLY=1 discourse/discourse_test:release -# Run all core and plugin tests (plugin mounted from host filesystem): -# docker run -e LOAD_PLUGINS=1 -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release +# Run all plugin tests (with a plugin mounted from host filesystem): +# docker run -e SKIP_CORE=1 -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release +# Run tests for a specific plugin (with a plugin mounted from host filesystem): +# docker run -e SKIP_CORE=1 SINGLE_PLUGIN='my-awesome-plugin' -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release + def run_or_fail(command) pid = Process.spawn(command) @@ -74,7 +75,7 @@ task 'docker:test' do @good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip) end - if ENV["LOAD_PLUGINS"] + unless ENV["SKIP_PLUGINS"] if ENV["SINGLE_PLUGIN"] @good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']") else @@ -85,13 +86,22 @@ task 'docker:test' do end unless ENV["RUBY_ONLY"] - unless ENV["SINGLE_PLUGIN"] + unless ENV["SKIP_CORE"] @good &&= run_or_fail("eslint app/assets/javascripts") @good &&= run_or_fail("eslint --ext .es6 app/assets/javascripts") @good &&= run_or_fail("eslint --ext .es6 test/javascripts") @good &&= run_or_fail("eslint test/javascripts") + @good &&= run_or_fail("bundle exec rake qunit:test['600000']") end - @good &&= run_or_fail("LOAD_PLUGINS=#{ENV["LOAD_PLUGINS"]} bundle exec rake qunit:test['600000']") + + unless ENV["SKIP_PLUGINS"] + if ENV["SINGLE_PLUGIN"] + @good &&= run_or_fail("bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','600000']") + else + @good &&= run_or_fail("bundle exec rake plugin:qunit['*','600000']") + end + end + end ensure diff --git a/lib/tasks/plugin.rake b/lib/tasks/plugin.rake index f36628c30c6..9666ed747c4 100644 --- a/lib/tasks/plugin.rake +++ b/lib/tasks/plugin.rake @@ -96,3 +96,19 @@ task 'plugin:spec', :plugin do |t, args| abort "No specs found." end end + +desc 'run plugin qunit tests' +task 'plugin:qunit', [:plugin, :timeout] do |t, args| + args.with_defaults(plugin: "*") + + ENV['LOAD_PLUGINS'] = '1' + ENV['QUNIT_SKIP_CORE'] = '1' + if args[:plugin] == "*" + puts "Running qunit tests for all plugins" + else + puts "Running qunit tests for #{args[:plugin]}" + ENV['QUNIT_SINGLE_PLUGIN'] = args[:plugin] + end + + Rake::Task["qunit:test"].invoke(args[:timeout]) +end diff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rake index 728cf1a8b28..af08cb58565 100644 --- a/lib/tasks/qunit.rake +++ b/lib/tasks/qunit.rake @@ -39,12 +39,12 @@ task "qunit:test", [:timeout] => :environment do |_, args| options = {} - %w{module filter}.each do |arg| + %w{module filter qunit_skip_core qunit_single_plugin}.each do |arg| options[arg] = ENV[arg.upcase] if ENV[arg.upcase].present? end if options.present? - cmd += "?#{options.to_query.gsub('+', '%20')}" + cmd += "?#{options.to_query.gsub('+', '%20').gsub("&", '\\\&')}" end if args[:timeout].present? diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index 3af1c2b6a73..e775197aaa6 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -138,10 +138,25 @@ window.asyncTestDiscourse = helpers.asyncTestDiscourse; window.controllerFor = helpers.controllerFor; window.fixture = helpers.fixture; +function getUrlParameter(name) { + name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); + var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); + var results = regex.exec(location.search); + return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); +}; + +var skipCore = (getUrlParameter('qunit_skip_core') == '1'); +var pluginPath = getUrlParameter('qunit_single_plugin') ? "\/"+getUrlParameter('qunit_single_plugin')+"\/" : "\/plugins\/"; + Object.keys(requirejs.entries).forEach(function(entry) { - if ((/\-test/).test(entry)) { + var isTest = (/\-test/).test(entry); + var regex = new RegExp(pluginPath) + var isPlugin = regex.test(entry); + + if (isTest && (!skipCore || isPlugin)) { require(entry, null, null, true); } }); + resetSite();