bridgetown-core 1.0.0.alpha6 → 1.0.0.alpha7
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/bridgetown-core.gemspec +1 -2
- data/lib/bridgetown-core/cache.rb +1 -1
- data/lib/bridgetown-core/collection.rb +1 -1
- data/lib/bridgetown-core/commands/configure.rb +7 -0
- data/lib/bridgetown-core/commands/new.rb +1 -0
- data/lib/bridgetown-core/component.rb +2 -2
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +1 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +6 -3
- data/lib/bridgetown-core/concerns/site/extensible.rb +2 -1
- data/lib/bridgetown-core/concerns/site/ssr.rb +38 -16
- data/lib/bridgetown-core/configuration.rb +77 -46
- data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
- data/lib/bridgetown-core/configurations/cypress/cypress.json +4 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json +5 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js +17 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js +21 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js +25 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js +20 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_tasks +33 -0
- data/lib/bridgetown-core/configurations/cypress.rb +13 -0
- data/lib/bridgetown-core/configurations/minitesting.rb +19 -15
- data/lib/bridgetown-core/configurations/netlify.rb +2 -4
- data/lib/bridgetown-core/configurations/purgecss.rb +2 -2
- data/lib/bridgetown-core/configurations/render/render.yaml.erb +26 -0
- data/lib/bridgetown-core/configurations/render.rb +6 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +3 -5
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/core_ext/psych.rb +1 -5
- data/lib/bridgetown-core/frontmatter_defaults.rb +2 -2
- data/lib/bridgetown-core/liquid_renderer.rb +1 -1
- data/lib/bridgetown-core/model/base.rb +23 -26
- data/lib/bridgetown-core/model/builder_origin.rb +8 -6
- data/lib/bridgetown-core/model/origin.rb +10 -1
- data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
- data/lib/bridgetown-core/plugin_manager.rb +7 -34
- data/lib/bridgetown-core/rack/boot.rb +46 -23
- data/lib/bridgetown-core/rack/roda.rb +2 -1
- data/lib/bridgetown-core/rack/routes.rb +2 -2
- data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +2 -2
- data/lib/bridgetown-core/resource/base.rb +3 -3
- data/lib/bridgetown-core/resource/relations.rb +1 -1
- data/lib/bridgetown-core/resource/taxonomy_term.rb +2 -2
- data/lib/bridgetown-core/resource/taxonomy_type.rb +2 -2
- data/lib/bridgetown-core/ruby_template_view.rb +2 -2
- data/lib/bridgetown-core/site.rb +15 -5
- data/lib/bridgetown-core/utils/loaders_manager.rb +72 -0
- data/lib/bridgetown-core/utils.rb +13 -14
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/bridgetown-core/watcher.rb +16 -7
- data/lib/bridgetown-core/yaml_parser.rb +1 -5
- data/lib/site_template/README.md +1 -1
- data/lib/site_template/Rakefile +3 -3
- metadata +16 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e8dceaa24615a3a0de23c469444c2d22b36ce1f2c171177a9d20646f7b31446
|
4
|
+
data.tar.gz: 10c6c7e5c3bfc2a1f591d8953d098dae8d0d90942bb1ad6ef7871834cf658434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 254a0d29eca611c8642acf2f664ace0dc8de883cf38dd00f56597dfc273625460089743e5ebc8e81df231035a8a1365393a5e890c1c4b1447d94fba48e310a2f
|
7
|
+
data.tar.gz: 48c9518b97fc1e890d8b04b908a117296def616657831c7d0572e9e611a58d3381870f9257f17303db965fa40d47b2280b3e2b814f02652b0b374e6ab4ab0f0d
|
data/bridgetown-core.gemspec
CHANGED
@@ -28,8 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
|
29
29
|
s.rdoc_options = ["--charset=UTF-8"]
|
30
30
|
|
31
|
-
s.required_ruby_version = ">= 2.
|
32
|
-
s.required_rubygems_version = ">= 2.7.0"
|
31
|
+
s.required_ruby_version = ">= 2.7.0"
|
33
32
|
|
34
33
|
s.add_runtime_dependency("activemodel", "~> 6.0")
|
35
34
|
s.add_runtime_dependency("activesupport", "~> 6.0")
|
@@ -144,7 +144,7 @@ module Bridgetown
|
|
144
144
|
@base_dir ||= File.join(Bridgetown::Cache.cache_dir, @name)
|
145
145
|
return @base_dir if hash.nil?
|
146
146
|
|
147
|
-
File.join(@base_dir, hash[0..1], hash[2
|
147
|
+
File.join(@base_dir, hash[0..1], hash[2..]).freeze
|
148
148
|
end
|
149
149
|
|
150
150
|
# Given a key, return a SHA2 hash that can be used for caching this item to disk.
|
@@ -234,7 +234,7 @@ module Bridgetown
|
|
234
234
|
end
|
235
235
|
|
236
236
|
resources.each do |data_resource|
|
237
|
-
segments = data_resource.relative_path.each_filename.to_a[1
|
237
|
+
segments = data_resource.relative_path.each_filename.to_a[1..]
|
238
238
|
nested = []
|
239
239
|
segments.each_with_index do |segment, index|
|
240
240
|
sanitized_segment = sanitize_filename.(File.basename(segment, ".*"))
|
@@ -41,6 +41,7 @@ module Bridgetown
|
|
41
41
|
configuration_file = find_in_source_paths("#{configuration}.rb")
|
42
42
|
|
43
43
|
inside(New.created_site_dir || Dir.pwd) do
|
44
|
+
@templates_dir = File.expand_path("../configurations/#{configuration}", __dir__)
|
44
45
|
apply configuration_file, verbose: false
|
45
46
|
end
|
46
47
|
end
|
@@ -62,6 +63,12 @@ module Bridgetown
|
|
62
63
|
return Dir.glob("*.rb").map { |file| file.sub(".rb", "") }
|
63
64
|
end
|
64
65
|
end
|
66
|
+
|
67
|
+
def in_templates_dir(*paths)
|
68
|
+
paths.reduce(@templates_dir) do |base, path|
|
69
|
+
Bridgetown.sanitized_path(base, path.to_s)
|
70
|
+
end
|
71
|
+
end
|
65
72
|
end
|
66
73
|
end
|
67
74
|
end
|
@@ -164,9 +164,9 @@ module Bridgetown
|
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
|
167
|
+
def method_missing(method, *args, **kwargs, &block)
|
168
168
|
if helpers.respond_to?(method.to_sym)
|
169
|
-
helpers.send method.to_sym, *args, &block
|
169
|
+
helpers.send method.to_sym, *args, **kwargs, &block
|
170
170
|
else
|
171
171
|
super
|
172
172
|
end
|
@@ -32,7 +32,7 @@ module Bridgetown
|
|
32
32
|
self.front_matter_line_count = ruby_content[1].lines.size
|
33
33
|
process_ruby_data(ruby_content[1], file_path, 2)
|
34
34
|
elsif Bridgetown::Utils.has_rbfm_header?(file_path)
|
35
|
-
process_ruby_data(File.read(file_path).lines[1
|
35
|
+
process_ruby_data(File.read(file_path).lines[1..].join("\n"), file_path, 2)
|
36
36
|
elsif is_a?(Layout)
|
37
37
|
self.content = file_contents
|
38
38
|
{}
|
@@ -155,10 +155,10 @@ class Bridgetown::Site
|
|
155
155
|
Bridgetown::Cache.disable_disk_cache! if config["disable_disk_cache"]
|
156
156
|
end
|
157
157
|
|
158
|
-
def configure_component_paths
|
158
|
+
def configure_component_paths # rubocop:todo Metrics/AbcSize
|
159
159
|
# Loop through plugins paths first
|
160
160
|
plugin_components_load_paths = Bridgetown::PluginManager.source_manifests
|
161
|
-
.
|
161
|
+
.filter_map(&:components)
|
162
162
|
|
163
163
|
local_components_load_paths = config["components_dir"].yield_self do |dir|
|
164
164
|
dir.is_a?(Array) ? dir : [dir]
|
@@ -172,7 +172,10 @@ class Bridgetown::Site
|
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
-
|
175
|
+
config.components_load_paths = plugin_components_load_paths + local_components_load_paths
|
176
|
+
# Because "first constant wins" in Zeitwerk, we need to load the local
|
177
|
+
# source components _before_ we load any from plugins
|
178
|
+
config.autoload_paths += config.components_load_paths.reverse
|
176
179
|
end
|
177
180
|
|
178
181
|
def configure_file_read_opts
|
@@ -3,13 +3,14 @@
|
|
3
3
|
class Bridgetown::Site
|
4
4
|
module Extensible
|
5
5
|
# Load necessary libraries, plugins, converters, and generators.
|
6
|
+
# This is only ever run once for the lifecycle of the site object.
|
6
7
|
# @see Converter
|
7
8
|
# @see Generator
|
8
9
|
# @see PluginManager
|
9
10
|
# @return [void]
|
10
11
|
def setup
|
11
12
|
plugin_manager.require_plugin_files
|
12
|
-
|
13
|
+
loaders_manager.setup_loaders
|
13
14
|
self.converters = instantiate_subclasses(Bridgetown::Converter)
|
14
15
|
self.generators = instantiate_subclasses(Bridgetown::Generator)
|
15
16
|
end
|
@@ -8,29 +8,16 @@ class Bridgetown::Site
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
# Establish an SSR pipeline for a persistent backend process
|
11
|
-
def start_ssr!
|
11
|
+
def start_ssr!(loaders_manager: nil, &block)
|
12
12
|
if Bridgetown::Current.site
|
13
13
|
raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
|
14
14
|
"Check your Rack app for threading issues"
|
15
15
|
end
|
16
16
|
|
17
17
|
Bridgetown::PluginManager.require_from_bundler
|
18
|
-
site = new(Bridgetown::Current.preloaded_configuration)
|
18
|
+
site = new(Bridgetown::Current.preloaded_configuration, loaders_manager: loaders_manager)
|
19
19
|
site.enable_ssr
|
20
|
-
|
21
|
-
Bridgetown::Hooks.trigger :site, :pre_read, site
|
22
|
-
site.defaults_reader.tap do |d|
|
23
|
-
d.path_defaults.clear
|
24
|
-
d.read
|
25
|
-
end
|
26
|
-
site.layouts = Bridgetown::LayoutReader.new(site).read
|
27
|
-
site.collections.data.tap do |coll|
|
28
|
-
coll.read
|
29
|
-
site.data = coll.merge_data_resources
|
30
|
-
end
|
31
|
-
Bridgetown::Hooks.trigger :site, :post_read, site
|
32
|
-
|
33
|
-
yield(site) if block_given? # provide additional setup hook
|
20
|
+
site.ssr_setup(&block)
|
34
21
|
|
35
22
|
site
|
36
23
|
end
|
@@ -45,6 +32,41 @@ class Bridgetown::Site
|
|
45
32
|
@ssr_enabled = true
|
46
33
|
end
|
47
34
|
|
35
|
+
def ssr_setup(&block) # rubocop:disable Metrics/AbcSize
|
36
|
+
config.serving = true
|
37
|
+
Bridgetown::Hooks.trigger :site, :pre_read, self
|
38
|
+
defaults_reader.tap do |d|
|
39
|
+
d.path_defaults.clear
|
40
|
+
d.read
|
41
|
+
end
|
42
|
+
reader.read_layouts
|
43
|
+
collections.data.tap do |coll|
|
44
|
+
coll.read
|
45
|
+
self.data = coll.merge_data_resources
|
46
|
+
end
|
47
|
+
Bridgetown::Hooks.trigger :site, :post_read, self
|
48
|
+
|
49
|
+
hook = block&.(self) # provide additional setup hook
|
50
|
+
return if Bridgetown.env.production?
|
51
|
+
|
52
|
+
@ssr_reload_hook = hook if hook.is_a?(Proc) && hook.lambda?
|
53
|
+
Bridgetown::Watcher.watch(self, config)
|
54
|
+
end
|
55
|
+
|
56
|
+
def ssr_reload
|
57
|
+
reset soft: true
|
58
|
+
reader.read_layouts
|
59
|
+
|
60
|
+
collections.data.tap do |coll|
|
61
|
+
coll.resources.clear
|
62
|
+
coll.read
|
63
|
+
coll.merge_data_resources.each do |k, v|
|
64
|
+
data[k] = v
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@ssr_reload_hook.() if @ssr_reload_hook.is_a?(Proc)
|
68
|
+
end
|
69
|
+
|
48
70
|
def disable_ssr
|
49
71
|
Bridgetown.logger.info "SSR:", "now disabled."
|
50
72
|
@ssr_enabled = false
|
@@ -11,64 +11,68 @@ module Bridgetown
|
|
11
11
|
# Strings rather than symbols are used for compatibility with YAML.
|
12
12
|
DEFAULTS = {
|
13
13
|
# Where things are
|
14
|
-
"root_dir"
|
15
|
-
"plugins_dir"
|
16
|
-
"source"
|
17
|
-
"destination"
|
18
|
-
"collections_dir"
|
19
|
-
"cache_dir"
|
20
|
-
"layouts_dir"
|
21
|
-
"data_dir"
|
22
|
-
"components_dir"
|
23
|
-
"partials_dir"
|
24
|
-
"collections"
|
25
|
-
"taxonomies"
|
14
|
+
"root_dir" => Dir.pwd,
|
15
|
+
"plugins_dir" => "plugins",
|
16
|
+
"source" => File.join(Dir.pwd, "src"),
|
17
|
+
"destination" => File.join(Dir.pwd, "output"),
|
18
|
+
"collections_dir" => "",
|
19
|
+
"cache_dir" => ".bridgetown-cache",
|
20
|
+
"layouts_dir" => "_layouts",
|
21
|
+
"data_dir" => "_data",
|
22
|
+
"components_dir" => "_components",
|
23
|
+
"partials_dir" => "_partials",
|
24
|
+
"collections" => {},
|
25
|
+
"taxonomies" => {
|
26
26
|
category: { key: "categories", title: "Category" }, tag: { key: "tags", title: "Tag" },
|
27
27
|
},
|
28
|
+
"autoload_paths" => [],
|
29
|
+
"eager_load_paths" => [],
|
30
|
+
"autoloader_collapsed_paths" => [],
|
31
|
+
"plugins_use_zeitwerk" => true,
|
28
32
|
|
29
33
|
# Handling Reading
|
30
|
-
"include"
|
31
|
-
"exclude"
|
32
|
-
"keep_files"
|
33
|
-
"encoding"
|
34
|
-
"markdown_ext"
|
35
|
-
"strict_front_matter"
|
36
|
-
"slugify_mode"
|
34
|
+
"include" => [".htaccess", "_redirects", ".well-known"],
|
35
|
+
"exclude" => [],
|
36
|
+
"keep_files" => [".git", ".svn", "_bridgetown"],
|
37
|
+
"encoding" => "utf-8",
|
38
|
+
"markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
|
39
|
+
"strict_front_matter" => false,
|
40
|
+
"slugify_mode" => "pretty",
|
37
41
|
|
38
42
|
# Filtering Content
|
39
|
-
"future"
|
40
|
-
"unpublished"
|
41
|
-
"ruby_in_front_matter"
|
43
|
+
"future" => false,
|
44
|
+
"unpublished" => false,
|
45
|
+
"ruby_in_front_matter" => true,
|
42
46
|
|
43
47
|
# Conversion
|
44
|
-
"content_engine"
|
45
|
-
"markdown"
|
46
|
-
"highlighter"
|
47
|
-
"excerpt_separator"
|
48
|
+
"content_engine" => "resource",
|
49
|
+
"markdown" => "kramdown",
|
50
|
+
"highlighter" => "rouge",
|
51
|
+
"excerpt_separator" => "\n\n",
|
48
52
|
|
49
53
|
# Serving
|
50
|
-
"port"
|
51
|
-
"host"
|
52
|
-
"base_path"
|
53
|
-
"show_dir_listing"
|
54
|
+
"port" => "4000",
|
55
|
+
"host" => "127.0.0.1",
|
56
|
+
"base_path" => "/",
|
57
|
+
"show_dir_listing" => false,
|
54
58
|
|
55
59
|
# Output Configuration
|
56
|
-
"available_locales"
|
57
|
-
"default_locale"
|
58
|
-
"permalink"
|
59
|
-
"timezone"
|
60
|
+
"available_locales" => [:en],
|
61
|
+
"default_locale" => :en,
|
62
|
+
"permalink" => nil, # default is set according to content engine
|
63
|
+
"timezone" => nil, # use the local timezone
|
60
64
|
|
61
|
-
"quiet"
|
62
|
-
"verbose"
|
63
|
-
"defaults"
|
65
|
+
"quiet" => false,
|
66
|
+
"verbose" => false,
|
67
|
+
"defaults" => [],
|
64
68
|
|
65
|
-
"liquid"
|
69
|
+
"liquid" => {
|
66
70
|
"error_mode" => "warn",
|
67
71
|
"strict_filters" => false,
|
68
72
|
"strict_variables" => false,
|
69
73
|
},
|
70
74
|
|
71
|
-
"kramdown"
|
75
|
+
"kramdown" => {
|
72
76
|
"auto_ids" => true,
|
73
77
|
"toc_levels" => (1..6).to_a,
|
74
78
|
"entity_output" => "as_char",
|
@@ -98,6 +102,7 @@ module Bridgetown
|
|
98
102
|
def from(user_config, starting_defaults = DEFAULTS)
|
99
103
|
Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
|
100
104
|
.merge_environment_specific_options!
|
105
|
+
.setup_load_paths!
|
101
106
|
.setup_locales
|
102
107
|
.add_default_collections
|
103
108
|
.add_default_excludes
|
@@ -109,21 +114,21 @@ module Bridgetown
|
|
109
114
|
override[config_key] || self[config_key] || DEFAULTS[config_key]
|
110
115
|
end
|
111
116
|
|
112
|
-
#
|
117
|
+
# Directory of the top-level root where config files are located
|
113
118
|
#
|
114
|
-
# override
|
119
|
+
# @param override [Hash] options hash which will override value if key is present
|
115
120
|
#
|
116
|
-
#
|
117
|
-
def root_dir(override =
|
121
|
+
# @return [String] path to the Bridgetown root directory
|
122
|
+
def root_dir(override = {})
|
118
123
|
get_config_value_with_override("root_dir", override)
|
119
124
|
end
|
120
125
|
|
121
126
|
# Public: Directory of the Bridgetown source folder
|
122
127
|
#
|
123
|
-
# override
|
128
|
+
# @param override [Hash] options hash which will override value if key is present
|
124
129
|
#
|
125
|
-
#
|
126
|
-
def source(override =
|
130
|
+
# @return [String] path to the Bridgetown source directory
|
131
|
+
def source(override = {})
|
127
132
|
get_config_value_with_override("source", override)
|
128
133
|
end
|
129
134
|
|
@@ -240,6 +245,32 @@ module Bridgetown
|
|
240
245
|
self[k] = self[Bridgetown.environment][k]
|
241
246
|
end
|
242
247
|
delete(Bridgetown.environment)
|
248
|
+
|
249
|
+
self
|
250
|
+
end
|
251
|
+
|
252
|
+
def setup_load_paths!
|
253
|
+
if self[:plugins_use_zeitwerk]
|
254
|
+
autoload_paths.unshift({
|
255
|
+
path: self[:plugins_dir],
|
256
|
+
eager: true,
|
257
|
+
})
|
258
|
+
end
|
259
|
+
|
260
|
+
autoload_paths.map! do |load_path|
|
261
|
+
if load_path.is_a?(Hash)
|
262
|
+
expanded = File.expand_path(load_path[:path], root_dir)
|
263
|
+
self[:eager_load_paths] << expanded if load_path[:eager]
|
264
|
+
next expanded
|
265
|
+
end
|
266
|
+
|
267
|
+
File.expand_path(load_path, root_dir)
|
268
|
+
end
|
269
|
+
|
270
|
+
autoloader_collapsed_paths.map! do |collapsed_path|
|
271
|
+
File.expand_path(collapsed_path, root_dir)
|
272
|
+
end
|
273
|
+
|
243
274
|
self
|
244
275
|
end
|
245
276
|
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
# rubocop:disable all
|
4
4
|
|
5
|
-
TEMPLATE_PATH = File.expand_path("./bt-postcss", __dir__)
|
6
|
-
|
7
5
|
unless File.exist?("postcss.config.js")
|
8
6
|
error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
|
9
7
|
|
@@ -21,6 +19,6 @@ plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
|
|
21
19
|
say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
|
22
20
|
run "yarn add -D #{plugins.join(' ')}"
|
23
21
|
|
24
|
-
copy_file "
|
22
|
+
copy_file in_templates_dir("postcss.config.js"), "postcss.config.js", force: true
|
25
23
|
|
26
24
|
# rubocop:enable all
|
@@ -0,0 +1,17 @@
|
|
1
|
+
describe("Testing that links exist in the navbar", () => {
|
2
|
+
beforeEach(() => {
|
3
|
+
cy.visit("/");
|
4
|
+
});
|
5
|
+
it("navbar links appear on all pages", () => {
|
6
|
+
const baseUrl = Cypress.config("baseUrl");
|
7
|
+
|
8
|
+
cy.get('[href="/"]').click();
|
9
|
+
cy.url().should("eq", baseUrl + "/");
|
10
|
+
|
11
|
+
cy.get('[href="/posts"]').click();
|
12
|
+
cy.url().should("eq", baseUrl + "/posts");
|
13
|
+
|
14
|
+
cy.get('[href="/about"]').click();
|
15
|
+
cy.url().should("eq", baseUrl + "/about");
|
16
|
+
});
|
17
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/// <reference types="cypress" />
|
2
|
+
// ***********************************************************
|
3
|
+
// This example plugins/index.js can be used to load plugins
|
4
|
+
//
|
5
|
+
// You can change the location of this file or turn off loading
|
6
|
+
// the plugins file with the 'pluginsFile' configuration option.
|
7
|
+
//
|
8
|
+
// You can read more here:
|
9
|
+
// https://on.cypress.io/plugins-guide
|
10
|
+
// ***********************************************************
|
11
|
+
|
12
|
+
// This function is called when a project is opened or re-opened (e.g. due to
|
13
|
+
// the project's config changing)
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @type {Cypress.PluginConfig}
|
17
|
+
*/
|
18
|
+
module.exports = (on, config) => {
|
19
|
+
// `on` is used to hook into various events Cypress emits
|
20
|
+
// `config` is the resolved Cypress config
|
21
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// ***********************************************
|
2
|
+
// This example commands.js shows you how to
|
3
|
+
// create various custom commands and overwrite
|
4
|
+
// existing commands.
|
5
|
+
//
|
6
|
+
// For more comprehensive examples of custom
|
7
|
+
// commands please read more here:
|
8
|
+
// https://on.cypress.io/custom-commands
|
9
|
+
// ***********************************************
|
10
|
+
//
|
11
|
+
//
|
12
|
+
// -- This is a parent command --
|
13
|
+
// Cypress.Commands.add("login", (email, password) => { ... })
|
14
|
+
//
|
15
|
+
//
|
16
|
+
// -- This is a child command --
|
17
|
+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
|
18
|
+
//
|
19
|
+
//
|
20
|
+
// -- This is a dual command --
|
21
|
+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
|
22
|
+
//
|
23
|
+
//
|
24
|
+
// -- This will overwrite an existing command --
|
25
|
+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// ***********************************************************
|
2
|
+
// This example support/index.js is processed and
|
3
|
+
// loaded automatically before your test files.
|
4
|
+
//
|
5
|
+
// This is a great place to put global configuration and
|
6
|
+
// behavior that modifies Cypress.
|
7
|
+
//
|
8
|
+
// You can change the location of this file or turn off
|
9
|
+
// automatically serving support files with the
|
10
|
+
// 'supportFile' configuration option.
|
11
|
+
//
|
12
|
+
// You can read more here:
|
13
|
+
// https://on.cypress.io/configuration
|
14
|
+
// ***********************************************************
|
15
|
+
|
16
|
+
// Import commands.js using ES2015 syntax:
|
17
|
+
import './commands'
|
18
|
+
|
19
|
+
// Alternatively you can use CommonJS syntax:
|
20
|
+
// require('./commands')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
namespace :cy do
|
2
|
+
desc "Open Cypress test runner"
|
3
|
+
task :open do
|
4
|
+
system "yarn run cypress open"
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Run Cypress tests headless"
|
8
|
+
task :run do
|
9
|
+
system "yarn run cypress run"
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Start server and open Cypress test runner"
|
13
|
+
task :test do
|
14
|
+
ENV["BRIDGETOWN_ENV"] = "test"
|
15
|
+
server_pid = fork { Bridgetown::Commands::Start.start }
|
16
|
+
Rake::Task["cy:open"].execute
|
17
|
+
Process.kill "SIGTERM", server_pid
|
18
|
+
sleep 1 # give processes time to clean up
|
19
|
+
puts
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :test do
|
23
|
+
desc "Start server and run Cypress tests headless"
|
24
|
+
task :ci do
|
25
|
+
ENV["BRIDGETOWN_ENV"] = "test"
|
26
|
+
server_pid = fork { Bridgetown::Commands::Start.start }
|
27
|
+
Rake::Task["cy:run"].execute
|
28
|
+
Process.kill "SIGTERM", server_pid
|
29
|
+
sleep 1 # give processes time to clean up
|
30
|
+
puts
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Install packages
|
4
|
+
|
5
|
+
say "Installing Cypress...", :green
|
6
|
+
run "yarn add -D cypress"
|
7
|
+
|
8
|
+
# Copy cypress files and tasks into place
|
9
|
+
cypress_tasks = File.read(in_templates_dir("cypress_tasks"))
|
10
|
+
|
11
|
+
copy_file in_templates_dir("cypress.json"), "cypress.json"
|
12
|
+
inject_into_file("Rakefile", "\n#{cypress_tasks}")
|
13
|
+
directory in_templates_dir("cypress_dir"), "cypress"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# rubocop:disable all
|
4
4
|
|
5
|
-
say_status :minitesting, "Adding test gems
|
5
|
+
say_status :minitesting, "Adding test gems and examples"
|
6
6
|
|
7
7
|
append_to_file "Gemfile" do
|
8
8
|
<<~GEMS
|
@@ -18,12 +18,6 @@ append_to_file "Gemfile" do
|
|
18
18
|
GEMS
|
19
19
|
end
|
20
20
|
|
21
|
-
new_scripts = ' "test": "BRIDGETOWN_ENV=test yarn build",'
|
22
|
-
new_scripts += "\n" + ' "deploy:test": "bundle install --with test && yarn deploy"'
|
23
|
-
package_json = "package.json"
|
24
|
-
script_regex = %r{"scripts": \{(\s+".*,?)*}
|
25
|
-
inject_into_file(package_json, ",\n" + new_scripts, after: script_regex)
|
26
|
-
|
27
21
|
create_file "test/helper.rb" do
|
28
22
|
<<~RUBY
|
29
23
|
require "nokogiri"
|
@@ -32,23 +26,29 @@ create_file "test/helper.rb" do
|
|
32
26
|
require "minitest/profile"
|
33
27
|
require "shoulda"
|
34
28
|
require "rails-dom-testing"
|
29
|
+
|
35
30
|
# Report with color.
|
36
31
|
Minitest::Reporters.use! [
|
37
32
|
Minitest::Reporters::DefaultReporter.new(
|
38
33
|
color: true
|
39
34
|
),
|
40
35
|
]
|
36
|
+
|
41
37
|
Minitest::Test.class_eval do
|
42
38
|
include Rails::Dom::Testing::Assertions
|
39
|
+
|
43
40
|
def site
|
44
41
|
@site ||= Bridgetown.sites.first
|
45
42
|
end
|
43
|
+
|
46
44
|
def nokogiri(input)
|
47
45
|
input.respond_to?(:output) ? Nokogiri::HTML(input.output) : Nokogiri::HTML(input)
|
48
46
|
end
|
47
|
+
|
49
48
|
def document_root(root)
|
50
49
|
@document_root = root.is_a?(Nokogiri::XML::Document) ? root : nokogiri(root)
|
51
50
|
end
|
51
|
+
|
52
52
|
def document_root_element
|
53
53
|
if @document_root.nil?
|
54
54
|
raise "Call `document_root' with a Nokogiri document before testing your assertions"
|
@@ -62,12 +62,14 @@ end
|
|
62
62
|
create_file "test/test_homepage.rb" do
|
63
63
|
<<~RUBY
|
64
64
|
require_relative "./helper"
|
65
|
+
|
65
66
|
class TestHomepage < Minitest::Test
|
66
67
|
context "homepage" do
|
67
68
|
setup do
|
68
69
|
page = site.collections.pages.resources.find { |doc| doc.relative_url == "/" }
|
69
70
|
document_root page
|
70
71
|
end
|
72
|
+
|
71
73
|
should "exist" do
|
72
74
|
assert_select "body"
|
73
75
|
end
|
@@ -78,18 +80,20 @@ end
|
|
78
80
|
|
79
81
|
create_file "plugins/test_output.rb" do
|
80
82
|
<<~RUBY
|
81
|
-
|
82
|
-
Bridgetown
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
module TestOutput
|
84
|
+
unless Bridgetown.env.development?
|
85
|
+
Bridgetown::Hooks.register :site, :post_write do
|
86
|
+
# Load test suite to run on exit
|
87
|
+
require "nokogiri"
|
88
|
+
Dir["test/**/*.rb"].each { |file| require_relative("../\#{file}") }
|
89
|
+
rescue LoadError
|
90
|
+
Bridgetown.logger.warn "Testing:", "To run tests, you must first run \`bundle install --with test\`"
|
91
|
+
end
|
88
92
|
end
|
89
93
|
end
|
90
94
|
RUBY
|
91
95
|
end
|
92
96
|
|
93
|
-
say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`
|
97
|
+
say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`bin/bridgetown test\`"
|
94
98
|
|
95
99
|
# rubocop:enable all
|