test-recorder 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 745f47568a578d0d76e8558dc16fd6277045cd86dca6a09f38b4914b90e09775
4
- data.tar.gz: 9ec908cb4e136d8137d5304c77594fd0d88e81070ff5b086198035e5cdef1d39
3
+ metadata.gz: 3b7a9be6d6179b7ea6275e1e9b9463817dd0062452ca6b45c95c85dd9a3d8840
4
+ data.tar.gz: af977f2a4990f75f107210dd50b3f4c755f5efdbc7779e9c070dc480a715e4d1
5
5
  SHA512:
6
- metadata.gz: f3962a434f3c98a2dfdd9840cf60205795cc175a18b34d2eb3dd66f6c1ec43603f9b6bd53cc0970811e1cfd6cb54149bdef3db2858173db72769f75a191b750e
7
- data.tar.gz: 97b93c654e9125cf0732c803e49808d4fb6a72402827307708cd52853d21def581843c9d8da877b027206d322cebae31a9efab655f28617212adfc4e299152f2
6
+ metadata.gz: 9f0faa3366d09f18b142ed4f5c42fa9ae1a7be31c8359eccae8695004920a973188880e0599759fc8b480e4c3e080d3a6985931d5d34fea2e349d36ed4d8005e
7
+ data.tar.gz: 634c35482c87795803ed7509d5042c357c440e876f03e6969a80501ca7d6e80b8b71292f1d13e9199e1c37dcf72763026b05e4c07fd91851a50162dc6e309ed8
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ concurrency:
10
+ group: ${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '3.0.3'
18
+ - uses: actions/setup-node@v1
19
+ with:
20
+ node-version: '14'
21
+ - name: Install ffmpeg
22
+ run: |
23
+ sudo apt update && sudo apt install ffmpeg
24
+ - name: Install dependencies
25
+ run: |
26
+ gem install bundler --no-document
27
+ bundle install
28
+ - name: Run test
29
+ run: bundle exec rake
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in videotest-recorder.gemspec
3
+ # Specify your gem's dependencies in test-recorder.gemspec
4
4
  gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
+ gem "debug"
data/Gemfile.lock CHANGED
@@ -1,75 +1,56 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-recorder (0.1.0)
5
- headless
6
- railties
4
+ test-recorder (0.1.3)
5
+ activesupport
6
+ selenium-devtools
7
+ selenium-webdriver (>= 4.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- actionpack (6.0.3.4)
12
- actionview (= 6.0.3.4)
13
- activesupport (= 6.0.3.4)
14
- rack (~> 2.0, >= 2.0.8)
15
- rack-test (>= 0.6.3)
16
- rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
18
- actionview (6.0.3.4)
19
- activesupport (= 6.0.3.4)
20
- builder (~> 3.1)
21
- erubi (~> 1.4)
22
- rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
24
- activesupport (6.0.3.4)
12
+ activesupport (7.0.1)
25
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
- i18n (>= 0.7, < 2)
27
- minitest (~> 5.1)
28
- tzinfo (~> 1.1)
29
- zeitwerk (~> 2.2, >= 2.2.2)
30
- builder (3.2.4)
31
- concurrent-ruby (1.1.7)
32
- crass (1.0.6)
33
- erubi (1.9.0)
34
- headless (2.3.1)
35
- i18n (1.8.5)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ activesupport-testing-metadata (0.1.0)
18
+ activesupport (>= 4.0)
19
+ childprocess (4.1.0)
20
+ concurrent-ruby (1.1.9)
21
+ debug (1.4.0)
22
+ irb (>= 1.3.6)
23
+ reline (>= 0.2.7)
24
+ i18n (1.8.11)
36
25
  concurrent-ruby (~> 1.0)
37
- loofah (2.7.0)
38
- crass (~> 1.0.2)
39
- nokogiri (>= 1.5.9)
40
- method_source (1.0.0)
41
- mini_portile2 (2.4.0)
26
+ io-console (0.5.11)
27
+ irb (1.4.1)
28
+ reline (>= 0.3.0)
42
29
  minitest (5.14.2)
43
- nokogiri (1.10.10)
44
- mini_portile2 (~> 2.4.0)
45
- rack (2.2.3)
46
- rack-test (1.1.0)
47
- rack (>= 1.0, < 3)
48
- rails-dom-testing (2.0.3)
49
- activesupport (>= 4.2.0)
50
- nokogiri (>= 1.6)
51
- rails-html-sanitizer (1.3.0)
52
- loofah (~> 2.3)
53
- railties (6.0.3.4)
54
- actionpack (= 6.0.3.4)
55
- activesupport (= 6.0.3.4)
56
- method_source
57
- rake (>= 0.8.7)
58
- thor (>= 0.20.3, < 2.0)
59
30
  rake (12.3.3)
60
- thor (1.0.1)
61
- thread_safe (0.3.6)
62
- tzinfo (1.2.7)
63
- thread_safe (~> 0.1)
64
- zeitwerk (2.4.0)
31
+ reline (0.3.1)
32
+ io-console (~> 0.5)
33
+ rexml (3.2.5)
34
+ rubyzip (2.3.2)
35
+ selenium-devtools (0.100.0)
36
+ websocket (~> 1.0)
37
+ selenium-webdriver (4.1.0)
38
+ childprocess (>= 0.5, < 5.0)
39
+ rexml (~> 3.2, >= 3.2.5)
40
+ rubyzip (>= 1.2.2)
41
+ tzinfo (2.0.4)
42
+ concurrent-ruby (~> 1.0)
43
+ websocket (1.2.9)
65
44
 
66
45
  PLATFORMS
67
46
  ruby
68
47
 
69
48
  DEPENDENCIES
49
+ activesupport-testing-metadata
50
+ debug
70
51
  minitest (~> 5.0)
71
52
  rake (~> 12.0)
72
53
  test-recorder!
73
54
 
74
55
  BUNDLED WITH
75
- 2.1.4
56
+ 2.2.32
data/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Videotest::Recorder
1
+ # TestRecorder
2
+
3
+ Record a video automatically when tests failed. The videos are generated in `tmp/videos` directory.
4
+
5
+ [![Build Status](https://github.com/y-yagi/test-recorder/workflows/CI/badge.svg)](https://github.com/y-yagi/test-recorder/actions)
6
+ [![Gem Version](https://badge.fury.io/rb/test-recorder.svg)](http://badge.fury.io/rb/test-recorder)
7
+
8
+
9
+ ## Requirements
10
+
11
+ This gem depends on FFmpeg. Please install that package.
12
+
13
+ On Debian/Ubuntu:
14
+
15
+ ```bash
16
+ sudo apt-get install ffmpeg
17
+ ```
18
+
19
+ ## Supported libraries
20
+
21
+ Rails system tests and RSpec(System Spec and Feature Spec).
22
+
23
+ ## Limitations
24
+
25
+ Currently, this gem only supports a Headless Chrome.
26
+
27
+ ## Usage
28
+
29
+ ### 1: Install the gem
30
+
31
+ Using Bundler, add the following to your Gemfile:
32
+
33
+ ```ruby
34
+ gem 'test-recorder', group: :test
35
+ ```
36
+
37
+ ### 2: Load library into your tests
38
+
39
+ #### Rails
40
+
41
+ ```ruby
42
+ require 'test_recorder/rails'
43
+ ```
44
+
45
+ #### RSpec
46
+
47
+ ```ruby
48
+ require 'test_recorder/rspec'
49
+ ```
50
+
51
+ ### Only record specific tests
52
+
53
+ `TestRecorder` records all tests by default. But if you want to limit the tests, you can do it by specifying metadata.
54
+
55
+ #### Rails
56
+
57
+ ##### 1: Install the additional Gem
58
+
59
+ Using Bundler, add the following to your Gemfile:
60
+
61
+ ```ruby
62
+ gem 'activesupport-testing-metadata', group: :test
63
+ ```
64
+
65
+ ##### 2. Disable `TestRecorder`, and specified tests with the tag
66
+
67
+ ```ruby
68
+ # test/test_helper.rb
69
+ require 'test_recorder/rails'
70
+ require 'active_support/testing/metadata'
71
+
72
+ TestRecorder.disable!
73
+ ```
74
+
75
+ ```ruby
76
+ test "test to something", test_recorder: true do
77
+ # ...
78
+ end
79
+ ```
80
+
81
+ #### RSpec
82
+
83
+ You don't need to install other gems. Only disable `TestRecorder`, and specified tests with the tag.
84
+
85
+ ```ruby
86
+ # test/test_helper.rb
87
+ require 'test_recorder/rspec'
88
+
89
+ TestRecorder.disable!
90
+ ```
91
+
92
+ ```ruby
93
+ it "test to something", test_recorder: true do
94
+ # ...
95
+ end
2
96
 
3
- :hammer_and_pick: WIP :hammer_and_pick:
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ Rake::TestTask.new(:test) do |t|
6
6
  t.libs << "lib"
7
7
  t.verbose = true
8
8
  t.warning = true
9
- t.test_files = FileList["test/**/*_test.rb"]
9
+ t.test_files = ["test/integration_test.rb"]
10
10
  end
11
11
 
12
12
  task :default => :test
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "videotest/recorder"
4
+ require "test_recorder"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,57 @@
1
+ require "open3"
2
+ require "fileutils"
3
+ require "tempfile"
4
+
5
+ module TestRecorder
6
+ class CdpRecorder
7
+ def initialize(enabled:)
8
+ @enabled = enabled
9
+ setup
10
+ end
11
+
12
+ def setup
13
+ @video_dir = ::Rails.root.join("tmp", "videos")
14
+ FileUtils.mkdir_p(@video_dir)
15
+ end
16
+
17
+ def start(page:, enabled: nil)
18
+ enabled = @enabled if enabled.nil?
19
+ return unless enabled
20
+
21
+ @tmp_video = Tempfile.open(["testrecorder", ".mp4"])
22
+ cmd = "ffmpeg -loglevel quiet -f image2pipe -avioflags direct -fpsprobesize 0 -probesize 32 -analyzeduration 0 -c:v mjpeg -i - -y -an -r 25 -qmin 0 -qmax 50 -crf 8 -deadline realtime -speed 8 -b:v 1M -threads 1 #{@tmp_video.path}"
23
+ @stdin, @wait_thrs = *Open3.pipeline_w(cmd)
24
+ @stdin.set_encoding("ASCII-8BIT")
25
+
26
+ @page = page
27
+ @page.driver.browser.devtools.page.enable
28
+
29
+ @page.driver.browser.devtools.page.on(:screencast_frame) do |event|
30
+ unless @stdin.closed?
31
+ decoded_data = Base64.decode64(event["data"])
32
+ @stdin.print(decoded_data)
33
+ end
34
+
35
+ @page.driver.browser.devtools.page.screencast_frame_ack(session_id: event["sessionId"])
36
+ end
37
+
38
+ @page.driver.browser.devtools.page.start_screencast(format: "jpeg", quality: 90)
39
+ end
40
+
41
+ def stop_and_discard
42
+ @stdin.close
43
+ end
44
+
45
+ def stop_and_save(filename)
46
+ return if @page.nil?
47
+
48
+ @stdin.close
49
+ @wait_thrs.each(&:join)
50
+
51
+ video_path = File.join(@video_dir, filename)
52
+ FileUtils.copy(@tmp_video.path, video_path)
53
+ @tmp_video.close(true)
54
+ video_path
55
+ end
56
+ end
57
+ end
@@ -1,30 +1,23 @@
1
- require "headless"
2
1
  require "fileutils"
3
2
 
4
3
  module TestRecorder
5
4
  module Rails
6
5
  module SetupAndTeardown
7
- attr_reader :video_dir, :headless
8
-
9
6
  def before_setup
10
- @video_dir = ::Rails.root.join("tmp", "videos")
11
- FileUtils.mkdir_p(video_dir)
12
7
 
13
- # TODO: Allow configuring parameters.
14
- @headless = Headless.new(video: { provider: :ffmpeg, codec: :libx264, extra: %w(-preset ultrafast) })
15
- headless.start
16
- headless.video.start_capture
8
+ @cdp_recorder = TestRecorder::CdpRecorder.new(enabled: TestRecorder.enabled?)
9
+ enabled = respond_to?(:metadata) ? metadata[:test_recorder] : nil
10
+ @cdp_recorder.start(page: page, enabled: enabled)
17
11
 
18
12
  super
19
13
  end
20
14
 
21
15
  def before_teardown
22
16
  if failures.empty?
23
- headless.video.stop_and_discard
17
+ @cdp_recorder.stop_and_discard
24
18
  else
25
- video = video_dir.join("failures_#{self.name}.mp4")
26
- headless.video.stop_and_save(video)
27
- puts "[Video]: #{video}"
19
+ video_path = @cdp_recorder.stop_and_save("failures_#{self.name}.mp4")
20
+ puts "[Video]: #{video_path}" if File.exist?(video_path)
28
21
  end
29
22
  ensure
30
23
  super
@@ -1,3 +1,4 @@
1
+ require "test_recorder/cdp_recorder"
1
2
  require "test_recorder/rails/setup_and_teardown"
2
3
 
3
4
  ActiveSupport.on_load(:action_dispatch_system_test_case) do
@@ -0,0 +1,13 @@
1
+ module TestRecorder
2
+ module RSpec
3
+ module ExampleWrapper
4
+ def run_before_example
5
+ super
6
+ TestRecorder::RSpec.cdp_recorder.start(
7
+ page: @example_group_instance.page,
8
+ enabled: self.metadata[:test_recorder]
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,20 +1,21 @@
1
- require "headless"
2
- require "fileutils"
1
+ require "test_recorder/cdp_recorder"
2
+ require "test_recorder/rspec/example_wrapper"
3
3
 
4
4
  module TestRecorder
5
- module Rspec
5
+ module RSpec
6
6
  CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
7
7
 
8
8
  class << self
9
- attr_accessor :headless, :video_dir
9
+ attr_accessor :cdp_recorder
10
10
 
11
11
  def after_failed_example(example)
12
12
  if example.exception
13
- video = video_dir.join("failures_#{method_name(example)}.mp4")
14
- headless.video.stop_and_save(video)
15
- example.metadata[:extra_failure_lines] = [example.metadata[:extra_failure_lines], "[Video]: #{video}"]
13
+ video_path = cdp_recorder.stop_and_save("failures_#{method_name(example)}.mp4").to_s
14
+ if File.exist?(video_path)
15
+ example.metadata[:extra_failure_lines] = [example.metadata[:extra_failure_lines], "[Video]: #{video_path}"].flatten
16
+ end
16
17
  else
17
- headless.video.stop_and_discard
18
+ cdp_recorder.stop_and_discard
18
19
  end
19
20
  end
20
21
 
@@ -25,21 +26,16 @@ module TestRecorder
25
26
  end
26
27
  end
27
28
 
28
- RSpec.configure do |config|
29
- config.before do
30
- TestRecorder::Rspec.video_dir = ::Rails.root.join("tmp", "videos")
31
- FileUtils.mkdir_p(TestRecorder::Rspec.video_dir)
29
+ RSpec::Core::Example.prepend(TestRecorder::RSpec::ExampleWrapper)
32
30
 
33
- TestRecorder::Rspec.headless = Headless.new(video: { provider: :ffmpeg, codec: :libx264, extra: %w(-preset ultrafast) })
34
- TestRecorder::Rspec.headless.start
35
- TestRecorder::Rspec.headless.video.start_capture
36
- end
31
+ RSpec.configure do |config|
32
+ TestRecorder::RSpec.cdp_recorder = TestRecorder::CdpRecorder.new(enabled: TestRecorder.enabled?)
37
33
 
38
34
  config.after(type: :system) do |example|
39
- TestRecorder::Rspec.after_failed_example(example)
35
+ TestRecorder::RSpec.after_failed_example(example)
40
36
  end
41
37
 
42
38
  config.after(type: :feature) do |example|
43
- TestRecorder::Rspec.after_failed_example(example)
39
+ TestRecorder::RSpec.after_failed_example(example)
44
40
  end
45
41
  end
@@ -1,3 +1,3 @@
1
1
  module TestRecorder
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/test_recorder.rb CHANGED
@@ -1 +1,17 @@
1
1
  require "test_recorder/version"
2
+
3
+ module TestRecorder
4
+ class << self
5
+ def enable!
6
+ @enable = true
7
+ end
8
+
9
+ def disable!
10
+ @enable = false
11
+ end
12
+
13
+ def enabled?
14
+ defined?(@enable) ? @enable : true
15
+ end
16
+ end
17
+ end
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.bindir = "exe"
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
- spec.add_dependency "headless"
23
- spec.add_dependency "railties"
22
+ spec.add_dependency "activesupport"
23
+ spec.add_dependency "selenium-webdriver", ">= 4.0"
24
+ spec.add_dependency "selenium-devtools"
25
+ spec.add_development_dependency "activesupport-testing-metadata"
24
26
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Yaginuma
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-23 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: headless
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: railties
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: selenium-devtools
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport-testing-metadata
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description:
42
70
  email:
43
71
  - yuuji.yaginuma@gmail.com
@@ -45,6 +73,7 @@ executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
76
+ - ".github/workflows/ci.yml"
48
77
  - ".gitignore"
49
78
  - Gemfile
50
79
  - Gemfile.lock
@@ -55,9 +84,11 @@ files:
55
84
  - bin/setup
56
85
  - lib/test-recorder.rb
57
86
  - lib/test_recorder.rb
87
+ - lib/test_recorder/cdp_recorder.rb
58
88
  - lib/test_recorder/rails.rb
59
89
  - lib/test_recorder/rails/setup_and_teardown.rb
60
90
  - lib/test_recorder/rspec.rb
91
+ - lib/test_recorder/rspec/example_wrapper.rb
61
92
  - lib/test_recorder/version.rb
62
93
  - test-recorder.gemspec
63
94
  homepage: http://github.com/y-yagi/test-recorder
@@ -80,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
111
  - !ruby/object:Gem::Version
81
112
  version: '0'
82
113
  requirements: []
83
- rubygems_version: 3.1.2
114
+ rubygems_version: 3.2.32
84
115
  signing_key:
85
116
  specification_version: 4
86
117
  summary: Automatically record videos when tests failed.