sewing_kit 0.93.0 → 0.94.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -0
- data/lib/sewing_kit/configuration.rb +9 -0
- data/lib/sewing_kit/version.rb +1 -1
- data/lib/sewing_kit/webpack/manifest.rb +20 -2
- data/lib/sewing_kit/webpack/manifest/test_with_no_assets.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3b2b21c04f2ce3043bc5ff0c27dc61b301ab3585e4f84347d1edfeef0f92121
|
4
|
+
data.tar.gz: d378424249b09da4747a81281d2ba3f703790f23ac8fa2732e0a39ef655224a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5beb6976e7812ebef7adc31040a1c5c08178af88118d3952d7aaaea5c740172a6e381b89cf1a388c1ed7e4e6d026e21effdc321e196587613fc0a56233b7be3
|
7
|
+
data.tar.gz: 2b2a62b6e61004d24571e4b5b14319100e5bfc3a60c392a2fcec30912e1e71c4ca3e2142de49d25d14d64d438384e2d3c51385ad7b413d0a5f60a898b195d852
|
data/README.md
CHANGED
@@ -179,6 +179,39 @@ afterAll(() => {
|
|
179
179
|
|
180
180
|
For more complete documentation of the jest plugin see [it's documentation](/docs/plugins/jest.md).
|
181
181
|
|
182
|
+
### Rails tests
|
183
|
+
|
184
|
+
Building JavaScript assets for Rails tests adds friction to test driven development, but some projects rely on tests that intermingle erb / JavaScript behaviour. To accommodate different test styles, sewing_kit offers two test modes.
|
185
|
+
|
186
|
+
#### `:return_no_assets` - sewing_kit helpers return empty arrays (default)
|
187
|
+
|
188
|
+
As noted above, the Web Foundation team highly recommends `sewing-kit test` for front end testing. Projects following this recommendation can use sewing_kit's default behaviour for controller, integration tests, and e2e tests. Note that no sewing_kit content will appear in pages with this mode enabled.
|
189
|
+
|
190
|
+
The default behaviour is equivalent to this configuration:
|
191
|
+
|
192
|
+
```rb
|
193
|
+
# config/initializers/sewing_kit.rb
|
194
|
+
SewingKit.configure do |config|
|
195
|
+
config.test_manifest_mode = :return_no_asets
|
196
|
+
end
|
197
|
+
```
|
198
|
+
|
199
|
+
#### Use precompiled assets
|
200
|
+
|
201
|
+
If end-to-end tests are unavoidable:
|
202
|
+
|
203
|
+
- Add extra steps to your test commands and CI pipelines that run `sewing-kit build --mode test` before test startup
|
204
|
+
- Configure sewing_kit's `test_manifest_mode` to use precompiled assets:
|
205
|
+
|
206
|
+
```rb
|
207
|
+
# config/initializers/sewing_kit.rb
|
208
|
+
SewingKit.configure do |config|
|
209
|
+
config.test_manifest_mode = :use_precompiled_assets
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
If your tests require production assets, precompile using `sewing-kit build --mode production` instead.
|
214
|
+
|
182
215
|
## FAQ
|
183
216
|
|
184
217
|
### Which version of sewing-kit can I use?
|
@@ -3,12 +3,21 @@ module SewingKit
|
|
3
3
|
class Configuration
|
4
4
|
attr_accessor :build_options, :dev_server_sewing_kit_bin, :manifest_name,
|
5
5
|
:manifest_path
|
6
|
+
attr_reader :test_manifest_mode
|
7
|
+
|
8
|
+
def test_manifest_mode=(mode)
|
9
|
+
valid_modes = [:return_no_assets, :use_precompiled_assets]
|
10
|
+
raise "Unknown mode '#{mode}' (valid modes are: #{valid_modes})" unless valid_modes.include?(mode)
|
11
|
+
|
12
|
+
@test_manifest_mode = mode
|
13
|
+
end
|
6
14
|
|
7
15
|
def initialize
|
8
16
|
@build_options = nil
|
9
17
|
@manifest_name = 'sewing-kit-manifest.json'
|
10
18
|
@manifest_path = nil
|
11
19
|
@dev_server_sewing_kit_bin = 'node_modules/.bin/sewing-kit'
|
20
|
+
self.test_manifest_mode = :return_no_assets
|
12
21
|
end
|
13
22
|
end
|
14
23
|
|
data/lib/sewing_kit/version.rb
CHANGED
@@ -54,13 +54,30 @@ module SewingKit
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def instance
|
57
|
-
|
58
|
-
|
57
|
+
return Production.new if simulate_production?
|
58
|
+
|
59
|
+
@instance ||= if mode == 'development'
|
59
60
|
Development.new
|
61
|
+
elsif skip_assets?
|
62
|
+
TestWithNoAssets.new
|
60
63
|
else
|
61
64
|
Production.new
|
62
65
|
end
|
63
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def mode
|
71
|
+
ENV['NODE_ENV'] || Rails.env.to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
def skip_assets?
|
75
|
+
mode == 'test' && SewingKit.configuration.test_manifest_mode == :return_no_assets
|
76
|
+
end
|
77
|
+
|
78
|
+
def simulate_production?
|
79
|
+
ENV['SK_SIMULATE_PRODUCTION'] == '1' || ENV['SK_SIMULATE_PRODUCTION'] == 'true'
|
80
|
+
end
|
64
81
|
end
|
65
82
|
end
|
66
83
|
end
|
@@ -68,3 +85,4 @@ end
|
|
68
85
|
|
69
86
|
require 'sewing_kit/webpack/manifest/development'
|
70
87
|
require 'sewing_kit/webpack/manifest/production'
|
88
|
+
require 'sewing_kit/webpack/manifest/test_with_no_assets'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sewing_kit/webpack/manifest/base'
|
3
|
+
|
4
|
+
module SewingKit
|
5
|
+
module Webpack
|
6
|
+
class Manifest
|
7
|
+
class TestWithNoAssets < Base
|
8
|
+
def asset_bundle_name(_user_agent)
|
9
|
+
'test'
|
10
|
+
end
|
11
|
+
|
12
|
+
def asset_dependencies(_entrypoint_name, _user_agent)
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
|
16
|
+
def manifest
|
17
|
+
raise OnlyUseInProductionError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sewing_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.94.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Sauve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/sewing_kit/webpack/manifest/base.rb
|
115
115
|
- lib/sewing_kit/webpack/manifest/development.rb
|
116
116
|
- lib/sewing_kit/webpack/manifest/production.rb
|
117
|
+
- lib/sewing_kit/webpack/manifest/test_with_no_assets.rb
|
117
118
|
- lib/sewing_kit/webpack/webpack.rb
|
118
119
|
- lib/tasks/sewing_kit.rake
|
119
120
|
homepage:
|