mirror of
https://github.com/discourse/discourse.git
synced 2025-06-16 07:31:23 +08:00
DEV: Remove ember-cli flags from the backend (#17147)
…and other auxiliary code * Restore `QUNIT_EMBER_CLI` flag warning * Add `ALLOW_EMBER_CLI_PROXY_BYPASS`
This commit is contained in:
4
.github/workflows/tests.yml
vendored
4
.github/workflows/tests.yml
vendored
@ -153,9 +153,9 @@ jobs:
|
|||||||
if: matrix.build_type == 'backend' && matrix.target == 'plugins'
|
if: matrix.build_type == 'backend' && matrix.target == 'plugins'
|
||||||
run: bin/rake plugin:spec
|
run: bin/rake plugin:spec
|
||||||
|
|
||||||
- name: Plugin QUnit (Ember CLI)
|
- name: Plugin QUnit
|
||||||
if: matrix.build_type == 'frontend' && (matrix.target == 'plugins' || matrix.target == 'core-plugins')
|
if: matrix.build_type == 'frontend' && (matrix.target == 'plugins' || matrix.target == 'core-plugins')
|
||||||
run: QUNIT_EMBER_CLI=1 bin/rake plugin:qunit['*','1200000']
|
run: bin/rake plugin:qunit['*','1200000']
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
|
||||||
- name: Check Annotations
|
- name: Check Annotations
|
||||||
|
@ -102,7 +102,7 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ember_cli_required?
|
def ember_cli_required?
|
||||||
Rails.env.development? && ENV['NO_EMBER_CLI'] != '1' && request.headers['X-Discourse-Ember-CLI'] != 'true'
|
Rails.env.development? && ENV["ALLOW_EMBER_CLI_PROXY_BYPASS"] != "1" && request.headers['X-Discourse-Ember-CLI'] != 'true'
|
||||||
end
|
end
|
||||||
|
|
||||||
def application_layout
|
def application_layout
|
||||||
|
@ -8,16 +8,6 @@ class QunitController < ApplicationController
|
|||||||
}
|
}
|
||||||
layout false
|
layout false
|
||||||
|
|
||||||
def is_ember_cli_proxy?
|
|
||||||
request.headers["HTTP_X_DISCOURSE_EMBER_CLI"] == "true"
|
|
||||||
end
|
|
||||||
|
|
||||||
# only used in non-ember-cli test / dev
|
|
||||||
def index
|
|
||||||
raise Discourse::NotFound.new if is_ember_cli_proxy? || EmberCli.enabled?
|
|
||||||
raise Discourse::InvalidAccess.new if Rails.env.production?
|
|
||||||
end
|
|
||||||
|
|
||||||
def theme
|
def theme
|
||||||
raise Discourse::NotFound.new if !can_see_theme_qunit?
|
raise Discourse::NotFound.new if !can_see_theme_qunit?
|
||||||
|
|
||||||
|
@ -136,11 +136,9 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def preload_script(script)
|
def preload_script(script)
|
||||||
script = EmberCli.transform_name(script)
|
|
||||||
|
|
||||||
scripts = [script]
|
scripts = [script]
|
||||||
|
|
||||||
if EmberCli.enabled? && chunks = EmberCli.script_chunks[script]
|
if chunks = EmberCli.script_chunks[script]
|
||||||
scripts.push(*chunks)
|
scripts.push(*chunks)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,33 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module QunitHelper
|
module QunitHelper
|
||||||
|
|
||||||
def vendor_theme_tests
|
|
||||||
if EmberCli.enabled?
|
|
||||||
preload_script("vendor")
|
|
||||||
else
|
|
||||||
preload_script("vendor-theme-tests")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def support_bundles
|
|
||||||
result = [
|
|
||||||
preload_script("discourse/tests/test-support-rails"),
|
|
||||||
preload_script("discourse/tests/test-helpers-rails")
|
|
||||||
].join("\n").html_safe
|
|
||||||
end
|
|
||||||
|
|
||||||
def boot_bundles
|
|
||||||
result = []
|
|
||||||
if EmberCli.enabled?
|
|
||||||
result << preload_script("scripts/discourse-test-listen-boot")
|
|
||||||
result << preload_script("scripts/discourse-boot")
|
|
||||||
else
|
|
||||||
result << preload_script("discourse/tests/test_starter")
|
|
||||||
end
|
|
||||||
result.join("\n").html_safe
|
|
||||||
end
|
|
||||||
|
|
||||||
def theme_tests
|
def theme_tests
|
||||||
theme = Theme.find_by(id: request.env[:resolved_theme_id])
|
theme = Theme.find_by(id: request.env[:resolved_theme_id])
|
||||||
return "" if theme.blank?
|
return "" if theme.blank?
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<%= preload_script_url ExtraLocalesController.url('overrides') %>
|
<%= preload_script_url ExtraLocalesController.url('overrides') %>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
<%= preload_script "vendor" %>
|
<%= preload_script "vendor" %>
|
||||||
<%= preload_script "application" %>
|
<%= preload_script "discourse" %>
|
||||||
<%- Discourse.find_plugin_js_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, request: request).each do |file| %>
|
<%- Discourse.find_plugin_js_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, request: request).each do |file| %>
|
||||||
<%= preload_script file %>
|
<%= preload_script file %>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
@ -57,7 +57,6 @@
|
|||||||
<meta name="apple-itunes-app" content="app-id=<%= SiteSetting.ios_app_id %><%= ios_app_argument %>">
|
<meta name="apple-itunes-app" content="app-id=<%= SiteSetting.ios_app_id %><%= ios_app_argument %>">
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
||||||
|
|
||||||
<%= yield :head %>
|
<%= yield :head %>
|
||||||
|
|
||||||
<%= build_plugin_html 'server:before-head-close' %>
|
<%= build_plugin_html 'server:before-head-close' %>
|
||||||
@ -118,7 +117,6 @@
|
|||||||
</form>
|
</form>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
<script defer src="<%= script_asset_path "start-discourse" %>"></script>
|
<script defer src="<%= script_asset_path "start-discourse" %>"></script>
|
||||||
|
|
||||||
<%= yield :data %>
|
<%= yield :data %>
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>QUnit Test Runner</title>
|
|
||||||
<%= discourse_color_scheme_stylesheets %>
|
|
||||||
<%= discourse_stylesheet_link_tag(:desktop, theme_id: nil) %>
|
|
||||||
<%= discourse_stylesheet_link_tag(:test_helper, theme_id: nil) %>
|
|
||||||
<%= preload_script "locales/#{I18n.locale}" %>
|
|
||||||
<%= preload_script "vendor" %>
|
|
||||||
<%= preload_script "application" %>
|
|
||||||
<%= preload_script "admin" %>
|
|
||||||
<%= preload_script "wizard" %>
|
|
||||||
<%= preload_script "discourse/tests/test-support-rails" %>
|
|
||||||
<%= preload_script "discourse/tests/test-helpers-rails" %>
|
|
||||||
<%= preload_script "discourse/tests/active-plugins" %>
|
|
||||||
<%= preload_script "discourse/tests/core-tests" %>
|
|
||||||
<%= preload_script "discourse/tests/plugin-tests" %>
|
|
||||||
<%= preload_script "discourse/tests/test_starter" %>
|
|
||||||
<%= csrf_meta_tags %>
|
|
||||||
<meta property="og:title" content="">
|
|
||||||
<meta property="og:url" content="">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="qunit"></div>
|
|
||||||
<div id="qunit-fixture"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -7,12 +7,13 @@
|
|||||||
<%= discourse_stylesheet_link_tag(:desktop, theme_id: nil) %>
|
<%= discourse_stylesheet_link_tag(:desktop, theme_id: nil) %>
|
||||||
<%= discourse_stylesheet_link_tag(:test_helper, theme_id: nil) %>
|
<%= discourse_stylesheet_link_tag(:test_helper, theme_id: nil) %>
|
||||||
<%= preload_script "locales/#{I18n.locale}" %>
|
<%= preload_script "locales/#{I18n.locale}" %>
|
||||||
<%= vendor_theme_tests %>
|
<%= preload_script "vendor" %>
|
||||||
<%= preload_script "application" %>
|
<%= preload_script "discourse" %>
|
||||||
<%= preload_script "admin" %>
|
<%= preload_script "admin" %>
|
||||||
<%= preload_script "discourse/tests/active-plugins" %>
|
<%= preload_script "discourse/tests/active-plugins" %>
|
||||||
<%= preload_script "admin-plugins" %>
|
<%= preload_script "admin-plugins" %>
|
||||||
<%= support_bundles %>
|
<%= preload_script "test-support" %>
|
||||||
|
<%= preload_script "test-helpers" %>
|
||||||
<%= theme_translations_lookup %>
|
<%= theme_translations_lookup %>
|
||||||
<%= theme_js_lookup %>
|
<%= theme_js_lookup %>
|
||||||
<%= theme_lookup("head_tag") %>
|
<%= theme_lookup("head_tag") %>
|
||||||
@ -33,12 +34,7 @@
|
|||||||
<%- end %>
|
<%- end %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%- if !@suggested_themes %>
|
<%- if @suggested_themes %>
|
||||||
<%- if !EmberCli.enabled? %>
|
|
||||||
<div id="qunit"></div>
|
|
||||||
<div id="qunit-fixture"></div>
|
|
||||||
<%- end %>
|
|
||||||
<%- else %>
|
|
||||||
<h2>Theme QUnit Test Runner</h2>
|
<h2>Theme QUnit Test Runner</h2>
|
||||||
<%- if @suggested_themes.size == 0 %>
|
<%- if @suggested_themes.size == 0 %>
|
||||||
<p>Cannot find any theme tests.</p>
|
<p>Cannot find any theme tests.</p>
|
||||||
@ -51,6 +47,7 @@
|
|||||||
<%- end %>
|
<%- end %>
|
||||||
</body>
|
</body>
|
||||||
<%- if !@suggested_themes %>
|
<%- if !@suggested_themes %>
|
||||||
<%= boot_bundles %>
|
<%= preload_script "scripts/discourse-test-listen-boot" %>
|
||||||
|
<%= preload_script "scripts/discourse-boot" %>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
</html>
|
</html>
|
||||||
|
@ -188,13 +188,11 @@ module Discourse
|
|||||||
Sprockets.register_mime_type 'application/javascript', extensions: ['.js', '.es6', '.js.es6'], charset: :unicode
|
Sprockets.register_mime_type 'application/javascript', extensions: ['.js', '.es6', '.js.es6'], charset: :unicode
|
||||||
Sprockets.register_postprocessor 'application/javascript', DiscourseJsProcessor
|
Sprockets.register_postprocessor 'application/javascript', DiscourseJsProcessor
|
||||||
|
|
||||||
if EmberCli.enabled?
|
Discourse::Application.initializer :prepend_ember_assets do |app|
|
||||||
Discourse::Application.initializer :prepend_ember_assets do |app|
|
# Needs to be in its own initializer so it runs after the append_assets_path initializer defined by Sprockets
|
||||||
# Needs to be in its own initializer so it runs after the append_assets_path initializer defined by Sprockets
|
app.config.assets.paths.unshift "#{app.config.root}/app/assets/javascripts/discourse/dist/assets"
|
||||||
app.config.assets.paths.unshift "#{app.config.root}/app/assets/javascripts/discourse/dist/assets"
|
Sprockets.unregister_postprocessor 'application/javascript', Sprockets::Rails::SourcemappingUrlProcessor
|
||||||
Sprockets.unregister_postprocessor 'application/javascript', Sprockets::Rails::SourcemappingUrlProcessor
|
Sprockets.register_postprocessor 'application/javascript', DiscourseSourcemappingUrlProcessor
|
||||||
Sprockets.register_postprocessor 'application/javascript', DiscourseSourcemappingUrlProcessor
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'discourse_redis'
|
require 'discourse_redis'
|
||||||
|
@ -22,9 +22,12 @@ Rails.application.config.assets.precompile += [lambda do |filename, path|
|
|||||||
end]
|
end]
|
||||||
|
|
||||||
Rails.application.config.assets.precompile += %w{
|
Rails.application.config.assets.precompile += %w{
|
||||||
|
discourse.js
|
||||||
vendor.js
|
vendor.js
|
||||||
admin.js
|
admin.js
|
||||||
wizard.js
|
wizard.js
|
||||||
|
test-support.js
|
||||||
|
test-helpers.js
|
||||||
browser-detect.js
|
browser-detect.js
|
||||||
browser-update.js
|
browser-update.js
|
||||||
break_string.js
|
break_string.js
|
||||||
@ -44,18 +47,11 @@ Rails.application.config.assets.precompile += %w{
|
|||||||
onpopstate-handler.js
|
onpopstate-handler.js
|
||||||
embed-application.js
|
embed-application.js
|
||||||
admin-plugins.js
|
admin-plugins.js
|
||||||
|
scripts/discourse-test-listen-boot
|
||||||
|
scripts/discourse-boot
|
||||||
}
|
}
|
||||||
|
|
||||||
if EmberCli.enabled?
|
Rails.application.config.assets.precompile += EmberCli::ASSETS.map { |name| name.sub('.js', '.map') }
|
||||||
Rails.application.config.assets.precompile += %w{
|
|
||||||
discourse.js
|
|
||||||
test-support.js
|
|
||||||
test-helpers.js
|
|
||||||
scripts/discourse-test-listen-boot
|
|
||||||
scripts/discourse-boot
|
|
||||||
}
|
|
||||||
Rails.application.config.assets.precompile += EmberCli::ASSETS.map { |name| name.sub('.js', '.map') }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Precompile all available locales
|
# Precompile all available locales
|
||||||
unless GlobalSetting.try(:omit_base_locales)
|
unless GlobalSetting.try(:omit_base_locales)
|
||||||
|
@ -1001,10 +1001,6 @@ Discourse::Application.routes.draw do
|
|||||||
get "/safe-mode" => "safe_mode#index"
|
get "/safe-mode" => "safe_mode#index"
|
||||||
post "/safe-mode" => "safe_mode#enter", as: "safe_mode_enter"
|
post "/safe-mode" => "safe_mode#enter", as: "safe_mode_enter"
|
||||||
|
|
||||||
unless Rails.env.production?
|
|
||||||
get "/qunit" => "qunit#index"
|
|
||||||
get "/wizard/qunit" => "wizard#qunit"
|
|
||||||
end
|
|
||||||
get "/theme-qunit" => "qunit#theme"
|
get "/theme-qunit" => "qunit#theme"
|
||||||
|
|
||||||
post "/push_notifications/subscribe" => "push_notification#subscribe"
|
post "/push_notifications/subscribe" => "push_notification#subscribe"
|
||||||
|
@ -10,19 +10,6 @@ module EmberCli
|
|||||||
vendor.js
|
vendor.js
|
||||||
)
|
)
|
||||||
|
|
||||||
ALIASES ||= {
|
|
||||||
"application" => "discourse",
|
|
||||||
"discourse/tests/test-support-rails" => "test-support",
|
|
||||||
"discourse/tests/test-helpers-rails" => "test-helpers"
|
|
||||||
}
|
|
||||||
|
|
||||||
def self.enabled?
|
|
||||||
if !Rails.env.production? && ENV["EMBER_CLI_PROD_ASSETS"] == "0"
|
|
||||||
STDERR.puts "The 'legacy' ember environment is discontinued. Running with ember-cli assets. Remove the EMBER_CLI_PROD_ASSETS=0 flag."
|
|
||||||
end
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.script_chunks
|
def self.script_chunks
|
||||||
return @@chunk_infos if defined? @@chunk_infos
|
return @@chunk_infos if defined? @@chunk_infos
|
||||||
|
|
||||||
@ -40,17 +27,7 @@ module EmberCli
|
|||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Some assets have changed name following the switch
|
|
||||||
# to ember-cli. When the switch is complete, we can
|
|
||||||
# drop this method and update all the references
|
|
||||||
# to use the new names
|
|
||||||
def self.transform_name(name)
|
|
||||||
return name if !enabled?
|
|
||||||
ALIASES[name] || name
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.is_ember_cli_asset?(name)
|
def self.is_ember_cli_asset?(name)
|
||||||
return false if !enabled?
|
|
||||||
ASSETS.include?(name) || name.start_with?("chunk.")
|
ASSETS.include?(name) || name.start_with?("chunk.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
if !defined?(EMBER_CLI)
|
|
||||||
EMBER_CLI = EmberCli.enabled?
|
|
||||||
end
|
|
||||||
|
|
||||||
if ENV["EMBER_CLI_PROD_ASSETS"] == "0"
|
|
||||||
STDERR.puts "The 'legacy' ember environment is discontinued. Compiling with ember-cli assets..."
|
|
||||||
end
|
|
||||||
|
|
||||||
task 'assets:precompile:before' do
|
task 'assets:precompile:before' do
|
||||||
|
|
||||||
require 'uglifier'
|
require 'uglifier'
|
||||||
require 'open3'
|
require 'open3'
|
||||||
|
|
||||||
@ -17,7 +8,7 @@ task 'assets:precompile:before' do
|
|||||||
raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets"
|
raise "rake assets:precompile should only be run in RAILS_ENV=production, you are risking unminified assets"
|
||||||
end
|
end
|
||||||
|
|
||||||
if EMBER_CLI && !(ENV["EMBER_CLI_COMPILE_DONE"] == "1")
|
if ENV["EMBER_CLI_COMPILE_DONE"] != "1"
|
||||||
compile_command = "NODE_OPTIONS='--max-old-space-size=2048' yarn --cwd app/assets/javascripts/discourse run ember build -prod"
|
compile_command = "NODE_OPTIONS='--max-old-space-size=2048' yarn --cwd app/assets/javascripts/discourse run ember build -prod"
|
||||||
only_assets_precompile_remaining = (ARGV.last == "assets:precompile")
|
only_assets_precompile_remaining = (ARGV.last == "assets:precompile")
|
||||||
|
|
||||||
@ -55,12 +46,10 @@ task 'assets:precompile:before' do
|
|||||||
require 'sprockets'
|
require 'sprockets'
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
|
|
||||||
if EMBER_CLI
|
# Add ember cli chunks
|
||||||
# Add ember cli chunks
|
Rails.configuration.assets.precompile.push(
|
||||||
Rails.configuration.assets.precompile.push(
|
*EmberCli.script_chunks.values.flatten.flat_map { |name| ["#{name}.js", "#{name}.map"] }
|
||||||
*EmberCli.script_chunks.values.flatten.flat_map { |name| ["#{name}.js", "#{name}.map"] }
|
)
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
task 'assets:precompile:css' => 'environment' do
|
task 'assets:precompile:css' => 'environment' do
|
||||||
@ -102,7 +91,6 @@ task 'assets:flush_sw' => 'environment' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def is_ember_cli_asset?(name)
|
def is_ember_cli_asset?(name)
|
||||||
return false if !EMBER_CLI
|
|
||||||
%w(
|
%w(
|
||||||
discourse.js
|
discourse.js
|
||||||
admin.js
|
admin.js
|
||||||
|
@ -214,9 +214,9 @@ task 'docker:test' do
|
|||||||
|
|
||||||
unless ENV["SKIP_PLUGINS"]
|
unless ENV["SKIP_PLUGINS"]
|
||||||
if ENV["SINGLE_PLUGIN"]
|
if ENV["SINGLE_PLUGIN"]
|
||||||
@good &&= run_or_fail("CI=1 QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','#{js_timeout}']")
|
@good &&= run_or_fail("CI=1 bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','#{js_timeout}']")
|
||||||
else
|
else
|
||||||
@good &&= run_or_fail("CI=1 QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['*','#{js_timeout}']")
|
@good &&= run_or_fail("CI=1 bundle exec rake plugin:qunit['*','#{js_timeout}']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,24 +28,18 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV['QUNIT_EMBER_CLI'] == "0"
|
if ENV["QUNIT_EMBER_CLI"] == "0"
|
||||||
puts "The 'legacy' ember environment is discontinued - running tests with ember-cli assets..."
|
puts "The 'legacy' ember environment is discontinued - running tests with ember-cli assets..."
|
||||||
end
|
end
|
||||||
|
|
||||||
ember_cli = true
|
|
||||||
|
|
||||||
port = ENV['TEST_SERVER_PORT'] || 60099
|
port = ENV['TEST_SERVER_PORT'] || 60099
|
||||||
while !port_available? port
|
while !port_available? port
|
||||||
port += 1
|
port += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if ember_cli
|
unicorn_port = 60098
|
||||||
unicorn_port = 60098
|
while unicorn_port == port || !port_available?(unicorn_port)
|
||||||
while unicorn_port == port || !port_available?(unicorn_port)
|
unicorn_port += 1
|
||||||
unicorn_port += 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
unicorn_port = port
|
|
||||||
end
|
end
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
@ -61,10 +55,6 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
|
|||||||
"UNICORN_TIMEOUT" => "90",
|
"UNICORN_TIMEOUT" => "90",
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ember_cli
|
|
||||||
env["EMBER_CLI_PROD_ASSETS"] = "0"
|
|
||||||
end
|
|
||||||
|
|
||||||
pid = Process.spawn(
|
pid = Process.spawn(
|
||||||
env,
|
env,
|
||||||
"#{Rails.root}/bin/unicorn",
|
"#{Rails.root}/bin/unicorn",
|
||||||
@ -75,7 +65,6 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
|
|||||||
success = true
|
success = true
|
||||||
test_path = "#{Rails.root}/test"
|
test_path = "#{Rails.root}/test"
|
||||||
qunit_path = args[:qunit_path]
|
qunit_path = args[:qunit_path]
|
||||||
qunit_path ||= "/qunit" if !ember_cli
|
|
||||||
|
|
||||||
options = { seed: (ENV["QUNIT_SEED"] || Random.new.seed), hidepassed: 1 }
|
options = { seed: (ENV["QUNIT_SEED"] || Random.new.seed), hidepassed: 1 }
|
||||||
|
|
||||||
@ -96,9 +85,10 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
|
|||||||
|
|
||||||
# wait for server to accept connections
|
# wait for server to accept connections
|
||||||
require 'net/http'
|
require 'net/http'
|
||||||
warmup_path = ember_cli ? "/assets/discourse/tests/active-plugins.js" : "/qunit"
|
warmup_path = "/assets/discourse/tests/active-plugins.js"
|
||||||
uri = URI("http://localhost:#{unicorn_port}/#{warmup_path}")
|
uri = URI("http://localhost:#{unicorn_port}/#{warmup_path}")
|
||||||
puts "Warming up Rails server"
|
puts "Warming up Rails server"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Net::HTTP.get(uri)
|
Net::HTTP.get(uri)
|
||||||
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, Net::ReadTimeout, EOFError
|
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, Net::ReadTimeout, EOFError
|
||||||
@ -109,24 +99,20 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
|
|||||||
end
|
end
|
||||||
puts "Rails server is warmed up"
|
puts "Rails server is warmed up"
|
||||||
|
|
||||||
if ember_cli
|
cmd = ["env", "UNICORN_PORT=#{unicorn_port}"]
|
||||||
cmd = ["env", "UNICORN_PORT=#{unicorn_port}"]
|
|
||||||
if qunit_path
|
if qunit_path
|
||||||
# Bypass `ember test` - it only works properly for the `/tests` path.
|
# Bypass `ember test` - it only works properly for the `/tests` path.
|
||||||
# We have to trigger a `build` manually so that JS is available for rails to serve.
|
# We have to trigger a `build` manually so that JS is available for rails to serve.
|
||||||
system("yarn", "ember", "build", chdir: "#{Rails.root}/app/assets/javascripts/discourse")
|
system("yarn", "ember", "build", chdir: "#{Rails.root}/app/assets/javascripts/discourse")
|
||||||
test_page = "#{qunit_path}?#{query}&testem=1"
|
test_page = "#{qunit_path}?#{query}&testem=1"
|
||||||
cmd += ["yarn", "testem", "ci", "-f", "testem.js", "-t", test_page]
|
cmd += ["yarn", "testem", "ci", "-f", "testem.js", "-t", test_page]
|
||||||
else
|
|
||||||
cmd += ["yarn", "ember", "test", "--query", query]
|
|
||||||
end
|
|
||||||
system(*cmd, chdir: "#{Rails.root}/app/assets/javascripts/discourse")
|
|
||||||
else
|
else
|
||||||
cmd = "node #{test_path}/run-qunit.js http://localhost:#{port}#{qunit_path}"
|
cmd += ["yarn", "ember", "test", "--query", query]
|
||||||
cmd += "?#{query.gsub('+', '%20').gsub("&", '\\\&')}"
|
|
||||||
cmd += " #{args[:timeout]}" if args[:timeout].present?
|
|
||||||
system(cmd)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
system(*cmd, chdir: "#{Rails.root}/app/assets/javascripts/discourse")
|
||||||
|
|
||||||
success &&= $?.success?
|
success &&= $?.success?
|
||||||
ensure
|
ensure
|
||||||
# was having issues with HUP
|
# was having issues with HUP
|
||||||
|
@ -31,9 +31,9 @@ describe ApplicationHelper do
|
|||||||
set_cdn_url "https://awesome.com"
|
set_cdn_url "https://awesome.com"
|
||||||
|
|
||||||
helper.request.env["HTTP_ACCEPT_ENCODING"] = 'br'
|
helper.request.env["HTTP_ACCEPT_ENCODING"] = 'br'
|
||||||
link = helper.preload_script('application')
|
link = helper.preload_script('discourse')
|
||||||
|
|
||||||
expect(link).to eq(preload_link("https://awesome.com/brotli_asset/#{EmberCli.transform_name("application")}.js"))
|
expect(link).to eq(preload_link("https://awesome.com/brotli_asset/discourse.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with s3 CDN" do
|
context "with s3 CDN" do
|
||||||
@ -47,41 +47,41 @@ describe ApplicationHelper do
|
|||||||
|
|
||||||
it "deals correctly with subfolder" do
|
it "deals correctly with subfolder" do
|
||||||
set_subfolder "/community"
|
set_subfolder "/community"
|
||||||
expect(helper.preload_script("application")).to include("https://s3cdn.com/assets/#{EmberCli.transform_name("application")}.js")
|
expect(helper.preload_script("discourse")).to include("https://s3cdn.com/assets/discourse.js")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "replaces cdn URLs with s3 cdn subfolder paths" do
|
it "replaces cdn URLs with s3 cdn subfolder paths" do
|
||||||
global_setting :s3_cdn_url, 'https://s3cdn.com/s3_subpath'
|
global_setting :s3_cdn_url, 'https://s3cdn.com/s3_subpath'
|
||||||
set_cdn_url "https://awesome.com"
|
set_cdn_url "https://awesome.com"
|
||||||
set_subfolder "/community"
|
set_subfolder "/community"
|
||||||
expect(helper.preload_script("application")).to include("https://s3cdn.com/s3_subpath/assets/#{EmberCli.transform_name("application")}.js")
|
expect(helper.preload_script("discourse")).to include("https://s3cdn.com/s3_subpath/assets/discourse.js")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns magic brotli mangling for brotli requests" do
|
it "returns magic brotli mangling for brotli requests" do
|
||||||
|
|
||||||
helper.request.env["HTTP_ACCEPT_ENCODING"] = 'br'
|
helper.request.env["HTTP_ACCEPT_ENCODING"] = 'br'
|
||||||
link = helper.preload_script('application')
|
link = helper.preload_script('discourse')
|
||||||
|
|
||||||
expect(link).to eq(preload_link("https://s3cdn.com/assets/#{EmberCli.transform_name("application")}.br.js"))
|
expect(link).to eq(preload_link("https://s3cdn.com/assets/discourse.br.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gives s3 cdn if asset host is not set" do
|
it "gives s3 cdn if asset host is not set" do
|
||||||
link = helper.preload_script('application')
|
link = helper.preload_script('discourse')
|
||||||
|
|
||||||
expect(link).to eq(preload_link("https://s3cdn.com/assets/#{EmberCli.transform_name("application")}.js"))
|
expect(link).to eq(preload_link("https://s3cdn.com/assets/discourse.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can fall back to gzip compression" do
|
it "can fall back to gzip compression" do
|
||||||
helper.request.env["HTTP_ACCEPT_ENCODING"] = 'gzip'
|
helper.request.env["HTTP_ACCEPT_ENCODING"] = 'gzip'
|
||||||
link = helper.preload_script('application')
|
link = helper.preload_script('discourse')
|
||||||
expect(link).to eq(preload_link("https://s3cdn.com/assets/#{EmberCli.transform_name("application")}.gz.js"))
|
expect(link).to eq(preload_link("https://s3cdn.com/assets/discourse.gz.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gives s3 cdn even if asset host is set" do
|
it "gives s3 cdn even if asset host is set" do
|
||||||
set_cdn_url "https://awesome.com"
|
set_cdn_url "https://awesome.com"
|
||||||
link = helper.preload_script('application')
|
link = helper.preload_script('discourse')
|
||||||
|
|
||||||
expect(link).to eq(preload_link("https://s3cdn.com/assets/#{EmberCli.transform_name("application")}.js"))
|
expect(link).to eq(preload_link("https://s3cdn.com/assets/discourse.js"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gives s3 cdn but without brotli/gzip extensions for theme tests assets" do
|
it "gives s3 cdn but without brotli/gzip extensions for theme tests assets" do
|
||||||
|
@ -10,7 +10,7 @@ describe InvitesController do
|
|||||||
it 'shows the accept invite page' do
|
it 'shows the accept invite page' do
|
||||||
get "/invites/#{invite.invite_key}"
|
get "/invites/#{invite.invite_key}"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to have_tag(:script, with: { src: "/assets/#{EmberCli.transform_name("application")}.js" })
|
expect(response.body).to have_tag(:script, with: { src: "/assets/discourse.js" })
|
||||||
expect(response.body).not_to include(invite.email)
|
expect(response.body).not_to include(invite.email)
|
||||||
expect(response.body).to_not include(I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url))
|
expect(response.body).to_not include(I18n.t('invite.not_found_template', site_name: SiteSetting.title, base_url: Discourse.base_url))
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ describe InvitesController do
|
|||||||
it 'shows unobfuscated email' do
|
it 'shows unobfuscated email' do
|
||||||
get "/invites/#{invite.invite_key}"
|
get "/invites/#{invite.invite_key}"
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(response.body).to have_tag(:script, with: { src: "/assets/#{EmberCli.transform_name("application")}.js" })
|
expect(response.body).to have_tag(:script, with: { src: "/assets/discourse.js" })
|
||||||
expect(response.body).to include(invite.email)
|
expect(response.body).to include(invite.email)
|
||||||
expect(response.body).not_to include('i*****g@a***********e.ooo')
|
expect(response.body).not_to include('i*****g@a***********e.ooo')
|
||||||
end
|
end
|
||||||
|
@ -99,7 +99,7 @@ describe QunitController do
|
|||||||
expect(response.body).to include("/test-support")
|
expect(response.body).to include("/test-support")
|
||||||
expect(response.body).to include("/test-helpers")
|
expect(response.body).to include("/test-helpers")
|
||||||
expect(response.body).to include("/assets/markdown-it-bundle.js")
|
expect(response.body).to include("/assets/markdown-it-bundle.js")
|
||||||
expect(response.body).to include("/assets/#{EmberCli.transform_name("application")}.js")
|
expect(response.body).to include("/assets/discourse.js")
|
||||||
expect(response.body).to include("/assets/admin.js")
|
expect(response.body).to include("/assets/admin.js")
|
||||||
expect(response.body).to match(/\/theme-javascripts\/\h{40}\.js/)
|
expect(response.body).to match(/\/theme-javascripts\/\h{40}\.js/)
|
||||||
expect(response.body).to include("/theme-javascripts/tests/#{theme.id}-")
|
expect(response.body).to include("/theme-javascripts/tests/#{theme.id}-")
|
||||||
|
@ -2362,7 +2362,7 @@ RSpec.describe TopicsController do
|
|||||||
|
|
||||||
body = response.body
|
body = response.body
|
||||||
|
|
||||||
expect(body).to have_tag(:script, src: "/assets/#{EmberCli.transform_name("application")}.js")
|
expect(body).to have_tag(:script, src: "/assets/discourse.js")
|
||||||
expect(body).to have_tag(:meta, with: { name: 'fragment' })
|
expect(body).to have_tag(:meta, with: { name: 'fragment' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2638,7 +2638,7 @@ RSpec.describe TopicsController do
|
|||||||
body = response.body
|
body = response.body
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
expect(body).to have_tag(:script, with: { src: "/assets/#{EmberCli.transform_name("application")}.js" })
|
expect(body).to have_tag(:script, with: { src: "/assets/discourse.js" })
|
||||||
expect(body).to_not have_tag(:meta, with: { name: 'fragment' })
|
expect(body).to_not have_tag(:meta, with: { name: 'fragment' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2653,7 +2653,7 @@ RSpec.describe TopicsController do
|
|||||||
|
|
||||||
body = response.body
|
body = response.body
|
||||||
|
|
||||||
expect(body).to have_tag(:script, with: { src: "/assets/#{EmberCli.transform_name("application")}.js" })
|
expect(body).to have_tag(:script, with: { src: "/assets/discourse.js" })
|
||||||
expect(body).to have_tag(:meta, with: { name: 'fragment' })
|
expect(body).to have_tag(:meta, with: { name: 'fragment' })
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -4306,7 +4306,7 @@ RSpec.describe TopicsController do
|
|||||||
|
|
||||||
body = response.body
|
body = response.body
|
||||||
|
|
||||||
expect(body).to have_tag(:script, with: { src: "/assets/#{EmberCli.transform_name("application")}.js" })
|
expect(body).to have_tag(:script, with: { src: "/assets/discourse.js" })
|
||||||
expect(body).to have_tag(:meta, with: { name: 'fragment' })
|
expect(body).to have_tag(:meta, with: { name: 'fragment' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user