webpack-helpers 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/webpack/helpers/version.rb +1 -1
- data/lib/webpack/testing/file_server.rb +84 -0
- data/lib/webpack/testing/helper.rb +21 -0
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ababba8966c18dbf4dbd906cd0f9b1efcefd9064735bcb6d1a2a588494199457
|
|
4
|
+
data.tar.gz: 9a5ecf440cf5431144d4cd9fce719f4485625f91366cef7a8f58f2ebee8d99c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7faca22d58f77c3cfdb782e075d043dc800ddd669a68ad19f5df7ed6a21b2f42742263969eba462e4ea1f10c7eeed907050dd6305a2b70e8eeed895ea7a4f009
|
|
7
|
+
data.tar.gz: 3b4c490655e6dca8c7957eeaf2e76c44cf05368f85f453ff7c64564518f9c387ffc1c588c805d4ffb29b97b0a63c78c1137e99f4cbd6aee0773e3470d5147ede
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "socket"
|
|
4
|
+
require "rack/server"
|
|
5
|
+
require "rack/file"
|
|
6
|
+
|
|
7
|
+
module Webpack
|
|
8
|
+
module Testing
|
|
9
|
+
class FileServer < ::Rack::Server
|
|
10
|
+
def initialize(root)
|
|
11
|
+
port = unused_port
|
|
12
|
+
pid = File.expand_path("./tmp/rack-#{port}.pid")
|
|
13
|
+
super(
|
|
14
|
+
app: ::Rack::File.new(root),
|
|
15
|
+
Host: default_host,
|
|
16
|
+
Port: port,
|
|
17
|
+
pid: pid,
|
|
18
|
+
daemonize: true
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def host
|
|
23
|
+
options[:Host]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def port
|
|
27
|
+
options[:Port]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def host_with_port
|
|
31
|
+
"#{host}:#{port}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def pid
|
|
35
|
+
::File.exist?(options[:pid]) ? ::File.read(options[:pid]).to_i : nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def running?
|
|
39
|
+
Socket.tcp(host, port).close
|
|
40
|
+
true
|
|
41
|
+
rescue Errno::ECONNREFUSED
|
|
42
|
+
false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def run(timeout: 10)
|
|
46
|
+
Process.fork { start } unless running?
|
|
47
|
+
wait timeout
|
|
48
|
+
|
|
49
|
+
return unless block_given?
|
|
50
|
+
|
|
51
|
+
yield self
|
|
52
|
+
stop
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def stop
|
|
56
|
+
return if pid.nil?
|
|
57
|
+
|
|
58
|
+
Process.kill "SIGTERM", pid
|
|
59
|
+
::File.delete(options[:pid])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def wait(timeout, interval: 1)
|
|
65
|
+
Timeout.timeout(timeout) do
|
|
66
|
+
loop do
|
|
67
|
+
break if running?
|
|
68
|
+
|
|
69
|
+
sleep interval
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def default_host
|
|
75
|
+
env = ENV["RACK_ENV"] || "development"
|
|
76
|
+
env == "development" ? "localhost" : "0.0.0.0"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def unused_port
|
|
80
|
+
Addrinfo.tcp("", 0).bind { |s| s.local_address.ip_port }
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "webpack/dev_server"
|
|
4
|
+
require "webpack/manifest"
|
|
5
|
+
require "webpack/testing/file_server"
|
|
6
|
+
|
|
7
|
+
module Webpack
|
|
8
|
+
module Testing
|
|
9
|
+
module Helper
|
|
10
|
+
def mock_dev_server(root_path)
|
|
11
|
+
Webpack::DevServer.stub :config, Webpack::DevServer::Configuration.new do
|
|
12
|
+
Webpack::Manifest.stub :config, Webpack::Manifest::Configuration.new do
|
|
13
|
+
Webpack::Testing::FileServer.new(root_path).run do |srv|
|
|
14
|
+
yield srv
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webpack-helpers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ak10m
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-02-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack-proxy
|
|
@@ -158,13 +158,15 @@ files:
|
|
|
158
158
|
- lib/webpack/rails/generators/templates/config.rb
|
|
159
159
|
- lib/webpack/rails/helpers.rb
|
|
160
160
|
- lib/webpack/railtie.rb
|
|
161
|
+
- lib/webpack/testing/file_server.rb
|
|
162
|
+
- lib/webpack/testing/helper.rb
|
|
161
163
|
homepage: https://github.com/ak10m/webpack-helpers
|
|
162
164
|
licenses:
|
|
163
165
|
- MIT
|
|
164
166
|
metadata:
|
|
165
167
|
homepage_uri: https://github.com/ak10m/webpack-helpers
|
|
166
|
-
source_code_uri: https://github.com/ak10m/webpack-helpers/tree/0.1.
|
|
167
|
-
changelog_uri: https://github.com/ak10m/webpack-helpers/blob/0.1.
|
|
168
|
+
source_code_uri: https://github.com/ak10m/webpack-helpers/tree/0.1.3
|
|
169
|
+
changelog_uri: https://github.com/ak10m/webpack-helpers/blob/0.1.3/CHANGELOG.md
|
|
168
170
|
post_install_message:
|
|
169
171
|
rdoc_options: []
|
|
170
172
|
require_paths:
|