integration-tests-rails 0.1.0 → 0.2.0

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: 30f959f27b2ebdf182bc6a8107f851baeb5f77805e02bfff5bf2dc591faecb5c
4
- data.tar.gz: 4b5dbdb852a9aecef5346044bf3b6ddb2f3349fa92e62411d39af6bd6c8a1b05
3
+ metadata.gz: 9916abfc2916528985a38a6d5c2741302f82ef36d9df705ff2b9fda7a22ceeaa
4
+ data.tar.gz: 5833c85dfde621c4cb5e4cb943e5e10016bb2396e74fa757225c6d9625be32e1
5
5
  SHA512:
6
- metadata.gz: f52d395e2dd5ab6fe1726e050f28c9dd34b8153a6d6e7b45dabd61ac15b0a1bac9f5aa15d49e1bc5247d0a2c42e84b9ee9ec0c98bb831ec6a535d526a77c5cb0
7
- data.tar.gz: f370d6841dfc1a179f8cf20aee07ff137f6f38f45eceeabb1838e0a5cde9902d9d04c5df8b7e5e498ce5c9fdb43d3db1de03f27bb5069359bc5d46f099fc614c
6
+ metadata.gz: f39e37e76d26a9ab4fd2b1309bc7d43c2f9c9ef8b82b03797d7302442f91c7b976afb268b9c9172314acfeb92bd1c252d73673b6732f486858e394b3882235c2
7
+ data.tar.gz: a63727ace5e18a8179f656adc83b1a142aee728850346cb34df62806cb3f011bf16c92267a812e3813ccd335df7e8e37b429c8bc946d3f50bf0fbf6223ab6ff3
data/README.md CHANGED
@@ -52,6 +52,7 @@ Since test suites can vary greatly between applications, manual setup of the con
52
52
  ```ruby
53
53
  # spec/capybara_helper.rb
54
54
 
55
+ require 'rails_helper'
55
56
  require 'integration_tests_rails'
56
57
 
57
58
  IntegrationTestsRails.setup
@@ -92,11 +93,11 @@ class TestsController < ActionController::Base
92
93
  <meta charset="UTF-8">
93
94
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
94
95
  <meta name="turbo-visit-control" content="reload">
95
- <%%= csrf_meta_tags %>
96
- <%%= csp_meta_tag %>
97
- <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
98
- <%%= stylesheet_link_tag 'custom', "data-turbo-track": "reload" %>
99
- <%%= javascript_importmap_tags %>
96
+ <%= csrf_meta_tags %>
97
+ <%= csp_meta_tag %>
98
+ <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
99
+ <%= stylesheet_link_tag 'custom', "data-turbo-track": "reload" %>
100
+ <%= javascript_importmap_tags %>
100
101
  </head>
101
102
  <body>
102
103
  </body>
@@ -116,11 +117,11 @@ Since vendored JavaScript are not included by default, additional tags may be re
116
117
  <meta charset="UTF-8">
117
118
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
118
119
  <meta name="turbo-visit-control" content="reload">
119
- <%%= csrf_meta_tags %>
120
- <%%= csp_meta_tag %>
121
- <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
122
- <%%= stylesheet_link_tag 'custom', "data-turbo-track": "reload" %>
123
- <%%= javascript_importmap_tags %>
120
+ <%= csrf_meta_tags %>
121
+ <%= csp_meta_tag %>
122
+ <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
123
+ <%= stylesheet_link_tag 'custom', "data-turbo-track": "reload" %>
124
+ <%= javascript_importmap_tags %>
124
125
 
125
126
  <script type="module">
126
127
  import CustomCode from 'custom_code';
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This provides a minimal page that loads your JavaScript
4
+ class TestsController < ActionController::Base
5
+ def index
6
+ render inline: IntegrationTestsRails.configuration.tests_page_html
7
+ end
8
+ end
@@ -41,6 +41,12 @@ module IntegrationTestsRails
41
41
  end
42
42
  end
43
43
 
44
+ def configure_routes
45
+ Rails.application.routes.append do
46
+ resources :tests, only: :index
47
+ end
48
+ end
49
+
44
50
  def verbose?
45
51
  IntegrationTestsRails.configuration.verbose
46
52
  end
@@ -4,6 +4,7 @@ require 'capybara/cuprite'
4
4
  require_relative 'capybara/util'
5
5
  require_relative 'capybara/remote'
6
6
  require_relative 'capybara/local'
7
+ require_relative 'capybara/tests_controller'
7
8
 
8
9
  module IntegrationTestsRails
9
10
  # This contains the Capybara setup and configuration.
@@ -22,6 +23,7 @@ module IntegrationTestsRails
22
23
 
23
24
  Util.configure_rspec
24
25
  Util.configure_webmock
26
+ Util.configure_routes
25
27
  end
26
28
  end
27
29
  end
@@ -3,8 +3,39 @@
3
3
  module IntegrationTestsRails
4
4
  # Configuration class for this gem to modify adjustable settings for Capybara, Cuprite and Istanbul.
5
5
  class Configuration
6
- attr_accessor :source_dir, :output_dir, :backup_dir, :coverage_path, :wait_time, :remote, :chrome_url,
7
- :verbose, :timeout, :server_host, :server_port, :puma_threads, :window_size, :max_server_retries
6
+ DEFAULT_HTML_CONTENT = <<~HTML.squish
7
+ <!DOCTYPE html>
8
+ <html lang="en">
9
+ <head>
10
+ <meta charset="UTF-8">
11
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
12
+ <meta name="turbo-visit-control" content="reload">
13
+ <%= csrf_meta_tags %>
14
+ <%= csp_meta_tag %>
15
+ <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
16
+ <%= stylesheet_link_tag 'custom', "data-turbo-track": "reload" %>
17
+ <%= javascript_importmap_tags %>
18
+ <!-- If there are JavaScript libraries not globally available, include them here for testing.-->
19
+ <!-- E.g. The block below shows how to import a JavaScript module and attach it to the window object. -->
20
+ <!-- The file is located in app/javascripts/libs/my_library.js -->
21
+ <!--
22
+ <script type="module">
23
+ import MyLibrary from 'libs/my_library';
24
+ window.MyLibrary = MyLibrary;
25
+ </script>
26
+ -->
27
+ </head>
28
+ <body>
29
+ <!-- Include JavaScript libraries here instead if they need to be loaded much later. -->
30
+ <!-- E.g. The line below loads a JavaScript file located in app/assets/javascripts/plugins/vendor.min.js -->
31
+ <%#= javascript_include_tag 'plugins/vendor.min' %>
32
+ </body>
33
+ </html>
34
+ HTML
35
+
36
+ attr_accessor :source_dir, :output_dir, :backup_dir, :coverage_path, :wait_time, :remote,
37
+ :chrome_url, :tests_page_html, :window_size, :max_server_retries,
38
+ :verbose, :timeout, :server_host, :server_port, :puma_threads
8
39
 
9
40
  def initialize
10
41
  @backup_dir = 'tmp/js_backup'
@@ -17,6 +48,7 @@ module IntegrationTestsRails
17
48
  @server_host = '0.0.0.0' # rubocop:disable Style/IpAddresses
18
49
  @server_port = nil
19
50
  @source_dir = 'app/javascript'
51
+ @tests_page_html = DEFAULT_HTML_CONTENT
20
52
  @timeout = 30
21
53
  @verbose = false
22
54
  @wait_time = 5
@@ -8,7 +8,6 @@ module IntegrationTestsRails
8
8
  def configure_rspec
9
9
  RSpec.configure do |config|
10
10
  config.before(:suite) do
11
- Instrumenter.instrument_all
12
11
  Collector.setup
13
12
  end
14
13
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IntegrationTestsRails
4
+ # Railtie to integrate with Rails applications.
5
+ class Railtie < Rails::Railtie
6
+ # rubocop:disable Metrics/BlockLength
7
+ rake_tasks do
8
+ namespace :integration_tests_rails do
9
+ desc 'Set up integration tests environment.'
10
+ task install: :environment do
11
+ unless system('which yarn > /dev/null 2>&1')
12
+ puts 'Yarn is not installed. Please install Yarn first: https://yarnpkg.com/getting-started/install'
13
+ exit 1
14
+ end
15
+
16
+ puts 'Installing Istanbul...'
17
+ system('yarn add --dev istanbul-lib-instrument istanbul-lib-coverage istanbul-lib-report istanbul-reports')
18
+ system('yarn install')
19
+
20
+ puts 'Updating .gitignore...'
21
+ gitignore_path = '.gitignore'
22
+ lines_to_add = ['node_modules/', 'coverage/', 'tmp/instrumented_js/', 'tmp/js_backup/']
23
+
24
+ if File.exist?(gitignore_path)
25
+ content = File.read(gitignore_path)
26
+ lines_to_add.each do |line|
27
+ if content.include?(line)
28
+ puts "'#{line}' already exists in .gitignore."
29
+ else
30
+ File.open(gitignore_path, 'a') { |file| file.puts line }
31
+ puts "Added '#{line}' to .gitignore."
32
+ end
33
+ end
34
+ else
35
+ puts '.gitignore does not exist. Skipping.'
36
+ end
37
+
38
+ puts 'Integration tests environment setup complete.'
39
+ end
40
+ end
41
+ end
42
+ # rubocop:enable Metrics/BlockLength
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IntegrationTestsRails
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'integration_tests_rails/version'
4
+ require_relative 'integration_tests_rails/railtie'
5
+
6
+ return unless Rails.env.test?
7
+
4
8
  require_relative 'integration_tests_rails/configuration'
5
9
  require_relative 'integration_tests_rails/istanbul'
6
10
  require_relative 'integration_tests_rails/capybara'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: integration-tests-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tien
@@ -87,19 +87,19 @@ extra_rdoc_files: []
87
87
  files:
88
88
  - MIT-LICENSE
89
89
  - README.md
90
- - lib/generators/integration_tests_rails/install_generator.rb
91
- - lib/generators/integration_tests_rails/templates/tests_controller.rb
92
90
  - lib/integration_tests_rails.rb
93
91
  - lib/integration_tests_rails/capybara.rb
94
92
  - lib/integration_tests_rails/capybara/helpers.rb
95
93
  - lib/integration_tests_rails/capybara/local.rb
96
94
  - lib/integration_tests_rails/capybara/remote.rb
95
+ - lib/integration_tests_rails/capybara/tests_controller.rb
97
96
  - lib/integration_tests_rails/capybara/util.rb
98
97
  - lib/integration_tests_rails/configuration.rb
99
98
  - lib/integration_tests_rails/istanbul.rb
100
99
  - lib/integration_tests_rails/istanbul/collector.rb
101
100
  - lib/integration_tests_rails/istanbul/instrumenter.rb
102
101
  - lib/integration_tests_rails/istanbul/util.rb
102
+ - lib/integration_tests_rails/railtie.rb
103
103
  - lib/integration_tests_rails/version.rb
104
104
  homepage: https://github.com/tieeeeen1994/integration-tests-rails
105
105
  licenses:
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
-
5
- module IntegrationTestsRails
6
- module Generators
7
- # Generator responsible for setting up the Rails project with necessary tools to make integration testing possible.
8
- class InstallGenerator < Rails::Generators::Base
9
- source_root File.expand_path('templates', __dir__)
10
-
11
- desc 'Initialize project for integration testing.'
12
-
13
- def install_node_dependencies
14
- unless system('which yarn > /dev/null 2>&1')
15
- say 'Yarn is not installed. Please install Yarn first: https://yarnpkg.com/getting-started/install', :red
16
- exit 1
17
- end
18
-
19
- say 'Installing Istanbul...', :green
20
- run 'yarn add --dev istanbul-lib-instrument istanbul-lib-coverage istanbul-lib-report istanbul-reports'
21
- run 'yarn install'
22
- end
23
-
24
- def copy_tests_controller
25
- template 'tests_controller.rb', 'spec/support/features/tests_controller.rb'
26
- end
27
-
28
- def add_route
29
- route 'resources(:tests, only: :index) if Rails.env.test?'
30
- end
31
-
32
- def update_gitignore
33
- gitignore_path = '.gitignore'
34
- lines_to_add = ['node_modules/', 'coverage/']
35
-
36
- return unless File.exist?(gitignore_path)
37
-
38
- content = File.read(gitignore_path)
39
- lines_to_add.each do |line|
40
- if content.include?(line)
41
- say "'#{line}' already exists in .gitignore", :blue
42
- else
43
- append_to_file gitignore_path, "\n#{line}\n"
44
- say "Added '#{line}' to .gitignore", :green
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This provides a minimal page that loads your JavaScript
4
- class TestsController < ActionController::Base
5
- def index
6
- render inline: <<~HTML.squish
7
- <!DOCTYPE html>
8
- <html lang="en">
9
- <head>
10
- <meta charset="UTF-8">
11
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
12
- <meta name="turbo-visit-control" content="reload">
13
- <%%= csrf_meta_tags %>
14
- <%%= csp_meta_tag %>
15
- <%%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
16
- <%%= stylesheet_link_tag 'custom', "data-turbo-track": "reload" %>
17
- <%%= javascript_importmap_tags %>
18
- <!-- If there are JavaScript libraries not globally available, include them here for testing.-->
19
- <!-- E.g. The block below shows how to import a JavaScript module and attach it to the window object. -->
20
- <!-- The file is located in app/javascripts/libs/my_library.js -->
21
- <!--
22
- <script type="module">
23
- import MyLibrary from 'libs/my_library';
24
- window.MyLibrary = MyLibrary;
25
- </script>
26
- -->
27
- </head>
28
- <body>
29
- <!-- Include JavaScript libraries here instead if they need to be loaded much later. -->
30
- <!-- E.g. The line below loads a JavaScript file located in app/assets/javascripts/plugins/vendor.min.js -->
31
- <%%#= javascript_include_tag 'plugins/vendor.min' %>
32
- </body>
33
- </html>
34
- HTML
35
- end
36
- end