integration-tests-rails 0.1.0 → 0.2.1
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/README.md +11 -10
- data/lib/integration_tests_rails/capybara/tests_controller.rb +8 -0
- data/lib/integration_tests_rails/capybara/util.rb +6 -0
- data/lib/integration_tests_rails/capybara.rb +2 -0
- data/lib/integration_tests_rails/configuration.rb +34 -2
- data/lib/integration_tests_rails/istanbul/util.rb +0 -1
- data/lib/integration_tests_rails/railtie.rb +44 -0
- data/lib/integration_tests_rails/version.rb +1 -1
- data/lib/integration_tests_rails.rb +4 -0
- metadata +3 -3
- data/lib/generators/integration_tests_rails/install_generator.rb +0 -50
- data/lib/generators/integration_tests_rails/templates/tests_controller.rb +0 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc1de1cb826d7842a9701bb161adae9ab10d4e37a71e0bf274c1b47fac502efa
|
|
4
|
+
data.tar.gz: 1c5f770ae1aac4871d6fa3e809071c10865e7301c1187d2b288198a8921b8e46
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f250652f859734d9683f756c967b7410346e0a31b19904e61a7de1ab550ff93c0b9a59da0006885b0dc4ee4e1c08415cc3f5f7f36c4d6279f091029745b8e103
|
|
7
|
+
data.tar.gz: 053d8a4fb259add5302cb7c4d666c5b8eae21298e6bba12c0d3a6b624dec2485cb0d63e3205b044b411284a1ab5360e65328d3b7f0d6748cb6890b430adc49d5
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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';
|
|
@@ -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
|
-
|
|
7
|
-
|
|
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
|
|
@@ -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,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? && defined?(RSpec) && defined?(Capybara) && defined?(Cuprite)
|
|
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
|
|
4
|
+
version: 0.2.1
|
|
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
|