diff --git a/lib/tasks/smoke_test.rake b/lib/tasks/smoke_test.rake index d3cab6a08cb..5535d6b2a04 100644 --- a/lib/tasks/smoke_test.rake +++ b/lib/tasks/smoke_test.rake @@ -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 diff --git a/test/run-qunit.js b/test/run-qunit.js index f55a9d70b0d..584e3f608cb 100644 --- a/test/run-qunit.js +++ b/test/run-qunit.js @@ -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 });