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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3f2c9a21a0e887ab86fde00efe66c1c971f6a995583d22f5588e7f220b87501
4
- data.tar.gz: 620502fbd9638568e999948c6bfc3b38ba45c225b879ce887c3510c0a645309d
3
+ metadata.gz: ababba8966c18dbf4dbd906cd0f9b1efcefd9064735bcb6d1a2a588494199457
4
+ data.tar.gz: 9a5ecf440cf5431144d4cd9fce719f4485625f91366cef7a8f58f2ebee8d99c7
5
5
  SHA512:
6
- metadata.gz: 1064dcdea31f3c5157c886004fb39b64d839b10aabd9f60117b0572f6fcebc1be47e00214ac3990e873bbf8b71c20014bc958052dd44fa0ec7df3dedb0b5a2d4
7
- data.tar.gz: 380486530d4c5cc85d3e3f97048b3fc45e94ff195b6d2cf0617201d8bc0524786c04ed912a609deddaf6411c459575d9c5d9e8882e8431e9275616e359982ff1
6
+ metadata.gz: 7faca22d58f77c3cfdb782e075d043dc800ddd669a68ad19f5df7ed6a21b2f42742263969eba462e4ea1f10c7eeed907050dd6305a2b70e8eeed895ea7a4f009
7
+ data.tar.gz: 3b4c490655e6dca8c7957eeaf2e76c44cf05368f85f453ff7c64564518f9c387ffc1c588c805d4ffb29b97b0a63c78c1137e99f4cbd6aee0773e3470d5147ede
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Webpack
4
4
  module Helpers
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -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.2
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-01-30 00:00:00.000000000 Z
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.2
167
- changelog_uri: https://github.com/ak10m/webpack-helpers/blob/0.1.2/CHANGELOG.md
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: