DEV: Skip CSS watcher when running QUnit tests and expose more Chrome logs (#13390)

There are 2 changes in this PR:

1) Add a new environment variable called `DISCOURSE_SKIP_CSS_WATCHER` to disable our stylesheet watcher, and make the `qunit:test` rake task set this variable on the Unicorn/Rails server it spins up to disable our stylesheet watcher when running the tests because it doesn't really need it.

2) Print more Chrome logs (such as network/security errors) to the console.
This commit is contained in:
Osama Sayegh 2021-06-15 18:27:15 +03:00 committed by GitHub
parent e36377d9ab
commit 503017474c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -84,7 +84,7 @@ Discourse::Application.configure do
config.developer_emails = emails.split(",").map(&:downcase).map(&:strip) config.developer_emails = emails.split(",").map(&:downcase).map(&:strip)
end end
if defined?(Rails::Server) || defined?(Puma) || defined?(Unicorn) if ENV["DISCOURSE_SKIP_CSS_WATCHER"] != "1" && (defined?(Rails::Server) || defined?(Puma) || defined?(Unicorn))
require 'stylesheet/watcher' require 'stylesheet/watcher'
STDERR.puts "Starting CSS change watcher" STDERR.puts "Starting CSS change watcher"
@watcher = Stylesheet::Watcher.watch @watcher = Stylesheet::Watcher.watch

View File

@ -49,7 +49,8 @@ task "qunit:test", [:timeout, :qunit_path] do |_, args|
"SKIP_ENFORCE_HOSTNAME" => "1", "SKIP_ENFORCE_HOSTNAME" => "1",
"UNICORN_PID_PATH" => "#{Rails.root}/tmp/pids/unicorn_test_#{port}.pid", # So this can run alongside development "UNICORN_PID_PATH" => "#{Rails.root}/tmp/pids/unicorn_test_#{port}.pid", # So this can run alongside development
"UNICORN_PORT" => port.to_s, "UNICORN_PORT" => port.to_s,
"UNICORN_SIDEKIQS" => "0" "UNICORN_SIDEKIQS" => "0",
"DISCOURSE_SKIP_CSS_WATCHER" => "1"
}, },
"#{Rails.root}/bin/unicorn -c config/unicorn.conf.rb", "#{Rails.root}/bin/unicorn -c config/unicorn.conf.rb",
pgroup: true pgroup: true

View File

@ -75,7 +75,19 @@ async function runAllTests() {
} }
} }
const { Inspector, Page, Runtime } = protocol; const { Inspector, Page, Runtime, Log } = protocol;
// Documentation https://chromedevtools.github.io/devtools-protocol/tot/Log/#type-LogEntry
Log.enable();
Log.entryAdded(({ entry }) => {
let message = `${new Date(entry.timestamp).toISOString()} - (type: ${
entry.source
}/${entry.level}) message: ${entry.text}`;
if (entry.url) {
message += `, url: ${entry.url}`;
}
console.log(message);
});
// eslint-disable-next-line // eslint-disable-next-line
await Promise.all([Inspector.enable(), Page.enable(), Runtime.enable()]); await Promise.all([Inspector.enable(), Page.enable(), Runtime.enable()]);