test-recorder 0.1.2 → 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: 77e11d42cdce42863b8b7d991d61c8b864c82ee82a17458532cd31cb7aafd9f2
4
- data.tar.gz: 5bae5ab5fc6a7ab032989af8bd6729a0e2e4f9d241b5d8f945d6f1cdf7e0315c
3
+ metadata.gz: 3b7a9be6d6179b7ea6275e1e9b9463817dd0062452ca6b45c95c85dd9a3d8840
4
+ data.tar.gz: af977f2a4990f75f107210dd50b3f4c755f5efdbc7779e9c070dc480a715e4d1
5
5
  SHA512:
6
- metadata.gz: be418cf8a5badd4f717bdc9f6c3f9928aeb756e960151508709b20a0685dcb6ffa285e5f5bc1dbf5a1e922fceabe349b40643cbe337e55e9b1cf04039dcd1932
7
- data.tar.gz: 6366982b9bf6f65011fc9a7854f32af57975ac0d7d811b20b6d7bd4a443709ce254e75dcd699a93e7005bc8020dbf60a0d4abe75327269c2153f11084adaa95f
6
+ metadata.gz: 9f0faa3366d09f18b142ed4f5c42fa9ae1a7be31c8359eccae8695004920a973188880e0599759fc8b480e4c3e080d3a6985931d5d34fea2e349d36ed4d8005e
7
+ data.tar.gz: 634c35482c87795803ed7509d5042c357c440e876f03e6969a80501ca7d6e80b8b71292f1d13e9199e1c37dcf72763026b05e4c07fd91851a50162dc6e309ed8
@@ -20,7 +20,7 @@ jobs:
20
20
  node-version: '14'
21
21
  - name: Install ffmpeg
22
22
  run: |
23
- sudo apt install ffmpeg
23
+ sudo apt update && sudo apt install ffmpeg
24
24
  - name: Install dependencies
25
25
  run: |
26
26
  gem install bundler --no-document
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- test-recorder (0.1.2)
4
+ test-recorder (0.1.3)
5
5
  activesupport
6
- activesupport-testing-metadata
7
6
  selenium-devtools
8
7
  selenium-webdriver (>= 4.0)
9
8
 
@@ -33,7 +32,7 @@ GEM
33
32
  io-console (~> 0.5)
34
33
  rexml (3.2.5)
35
34
  rubyzip (2.3.2)
36
- selenium-devtools (0.97.0)
35
+ selenium-devtools (0.100.0)
37
36
  websocket (~> 1.0)
38
37
  selenium-webdriver (4.1.0)
39
38
  childprocess (>= 0.5, < 5.0)
@@ -47,6 +46,7 @@ PLATFORMS
47
46
  ruby
48
47
 
49
48
  DEPENDENCIES
49
+ activesupport-testing-metadata
50
50
  debug
51
51
  minitest (~> 5.0)
52
52
  rake (~> 12.0)
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Record a video automatically when tests failed. The videos are generated in `tmp/videos` directory.
4
4
 
