Skip to content

Commit 1bd3565

Browse files
committed
We scan for anything on port 8080 because webpack changes PID after it forks.
1 parent 3980169 commit 1bd3565

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

test/support/webpacker_helpers.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def with_dev_server
4949
ENV['NODE_ENV'] = 'development'
5050

5151
# Start the server in a forked process:
52-
webpack_dev_server = Dir.chdir("test/#{DUMMY_LOCATION}") do
52+
Dir.chdir("test/#{DUMMY_LOCATION}") do
5353
spawn 'RAILS_ENV=development ./bin/webpack-dev-server '
5454
end
5555

@@ -69,12 +69,24 @@ def with_dev_server
6969
yield
7070

7171
ensure
72-
# Kill the server process
73-
puts "Killing webpack dev server"
74-
kill_cmd = "kill -9 #{webpack_dev_server}"
72+
check_cmd = 'lsof -i :8080 -S'
73+
10.times do
74+
# puts check_cmd
75+
status = `#{check_cmd}`
76+
# puts status
77+
remaining_pid_match = status.match(/\n[a-z]+\s+(\d+)/)
78+
if remaining_pid_match
79+
remaining_pid = remaining_pid_match[1]
80+
# puts "Remaining #{remaining_pid}"
81+
kill_cmd = "kill -9 #{remaining_pid}"
82+
# puts kill_cmd
83+
`#{kill_cmd}`
84+
sleep 0.5
85+
else
86+
break
87+
end
88+
end
7589

76-
puts kill_cmd
77-
`#{kill_cmd}`
7890
# Remove the dev-server packs:
7991
WebpackerHelpers.clear_webpacker_packs
8092
ENV['NODE_ENV'] = old_env
@@ -86,12 +98,14 @@ def with_dev_server
8698
def dev_server_running?
8799
manifest_refresh
88100
example_asset_path = manifest_data.values.first
101+
return false unless example_asset_path
102+
return false unless example_asset_path.start_with?('http://localhost:8080')
89103
begin
90104
file = open('http://localhost:8080/packs/application.js')
91105
rescue StandardError => e
92106
file = nil
93107
end
94-
if !example_asset_path.start_with?('http://localhost:8080') && ! file
108+
unless file
95109
puts "Manifest doesn't include absolute path to dev server"
96110
return false
97111
end
@@ -118,6 +132,7 @@ def dev_server_running?
118132

119133
ds = Webpacker.dev_server
120134
example_asset_path = manifest_data.values.first
135+
return false unless example_asset_path
121136
begin
122137
file = open("#{ds.protocol}://#{ds.host}:#{ds.port}#{example_asset_path}")
123138
rescue StandardError => e

0 commit comments

Comments
 (0)