Skip to content

A platform for community discussion. Free, open, simple.

DEV: Correct `bin/qunit` random seed handling (#37087)

David Taylor8671593a9983
diff --git a/bin/qunit b/bin/qunit
index dcded9de67e..eedc118684e 100755
--- a/bin/qunit
+++ b/bin/qunit
@@ -7,6 +7,7 @@ require "fileutils"
require "socket"
require "uri"
require "net/http"
+require "securerandom"
require_relative "../lib/chrome_installed_checker"
class QunitRunner
@@ -260,6 +261,7 @@ class QunitRunner
args += ["--filter", filter] if filter
args += ["--file-path", file_path_filter] if file_path_filter
args += ["--load-balance", "--parallel", parallel.to_s] if parallel
+ args += ["--random", resolved_seed]
args += %w[--path dist] if reuse_build
args << "--write-execution-file" if ENV["QUNIT_WRITE_EXECUTION_FILE"]
end
@@ -496,7 +498,10 @@ class QunitRunner
def build_query
params = {}
- params["seed"] = resolved_seed
+ if @qunit_path
+ # Only include seed manually if we're running without ember exam
+ params["seed"] = resolved_seed
+ end
params["module"] = @module if @module
params["theme_name"] = @theme_name if @theme_name
params["theme_url"] = @theme_url if @theme_url
@@ -541,7 +546,7 @@ class QunitRunner
end
def resolved_seed
- @resolved_seed ||= present_string(@seed) || Random.new.seed
+ @resolved_seed ||= present_string(@seed) || SecureRandom.alphanumeric(8)
end
def should_load_plugins?
diff --git a/spec/tasks/qunit_cli_spec.rb b/spec/tasks/qunit_cli_spec.rb
index 84ba6f41eda..6095683ff5b 100644
--- a/spec/tasks/qunit_cli_spec.rb
+++ b/spec/tasks/qunit_cli_spec.rb
@@ -36,7 +36,9 @@ describe "bin/qunit" do
"ember",
"exam",
"--query",
- a_string_matching(/\Aseed=\d+&target=core\z/),
+ "target=core",
+ "--random",
+ a_string_matching(/\A[a-zA-Z0-9]{8}\z/),
"--path",
"dist",
],
@@ -59,9 +61,11 @@ describe "bin/qunit" do
"ember",
"exam",
"--query",
- a_string_matching(/\Aseed=\d+&target=core\z/),
+ "target=core",
"--file-path",
core_test_file.sub("#{Rails.root}/frontend/discourse/", ""),
+ "--random",
+ a_string_matching(/\A[a-zA-Z0-9]{8}\z/),
"--path",
"dist",
],
@@ -79,7 +83,15 @@ describe "bin/qunit" do
expect(result.launched_unicorn).to eq(false)
expect(result.args).to match(
- ["pnpm", "ember", "exam", "--query", a_string_matching(/\Aseed=\d+\z/), "--path", "dist"],
+ [
+ "pnpm",
+ "ember",
+ "exam",
+ "--random",
+ a_string_matching(/\A[a-zA-Z0-9]{8}\z/),
+ "--path",
+ "dist",
+ ],
)
expect(result.env).to match(
"UNICORN_PORT" => a_truthy_value,
@@ -95,7 +107,15 @@ describe "bin/qunit" do
expect(result.launched_unicorn).to eq(false)
expect(result.args).to match(
- ["pnpm", "ember", "exam", "--query", a_string_matching(/\Aseed=\d+\z/), "--path", "dist"],
+ [
+ "pnpm",
+ "ember",
+ "exam",
+ "--random",
+ a_string_matching(/\A[a-zA-Z0-9]{8}\z/),
+ "--path",
+ "dist",
+ ],
)
expect(result.env).to match(
"UNICORN_PORT" => a_truthy_value,
@@ -116,12 +136,14 @@ describe "bin/qunit" do
"ember",
"exam",
"--query",
- a_string_matching(/\Aseed=\d+&target=chat\z/),
+ "target=chat",
"--file-path",
chat_test_file.sub(
"#{Rails.root}/plugins/chat/test/javascripts/",
"discourse/plugins/chat/",
),
+ "--random",
+ a_string_matching(/\A[a-zA-Z0-9]{8}\z/),
"--path",
"dist",
],