5
- ![CI](https://github.com/y-yagi/test-recorder/workflows/CI/badge.svg)
5
+ [![Build Status](https://github.com/y-yagi/test-recorder/workflows/CI/badge.svg)](https://github.com/y-yagi/test-recorder/actions)
6
6
  [![Gem Version](https://badge.fury.io/rb/test-recorder.svg)](http://badge.fury.io/rb/test-recorder)
7
7
 
8
8
 
@@ -54,6 +54,16 @@ require 'test_recorder/rspec'
54
54
 
55
55
  #### Rails
56
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
+
57
67
  ```ruby
58
68
  # test/test_helper.rb
59
69
  require 'test_recorder/rails'
@@ -70,6 +80,8 @@ end
70
80
 
71
81
  #### RSpec
72
82
 
83
+ You don't need to install other gems. Only disable `TestRecorder`, and specified tests with the tag.
84
+
73
85
  ```ruby
74
86
  # test/test_helper.rb
75
87
  require 'test_recorder/rspec'
@@ -1,10 +1,11 @@
1
+ require "open3"
1
2
  require "fileutils"
3
+ require "tempfile"
2
4
 
3
5
  module TestRecorder
4
6
  class CdpRecorder
5
7
  def initialize(enabled:)
6
8
  @enabled = enabled
7
- @tmpdir = nil
8
9
  setup
9
10
  end
10
11
 
@@ -17,19 +18,20 @@ module TestRecorder
17
18
  enabled = @enabled if enabled.nil?
18
19
  return unless enabled
19
20
 
20
- @tmpdir = Dir.mktmpdir("testrecorder")
21
- @counter = 1
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")
22
25
 
23
26
  @page = page
24
27
  @page.driver.browser.devtools.page.enable
25
28
 
26
29
  @page.driver.browser.devtools.page.on(:screencast_frame) do |event|
27
- decoded_data = Base64.decode64(event["data"])
28
- filename = "%010d.jpeg" % @counter
29
- if Dir.exist?(@tmpdir)
30
- IO.binwrite("#{File.join(@tmpdir, filename)}", decoded_data)
31
- @counter += 1
30
+ unless @stdin.closed?
31
+ decoded_data = Base64.decode64(event["data"])
32
+ @stdin.print(decoded_data)
32
33
  end
34
+
33
35
  @page.driver.browser.devtools.page.screencast_frame_ack(session_id: event["sessionId"])
34
36
  end
35
37
 
@@ -37,25 +39,19 @@ module TestRecorder
37
39
  end
38
40
 
39
41
  def stop_and_discard
40
- FileUtils.rm_rf(@tmpdir) unless @tmpdir.nil?
42
+ @stdin.close
41
43
  end
42
44
 
43
45
  def stop_and_save(filename)
44
- return if @tmpdir.nil? || @page.nil?
46
+ return if @page.nil?
45
47
 
46
- @page.driver.browser.devtools.page.stop_screencast
47
- video_path = File.join(@video_dir, filename)
48
+ @stdin.close
49
+ @wait_thrs.each(&:join)
48
50
 
49
- args = %W(-loglevel error -f image2 -avioflags direct -fpsprobesize 0
50
- -probesize 32 -analyzeduration 0 -c:v mjpeg -i #{File.join(@tmpdir, "%010d.jpeg")}
51
- -y -an -r 25 -qmin 0 -qmax 50 -crf 8 -deadline realtime -speed 8 -b:v 1M
52
- -threads 1 #{video_path})
53
- system("ffmpeg", *args, exception: true)
51
+ video_path = File.join(@video_dir, filename)
52
+ FileUtils.copy(@tmp_video.path, video_path)
53
+ @tmp_video.close(true)
54
54
  video_path
55
- rescue => e
56
- $stderr.puts("[TestRecorder] ffmpeg failed: #{e.message}")
57
- ensure
58
- FileUtils.rm_rf(@tmpdir)
59
55
  end
60
56
  end
61
57
  end
@@ -6,7 +6,8 @@ module TestRecorder
6
6
  def before_setup
7
7
 
8
8
  @cdp_recorder = TestRecorder::CdpRecorder.new(enabled: TestRecorder.enabled?)
9
- @cdp_recorder.start(page: page, enabled: metadata[:test_recorder])
9
+ enabled = respond_to?(:metadata) ? metadata[:test_recorder] : nil
10
+ @cdp_recorder.start(page: page, enabled: enabled)
10
11
 
11
12
  super
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module TestRecorder
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
  spec.add_dependency "activesupport"
23
- spec.add_dependency "activesupport-testing-metadata"
24
23
  spec.add_dependency "selenium-webdriver", ">= 4.0"
25
24
  spec.add_dependency "selenium-devtools"
25
+ spec.add_development_dependency "activesupport-testing-metadata"
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test-recorder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
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: 2022-01-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
14
  name: activesupport
@@ -25,41 +25,41 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport-testing-metadata
28
+ name: selenium-webdriver
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: selenium-webdriver
42
+ name: selenium-devtools
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.0'
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: selenium-devtools
56
+ name: activesupport-testing-metadata
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :runtime
62
+ type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements: