mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 09:17:15 +08:00
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:
@ -2,10 +2,10 @@ import { registerHelpers } from 'discourse-common/lib/helpers';
|
|||||||
|
|
||||||
export function autoLoadModules(container, registry) {
|
export function autoLoadModules(container, registry) {
|
||||||
Object.keys(requirejs.entries).forEach(entry => {
|
Object.keys(requirejs.entries).forEach(entry => {
|
||||||
if ((/\/helpers\//).test(entry)) {
|
if ((/\/helpers\//).test(entry) && !(/-test/).test(entry)) {
|
||||||
requirejs(entry, null, null, true);
|
requirejs(entry, null, null, true);
|
||||||
}
|
}
|
||||||
if ((/\/widgets\//).test(entry)) {
|
if ((/\/widgets\//).test(entry) && !(/-test/).test(entry)) {
|
||||||
requirejs(entry, null, null, true);
|
requirejs(entry, null, null, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,28 +2,29 @@
|
|||||||
# running it anywhere else will likely fail
|
# running it anywhere else will likely fail
|
||||||
#
|
#
|
||||||
# Environment Variables (specific to this rake task)
|
# 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
|
# => 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
|
# => 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
|
# => JS_ONLY set to 1 to skip all rspec tests
|
||||||
# => BISECT set to 1 to run rspec --bisect
|
# => SINGLE_PLUGIN set to plugin name to only run plugin-specific rspec tests (you'll probably want to SKIP_CORE as well)
|
||||||
# => RSPEC_SEED set to seed to use for rspec tests
|
# => 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)
|
# 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
|
# => 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"
|
# this can also be set to a branch, e.g. "origin/tests-passed"
|
||||||
#
|
#
|
||||||
# Example usage:
|
# Example usage:
|
||||||
# Run all core tests:
|
# Run all core and plugin tests:
|
||||||
# docker run discourse/discourse_test:release
|
# docker run discourse/discourse_test:release
|
||||||
# Run only rspec tests:
|
# Run only rspec tests:
|
||||||
# docker run -e RUBY_ONLY=1 discourse/discourse_test:release
|
# docker run -e RUBY_ONLY=1 discourse/discourse_test:release
|
||||||
# Run all core and plugin tests (plugin mounted from host filesystem):
|
# Run all plugin tests (with a 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
|
# 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)
|
def run_or_fail(command)
|
||||||
pid = Process.spawn(command)
|
pid = Process.spawn(command)
|
||||||
@ -74,7 +75,7 @@ task 'docker:test' do
|
|||||||
@good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
|
@good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV["LOAD_PLUGINS"]
|
unless ENV["SKIP_PLUGINS"]
|
||||||
if ENV["SINGLE_PLUGIN"]
|
if ENV["SINGLE_PLUGIN"]
|
||||||
@good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
|
@good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
|
||||||
else
|
else
|
||||||
@ -85,13 +86,22 @@ task 'docker:test' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
unless ENV["RUBY_ONLY"]
|
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 app/assets/javascripts")
|
||||||
@good &&= run_or_fail("eslint --ext .es6 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 --ext .es6 test/javascripts")
|
||||||
@good &&= run_or_fail("eslint test/javascripts")
|
@good &&= run_or_fail("eslint test/javascripts")
|
||||||
|
@good &&= run_or_fail("bundle exec rake qunit:test['600000']")
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
|
@ -96,3 +96,19 @@ task 'plugin:spec', :plugin do |t, args|
|
|||||||
abort "No specs found."
|
abort "No specs found."
|
||||||
end
|
end
|
||||||
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 = {}
|
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?
|
options[arg] = ENV[arg.upcase] if ENV[arg.upcase].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
if options.present?
|
if options.present?
|
||||||
cmd += "?#{options.to_query.gsub('+', '%20')}"
|
cmd += "?#{options.to_query.gsub('+', '%20').gsub("&", '\\\&')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if args[:timeout].present?
|
if args[:timeout].present?
|
||||||
|
@ -138,10 +138,25 @@ window.asyncTestDiscourse = helpers.asyncTestDiscourse;
|
|||||||
window.controllerFor = helpers.controllerFor;
|
window.controllerFor = helpers.controllerFor;
|
||||||
window.fixture = helpers.fixture;
|
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) {
|
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);
|
require(entry, null, null, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
resetSite();
|
resetSite();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user