Skip to content

Commit

Permalink
test: properly verify dev server exec
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Nov 17, 2023
1 parent c78a5c0 commit 7387654
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 36 deletions.
102 changes: 84 additions & 18 deletions spec/backward_compatibility_specs/dev_server_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,52 @@
verify_command(cmd, argv: (["--quiet"]))
end

it "does not automatically pass the --https flag" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd)
end

it "supports the https flag" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])

dev_server = double()
allow(dev_server).to receive(:host).and_return("localhost")
allow(dev_server).to receive(:port).and_return("3035")
allow(dev_server).to receive(:pretty?).and_return(false)
allow(dev_server).to receive(:https?).and_return(true)
allow(dev_server).to receive(:hmr?).and_return(false)
allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd, argv: ["--https"])
end

it "supports hot module reloading" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"])

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
)
)

allow(Shakapacker::DevServer).to receive(:new) do
verify_command(cmd, argv: (["--https"]))
end.and_return(dev_server)
verify_command(cmd)
end

it "accepts environment variables" do
Expand Down Expand Up @@ -94,19 +127,52 @@
verify_command(cmd, argv: (["--quiet"]))
end

it "does not automatically pass the --https flag" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd)
end

it "supports the https flag" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]

dev_server = double()
allow(dev_server).to receive(:host).and_return("localhost")
allow(dev_server).to receive(:port).and_return("3035")
allow(dev_server).to receive(:pretty?).and_return(false)
allow(dev_server).to receive(:https?).and_return(true)
allow(dev_server).to receive(:hmr?).and_return(false)
allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd, argv: ["--https"])
end

it "supports hot module reloading" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"]

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
)
)

allow(Shakapacker::DevServer).to receive(:new) do
verify_command(cmd, argv: (["--https"]))
end.and_return(dev_server)
verify_command(cmd)
end

it "accepts environment variables" do
Expand Down
102 changes: 84 additions & 18 deletions spec/shakapacker/dev_server_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,52 @@
verify_command(cmd, argv: (["--quiet"]))
end

it "does not automatically pass the --https flag" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd)
end

it "supports the https flag" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])

dev_server = double()
allow(dev_server).to receive(:host).and_return("localhost")
allow(dev_server).to receive(:port).and_return("3035")
allow(dev_server).to receive(:pretty?).and_return(false)
allow(dev_server).to receive(:https?).and_return(true)
allow(dev_server).to receive(:hmr?).and_return(false)
allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd, argv: ["--https"])
end

it "supports hot module reloading" do
cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"])

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
)
)

allow(Shakapacker::DevServer).to receive(:new) do
verify_command(cmd, argv: (["--https"]))
end.and_return(dev_server)
verify_command(cmd)
end

it "accepts environment variables" do
Expand Down Expand Up @@ -92,19 +125,52 @@
verify_command(cmd, argv: (["--quiet"]))
end

it "does not automatically pass the --https flag" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd)
end

it "supports the https flag" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]

dev_server = double()
allow(dev_server).to receive(:host).and_return("localhost")
allow(dev_server).to receive(:port).and_return("3035")
allow(dev_server).to receive(:pretty?).and_return(false)
allow(dev_server).to receive(:https?).and_return(true)
allow(dev_server).to receive(:hmr?).and_return(false)
allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "https",
hmr?: false
)
)

verify_command(cmd, argv: ["--https"])
end

it "supports hot module reloading" do
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--hot"]

allow(Shakapacker::DevServer).to receive(:new).and_return(
double(
host: "localhost",
port: "3035",
pretty?: false,
protocol: "http",
hmr?: true
)
)

allow(Shakapacker::DevServer).to receive(:new) do
verify_command(cmd, argv: (["--https"]))
end.and_return(dev_server)
verify_command(cmd)
end

it "accepts environment variables" do
Expand Down

0 comments on commit 7387654

Please sign in to comment.