capybara-lockstep 0.5.0 → 0.6.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: 29e90825f3d0526be3d7780f7a291eddb9094b271f53ea5dcd4331a4123cda01
4
- data.tar.gz: 1985baa9704e28b4a0b8a38c53af53b133adc68db14b5ec1fc613cd2adc0f21c
3
+ metadata.gz: ef423eecbf9d793e932d66b056feee733835efa0387ec6740fecb2975585f95e
4
+ data.tar.gz: 55e8872d7b892567797ded6fb67ed17500bc3daf29e11fbf4fee45588cdab9f2
5
5
  SHA512:
6
- metadata.gz: 761be246131d0fce67dd2fb4d3ac8c7bddb0775e477ebe02b7c36139dc7e6152c0dea579cd02343b2e7f5ba3dd85ce2127fc21b323e1216584e3ebd16867a145
7
- data.tar.gz: c0c4ad6b8bb83bf6493276bc2388446a3f6ff07b6ae8c924189851e77e9f767a551ce85ba9f04c6ebe285c0904fe3eb44ed1761f704e0ebaee1a7a638c49e26e
6
+ metadata.gz: cd14f06c4b820e5e0dda482438d282e7a856c790ef0952f44c28a6f18dd9fb863323f782b8e21d9846ec9660fcf804ea257e5c05640482e777408e71ab820ccd
7
+ data.tar.gz: dc64900722119cc945b6b22113b63d13706d0cfb2ae39e0b8411c62aad0cbfc716ff84433189521f685219ee85f48554852df1204ce0fad1fed4e7f19b1d3cf0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capybara-lockstep (0.5.0)
4
+ capybara-lockstep (0.6.0)
5
5
  activesupport (>= 3.2)
6
6
  capybara (>= 2.0)
7
7
  selenium-webdriver (>= 3)
@@ -32,8 +32,10 @@ GEM
32
32
  i18n (1.8.9)
33
33
  concurrent-ruby (~> 1.0)
34
34
  mini_mime (1.0.2)
35
+ mini_portile2 (2.5.0)
35
36
  minitest (5.14.4)
36
- nokogiri (1.11.1-x86_64-linux)
37
+ nokogiri (1.11.1)
38
+ mini_portile2 (~> 2.5.0)
37
39
  racc (~> 1.4)
38
40
  public_suffix (4.0.6)
39
41
  racc (1.5.2)
@@ -12,13 +12,18 @@ module Capybara
12
12
 
13
13
  if visiting_remote_url
14
14
  # We're about to leave this screen, killing all in-flight requests.
15
- Capybara::Lockstep.synchronize
15
+ # Give pending form submissions etc. a chance to finish before we tear down
16
+ # the browser environment.
17
+ #
18
+ # We force a non-lazy synchronization so we pick up all client-side changes
19
+ # that have not been caused by Capybara commands.
20
+ Lockstep.synchronize(lazy: false)
16
21
  end
17
22
 
18
23
  super(*args, &block).tap do
19
24
  if visiting_remote_url
20
- # puts "After visit: unsynchronizing"
21
- Capybara::Lockstep.synchronized = false
25
+ # We haven't yet synchronized the new screen.
26
+ Lockstep.synchronized = false
22
27
  end
23
28
  end
24
29
  end
@@ -26,11 +31,57 @@ module Capybara
26
31
  end
27
32
  end
28
33
 
29
-
30
34
  Capybara::Session.class_eval do
31
35
  prepend Capybara::Lockstep::VisitWithWaiting
32
36
  end
33
37
 
38
+ module Capybara
39
+ module Lockstep
40
+ module SynchronizeAroundScriptMethod
41
+
42
+ def synchronize_around_script_method(meth)
43
+ mod = Module.new do
44
+ define_method meth do |script, *args, &block|
45
+ # Synchronization uses execute_script itself, so don't synchronize when
46
+ # we're already synchronizing.
47
+ if !Lockstep.synchronizing?
48
+ # It's generally a good idea to synchronize before a JavaScript wants
49
+ # to access or observe an earlier state change.
50
+ #
51
+ # In case the given script navigates away (with `location.href = url`,
52
+ # `history.back()`, etc.) we would kill all in-flight requests. For this case
53
+ # we force a non-lazy synchronization so we pick up all client-side changes
54
+ # that have not been caused by Capybara commands.
55
+ script_may_navigate_away = script =~ /\b(location|history)\b/
56
+ Lockstep.log "Synchronizing before script: #{script}"
57
+ Lockstep.synchronize(lazy: !script_may_navigate_away)
58
+ end
59
+
60
+ super(script, *args, &block).tap do
61
+ if !Lockstep.synchronizing?
62
+ # We haven't yet synchronized with whatever changes the JavaScript
63
+ # did on the frontend.
64
+ Lockstep.synchronized = false
65
+ end
66
+ end
67
+ end
68
+ end
69
+ prepend(mod)
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+
76
+ Capybara::Session.class_eval do
77
+ extend Capybara::Lockstep::SynchronizeAroundScriptMethod
78
+
79
+ synchronize_around_script_method :execute_script
80
+ synchronize_around_script_method :evaluate_async_script
81
+ # Don't synchronize around evaluate_script. It calls execute_script
82
+ # internally and we don't want to synchronize multiple times.
83
+ end
84
+
34
85
  module Capybara
35
86
  module Lockstep
36
87
  module UnsychronizeAfter
@@ -38,7 +89,7 @@ module Capybara
38
89
  mod = Module.new do
39
90
  define_method meth do |*args, &block|
40
91
  super(*args, &block).tap do
41
- Capybara::Lockstep.synchronized = false
92
+ Lockstep.synchronized = false
42
93
  end
43
94
  end
44
95
  end
@@ -69,7 +69,7 @@ window.CapybaraLockstep = (function() {
69
69
 
70
70
  let idleCallback
71
71
  while (isIdle() && (idleCallback = idleCallbacks.shift())) {
72
- idleCallback('Finished waiting for JavaScript')
72
+ idleCallback('Finished waiting for browser')
73
73
  }
74
74
  }
75
75
 
@@ -39,6 +39,8 @@ module Capybara
39
39
 
40
40
  log 'Synchronizing'
41
41
 
42
+ start_time = current_seconds
43
+
42
44
  begin
43
45
  with_max_wait_time(timeout) do
44
46
  message_from_js = evaluate_async_script(<<~JS)
@@ -67,7 +69,9 @@ module Capybara
67
69
  log(message_from_js)
68
70
  else
69
71
  log message_from_js
70
- log "Synchronized successfully"
72
+ end_time = current_seconds
73
+ ms_elapsed = ((end_time.to_f - start_time) * 1000).round
74
+ log "Synchronized successfully [#{ms_elapsed} ms]"
71
75
  self.synchronized = true
72
76
  end
73
77
  end
@@ -124,6 +128,10 @@ module Capybara
124
128
  # no-op
125
129
  end
126
130
 
131
+ def current_seconds
132
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
133
+ end
134
+
127
135
  end
128
136
 
129
137
  end
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Lockstep
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-lockstep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara