Qunit plugin rake tasks (#4985)
* Allow running specific plugin tests using ENV variables * Add a `rake plugin:qunit` task to match the existing `rake plugin:spec` task * Improve docker.rake to allow running specific plugin qunit tests * Purge cache before and after qunit tests * Stop module auto-loader trying to auto-load tests * Use URL query parameters to pass config into Qunit, avoiding caching issues * Oops, searchParams doesn’t work in phantomJS. Parse the URL manually. * Escape ampersands before passing URL to phantomJS, otherwise multiple parameters go wrong
This commit is contained in:
parent
917d186303
commit
febd7621ea
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue