DEV: Add optional theme test step to the smoke:test rake task (#13418)

The purpose of this is to allow us to catch regressions for a feature we've built recently that allows theme tests to run in production. We recently had a regression that we didn't notice for days, so to prevent that from happening again we'll use this in our internal CI pipelines.
This commit is contained in:
Osama Sayegh 2021-06-17 20:09:29 +03:00 committed by GitHub
parent 6fd13f38a2
commit c47f55253f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 4 deletions

View File

@ -81,4 +81,33 @@ task "smoke:test" do
if results !~ /ALL PASSED/
raise "FAILED"
end
api_key = ENV["ADMIN_API_KEY"]
api_username = ENV["ADMIN_API_USERNAME"]
theme_url = ENV["SMOKE_TEST_THEME_URL"]
next if api_key.blank? && api_username.blank? && theme_url.blank?
puts "Running QUnit tests for theme #{theme_url.inspect} using API key #{api_key[0..3]}… and username #{api_username.inspect}"
query_params = {
seed: Random.new.seed,
theme_url: theme_url,
hidepassed: 1,
report_requests: 1
}
url += '/' if !url.end_with?('/')
full_url = "#{url}theme-qunit?#{query_params.to_query}"
timeout = 1000 * 60 * 10
sh(
"node",
"#{Rails.root}/test/run-qunit.js",
full_url,
timeout.to_s
)
if !$?.success?
raise "THEME TESTS FAILED!"
end
end

View File

@ -76,9 +76,15 @@ async function runAllTests() {
}
const { Inspector, Page, Runtime, Log } = protocol;
// eslint-disable-next-line
await Promise.all([
Inspector.enable(),
Page.enable(),
Runtime.enable(),
Log.enable(),
]);
// 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
@ -89,9 +95,6 @@ async function runAllTests() {
console.log(message);
});
// eslint-disable-next-line
await Promise.all([Inspector.enable(), Page.enable(), Runtime.enable()]);
Inspector.targetCrashed((entry) => {
console.log("Chrome target crashed:");
console.log(entry);
@ -119,6 +122,31 @@ async function runAllTests() {
});
let url = args[0] + "&qunit_disable_auto_start=1";
const apiKey = process.env.ADMIN_API_KEY;
const apiUsername = process.env.ADMIN_API_USERNAME;
if (apiKey && apiUsername) {
const { Fetch } = protocol;
await Fetch.enable();
const urlObj = new URL(url);
Fetch.requestPaused((data) => {
const requestURL = new URL(data.request.url);
if (requestURL.hostname != urlObj.hostname) {
Fetch.continueRequest({
requestId: data.requestId,
});
return;
}
Fetch.continueRequest({
requestId: data.requestId,
headers: [
{ name: "Api-Key", value: apiKey },
{ name: "Api-Username", value: apiUsername },
],
});
});
}
console.log("navigate to ", url);
Page.navigate({ url });