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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +1 -2
  3. data/lib/bridgetown-core/cache.rb +1 -1
  4. data/lib/bridgetown-core/collection.rb +1 -1
  5. data/lib/bridgetown-core/commands/configure.rb +7 -0
  6. data/lib/bridgetown-core/commands/new.rb +1 -0
  7. data/lib/bridgetown-core/component.rb +2 -2
  8. data/lib/bridgetown-core/concerns/front_matter_importer.rb +1 -1
  9. data/lib/bridgetown-core/concerns/site/configurable.rb +6 -3
  10. data/lib/bridgetown-core/concerns/site/extensible.rb +2 -1
  11. data/lib/bridgetown-core/concerns/site/ssr.rb +38 -16
  12. data/lib/bridgetown-core/configuration.rb +77 -46
  13. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
  14. data/lib/bridgetown-core/configurations/cypress/cypress.json +4 -0
  15. data/lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json +5 -0
  16. data/lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js +17 -0
  17. data/lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js +21 -0
  18. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js +25 -0
  19. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js +20 -0
  20. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +33 -0
  21. data/lib/bridgetown-core/configurations/cypress.rb +13 -0
  22. data/lib/bridgetown-core/configurations/minitesting.rb +19 -15
  23. data/lib/bridgetown-core/configurations/netlify.rb +2 -4
  24. data/lib/bridgetown-core/configurations/purgecss.rb +2 -2
  25. data/lib/bridgetown-core/configurations/render/render.yaml.erb +26 -0
  26. data/lib/bridgetown-core/configurations/render.rb +6 -0
  27. data/lib/bridgetown-core/configurations/tailwindcss.rb +3 -5
  28. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  29. data/lib/bridgetown-core/core_ext/psych.rb +1 -5
  30. data/lib/bridgetown-core/frontmatter_defaults.rb +2 -2
  31. data/lib/bridgetown-core/liquid_renderer.rb +1 -1
  32. data/lib/bridgetown-core/model/base.rb +23 -26
  33. data/lib/bridgetown-core/model/builder_origin.rb +8 -6
  34. data/lib/bridgetown-core/model/origin.rb +10 -1
  35. data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
  36. data/lib/bridgetown-core/plugin_manager.rb +7 -34
  37. data/lib/bridgetown-core/rack/boot.rb +46 -23
  38. data/lib/bridgetown-core/rack/roda.rb +2 -1
  39. data/lib/bridgetown-core/rack/routes.rb +2 -2
  40. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  41. data/lib/bridgetown-core/readers/plugin_content_reader.rb +1 -1
  42. data/lib/bridgetown-core/renderer.rb +2 -2
  43. data/lib/bridgetown-core/resource/base.rb +3 -3
  44. data/lib/bridgetown-core/resource/relations.rb +1 -1
  45. data/lib/bridgetown-core/resource/taxonomy_term.rb +2 -2
  46. data/lib/bridgetown-core/resource/taxonomy_type.rb +2 -2
  47. data/lib/bridgetown-core/ruby_template_view.rb +2 -2
  48. data/lib/bridgetown-core/site.rb +15 -5
  49. data/lib/bridgetown-core/utils/loaders_manager.rb +72 -0
  50. data/lib/bridgetown-core/utils.rb +13 -14
  51. data/lib/bridgetown-core/version.rb +1 -1
  52. data/lib/bridgetown-core/watcher.rb +16 -7
  53. data/lib/bridgetown-core/yaml_parser.rb +1 -5
  54. data/lib/site_template/README.md +1 -1
  55. data/lib/site_template/Rakefile +3 -3
  56. metadata +16 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dd8600eb037c6f3841fdbc7a9175ecccd0ab4e3c7d1814e914b6954ad4fb832
4
- data.tar.gz: ca457af17e62de5d71a441b90d9aa8d97136fcd4cc9ecd65a855d8a78bab53b3
3
+ metadata.gz: 7e8dceaa24615a3a0de23c469444c2d22b36ce1f2c171177a9d20646f7b31446
4
+ data.tar.gz: 10c6c7e5c3bfc2a1f591d8953d098dae8d0d90942bb1ad6ef7871834cf658434
5
5
  SHA512:
