@@ -49,7 +49,7 @@ def with_dev_server
49
49
ENV [ 'NODE_ENV' ] = 'development'
50
50
51
51
# Start the server in a forked process:
52
- webpack_dev_server = Dir . chdir ( "test/#{ DUMMY_LOCATION } " ) do
52
+ Dir . chdir ( "test/#{ DUMMY_LOCATION } " ) do
53
53
spawn 'RAILS_ENV=development ./bin/webpack-dev-server '
54
54
end
55
55
@@ -69,12 +69,24 @@ def with_dev_server
69
69
yield
70
70
71
71
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
75
89
76
- puts kill_cmd
77
- `#{ kill_cmd } `
78
90
# Remove the dev-server packs:
79
91
WebpackerHelpers . clear_webpacker_packs
80
92
ENV [ 'NODE_ENV' ] = old_env
@@ -86,12 +98,14 @@ def with_dev_server
86
98
def dev_server_running?
87
99
manifest_refresh
88
100
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' )
89
103
begin
90
104
file = open ( 'http://localhost:8080/packs/application.js' )
91
105
rescue StandardError => e
92
106
file = nil
93
107
end
94
- if ! example_asset_path . start_with? ( 'http://localhost:8080' ) && ! file
108
+ unless file
95
109
puts "Manifest doesn't include absolute path to dev server"
96
110
return false
97
111
end
@@ -118,6 +132,7 @@ def dev_server_running?
118
132
119
133
ds = Webpacker . dev_server
120
134
example_asset_path = manifest_data . values . first
135
+ return false unless example_asset_path
121
136
begin
122
137
file = open ( "#{ ds . protocol } ://#{ ds . host } :#{ ds . port } #{ example_asset_path } " )
123
138
rescue StandardError => e
0 commit comments