6
- metadata.gz: 594d6e6de4a514e3eeb439a1ebc3d8936d4bb5027a78063db12c503072fe1c8b6db9d8f3ce6568a95781375d2e0c59dc32faf83fc333e8e9dcd3e95c140e7287
7
- data.tar.gz: fa2ad70a10323054e8f9ab646dfb92cc37457b53427907888dd8bc47589046feafcdc29730c3d4e6d3eb81cf8cd0be6cebbb692a32d8c3ec200c7a8c7fb80693
6
+ metadata.gz: 254a0d29eca611c8642acf2f664ace0dc8de883cf38dd00f56597dfc273625460089743e5ebc8e81df231035a8a1365393a5e890c1c4b1447d94fba48e310a2f
7
+ data.tar.gz: 48c9518b97fc1e890d8b04b908a117296def616657831c7d0572e9e611a58d3381870f9257f17303db965fa40d47b2280b3e2b814f02652b0b374e6ab4ab0f0d
@@ -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.5.0"
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..-1]).freeze
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..-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
@@ -153,6 +153,7 @@ module Bridgetown
153
153
  inside(path) do
154
154
  run "bundle install", abort_on_failure: true
155
155
  run "bundle binstubs bridgetown-core"
156
+ run "cp bin/bridgetown bin/bt"
156
157
  end
157
158
  end
158
159
  end
@@ -164,9 +164,9 @@ module Bridgetown
164
164
  end
165
165
  end
166
166
 
167
- ruby2_keywords def method_missing(method, *args, &block)
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..-1].join("\n"), file_path, 2)
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
- .map(&:components).compact
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
- @components_load_paths = plugin_components_load_paths + local_components_load_paths
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
- plugin_manager.setup_component_loaders
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! # rubocop:todo Metrics/AbcSize
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" => 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" => {
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" => [".htaccess", "_redirects", ".well-known"],
31
- "exclude" => [],
32
- "keep_files" => [".git", ".svn", "_bridgetown"],
33
- "encoding" => "utf-8",
34
- "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
35
- "strict_front_matter" => false,
36
- "slugify_mode" => "pretty",
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" => false,
40
- "unpublished" => false,
41
- "ruby_in_front_matter" => true,
43
+ "future" => false,
44
+ "unpublished" => false,
45
+ "ruby_in_front_matter" => true,
42
46
 
43
47
  # Conversion
44
- "content_engine" => "resource",
45
- "markdown" => "kramdown",
46
- "highlighter" => "rouge",
47
- "excerpt_separator" => "\n\n",
48
+ "content_engine" => "resource",
49
+ "markdown" => "kramdown",
50
+ "highlighter" => "rouge",
51
+ "excerpt_separator" => "\n\n",
48
52
 
49
53
  # Serving
50
- "port" => "4000",
51
- "host" => "127.0.0.1",
52
- "base_path" => "/",
53
- "show_dir_listing" => false,
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" => [:en],
57
- "default_locale" => :en,
58
- "permalink" => nil, # default is set according to content engine
59
- "timezone" => nil, # use the local 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" => false,
62
- "verbose" => false,
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
- # Public: Directory of the top-level root where config files are located
117
+ # Directory of the top-level root where config files are located
113
118
  #
114
- # override - the command-line options hash
119
+ # @param override [Hash] options hash which will override value if key is present
115
120
  #
116
- # Returns the path to the Bridgetown root directory
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 - the command-line options hash
128
+ # @param override [Hash] options hash which will override value if key is present
124
129
  #
125
- # Returns the path to the Bridgetown source directory
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 "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
22
+ copy_file in_templates_dir("postcss.config.js"), "postcss.config.js", force: true
25
23
 
26
24
  # rubocop:enable all
@@ -0,0 +1,4 @@
1
+ {
2
+ "baseUrl": "http://localhost:4000"
3
+ }
4
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -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, package.json scripts, and examples"
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
- unless Bridgetown.environment == "development"
82
- Bridgetown::Hooks.register :site, :post_write do
83
- # Load test suite to run on exit
84
- require "nokogiri"
85
- Dir["test/**/*.rb"].each { |file| require_relative("../\#{file}") }
86
- rescue LoadError
87
- Bridgetown.logger.warn "Testing:", "To run tests, you must first run \`bundle install --with test\`"
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 \`yarn test\`"
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