boojs 0.0.29 → 0.0.30

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
  SHA1:
3
- metadata.gz: ee076999d3654b754da3a40822627c8324a0b9ec
4
- data.tar.gz: 462e252cb637d6ad3d063b6e35faa6636d03fe6d
3
+ metadata.gz: 8afbb0e166580c67fdc4952b918827224e90a09e
4
+ data.tar.gz: 0e358c78333c5630542df9a918200f6ab188be6a
5
5
  SHA512:
6
- metadata.gz: d760e8bae7f62534eee68d823e23397c5b60043bcd35fe45c92ba85e3fd07ae6296bbfa9fe4c33c3137ddd46f327545ed516edb170fd1eed1e955d5e3570b701
7
- data.tar.gz: 7737bf0b63bd9dbcb90cbf42d67a964d73180d4dc34113fb842d711fac46f9847c3c75dd8a574f49eb669e805d49113b8c93263609546cedad72ed6d6d44f04e
6
+ metadata.gz: 5899ff5185e76d0a1130172f2b0453994faa4c2201bdaf46ed9798c60bf9c7cf713ffa0fdf668715d91d1d4262842d053f1ba1dd936a03a6202c683e39c17e20
7
+ data.tar.gz: e18edf2f45f15c15d079894c0598e290c4f376827432b855972487bc2d76300b4722cc9ceab16e2c6c273fee651300278923e4bb3caf30c6c2111fdc1d284a69
data/README.md CHANGED
@@ -64,10 +64,18 @@ Verify that a file contains no javascript runtime initialization errors
64
64
  0
65
65
  ```
66
66
 
67
+
67
68
  #### NOTES
68
69
  * Calling `booPing()` will immediately return `"pong"` to `stdout`. You may use this to know when boo has started up fully.
69
70
  * `console.error(msg)` will output to `$stderr`. `console.log(msg)` will output to `$stdout`.
70
71
 
72
+ #### Local Storage Persistance
73
+ Every restart of boojs will cause `localStorage` to be reset. There is a bug where multiple instances of `boojs` will all *share* the same
74
+ instance of `localStorage`, so if you open multiple copies of boojs, you are guaranteed to delete `localStorage` of all boojs instances.
75
+ You may restart the boojs intsance without deleting local storage via sending `$__RESTART__` directly to `stdin` of the boojs instance as
76
+ it's own line. You may then wait for the reply `$__RESTART_OK__`. At this point, boojs will have restarted with a fresh instance except
77
+ that `localStorage` will still be intact.
78
+
71
79
  ## Requirements
72
80
 
73
81
  - Ruby 2.1 or Higher
data/lib/boojs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BooJS
2
- VERSION = '0.0.29'
2
+ VERSION = '0.0.30'
3
3
  end
data/lib/boojs.rb CHANGED
@@ -33,6 +33,7 @@ module BooJS
33
33
 
34
34
  begin
35
35
  #Do we have a syntax error?
36
+ #Open a pipe and check if syntax_error
36
37
  @syntax_error = false
37
38
  Timeout.timeout(8) do
38
39
  Open3.popen3 "#{$phantomjs_path} #{path}" do |_, out, err, _|
@@ -69,10 +70,16 @@ module BooJS
69
70
  return 1
70
71
  end
71
72
 
73
+ #Restart request
74
+ class PipeRestart < Exception
75
+ end
76
+
72
77
  #Optionally, accept code to inject and a command to run
73
78
  #If the command is nil, this is not executed as a oneshot
74
79
  def self.pipe(str=nil, cmd=nil, will_timeout=false, output_phantomjs_pid=false)
75
80
  js = %{
81
+ //Clear localStorage
82
+
76
83
  var system = require('system');
77
84
  function __spec_ping(str) {
78
85
  system.stdout.writeLine("pong"+str)
@@ -121,20 +128,34 @@ module BooJS
121
128
 
122
129
  @input_sender_r, @input_sender_w = IO.pipe
123
130
 
131
+ #Set to true on restarts, for knowing whether to output $__RESTART_OK__ when the restart finishes
132
+ pipe_restart = false
124
133
  #Phantom JS Process
125
134
  begin
126
135
  p = IO.popen("#{$phantomjs_path} #{tmp.path}")
127
136
 
137
+ #If it's not a pipe restart, then clear local storage
138
+ unless pipe_restart
139
+ @input_sender_w.puts "localStorage.clear();"
140
+ end
141
+
128
142
  #We are going to do a loop back (ready to rcv) to wait for the JS to respond before outputing the spec PID
129
143
  #So that in the specs, we have a reliable way of testing the process execution as ending this process
130
144
  #before the child process ends, will termiante the spawned process (PhantomJS) by default but not if it's
131
145
  #kept alive for a while (which we handle via sending it an INT in the ensure)
132
- if output_phantomjs_pid
146
+ if output_phantomjs_pid and not pipe_restart #Dont re-emit the PID on pipe restarts
133
147
  @input_sender_w.puts "booPing();"
134
148
  res = p.readline
135
149
  puts p.pid
136
150
  end
137
151
 
152
+ #Tell stdout that we did restart
153
+ if pipe_restart
154
+ pipe_restart = false
155
+ puts "$__RESTART_OK__"
156
+ $stdout.flush
157
+ end
158
+
138
159
  loop do
139
160
  rr, _ = select([p, STDIN]); e = rr[0]
140
161
  #PhantomJS has written something
@@ -152,9 +173,18 @@ module BooJS
152
173
 
153
174
  #User has written to this program
154
175
  if e == STDIN
155
- @input_sender_w.puts e.readline
176
+ res = e.readline
177
+ if res == "$__RESTART__\n"
178
+ pipe_restart = true
179
+ raise PipeRestart
180
+ else
181
+ @input_sender_w.puts res
182
+ end
156
183
  end
157
184
  end
185
+ rescue PipeRestart
186
+ Process.kill :INT, p.pid
187
+ retry
158
188
  ensure
159
189
  Process.kill :INT, p.pid
160
190
  end
@@ -0,0 +1,74 @@
1
+ require 'open3'
2
+ Dir.chdir File.join(File.dirname(__FILE__), '../')
3
+ require './spec/helpers'
4
+
5
+ RSpec.describe "Persist" do
6
+ $stdout.sync = true
7
+ it "Does accept the restart command" do
8
+ Open3.popen3 "ruby -Ilib ./bin/boojs" do |i, o, e, t|
9
+ begin
10
+ i.puts "$__RESTART__"
11
+ res = o.readline
12
+ expect(res).to eq("$__RESTART_OK__\n")
13
+ ensure
14
+ begin
15
+ Process.kill :INT, t[:pid]
16
+ rescue Errno::ESRCH
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ it "Does NOT persist during new process" do
23
+ #Try once
24
+ Open3.popen3 "ruby -Ilib ./bin/boojs" do |i, o, e, t|
25
+ begin
26
+ i.puts "localStorage.setItem('foo', 'bar');"
27
+ i.puts "console.log(localStorage.getItem('foo'))"
28
+ res = o.readline
29
+ expect(res).to eq("bar\n")
30
+ ensure
31
+ begin
32
+ Process.kill :INT, t[:pid]
33
+ rescue Errno::ESRCH
34
+ end
35
+ end
36
+ end
37
+
38
+ #Try again
39
+ Open3.popen3 "ruby -Ilib ./bin/boojs" do |i, o, e, t|
40
+ begin
41
+ i.puts "console.log(localStorage.getItem('foo'))"
42
+ res = o.readline
43
+ expect(res).to eq("null\n")
44
+ ensure
45
+ begin
46
+ Process.kill :INT, t[:pid]
47
+ rescue Errno::ESRCH
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ it "Does persist during restarts" do
55
+ Open3.popen3 "ruby -Ilib ./bin/boojs" do |i, o, e, t|
56
+ begin
57
+ i.puts "localStorage.setItem('foo', 'bar');"
58
+ i.puts "$__RESTART__"
59
+ res = o.readline
60
+ expect(res).to eq("$__RESTART_OK__\n")
61
+
62
+ i.puts "console.log(localStorage.getItem('foo'))"
63
+ res = o.readline
64
+ expect(res).to eq("bar\n")
65
+ ensure
66
+ begin
67
+ Process.kill :INT, t[:pid]
68
+ rescue Errno::ESRCH
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ end
data/spec/sample_spec.rb CHANGED
@@ -4,64 +4,64 @@ require './spec/helpers'
4
4
 
5
5
  #Files that are reported as bugged end up here for testing.
6
6
  RSpec.describe "Live Culture" do
7
- # it "Can run jquery_ajax.js and output success" do
8
- #begin
9
- #@web = Webbing.get("/", 4545) do |info|
10
- #{"hello" => "world"}
11
- #end
7
+ it "Can run jquery_ajax.js and output success" do
8
+ begin
9
+ @web = Webbing.get("/", 4545) do |info|
10
+ {"hello" => "world"}
11
+ end
12
12
 
13
- #begin
14
- #Timeout.timeout(8) do
15
- #IO.popen "ruby -Ilib ./bin/boojs ./spec/samples/jquery_ajax.js", "r" do |p|
16
- #begin
17
- #@res = p.readline.strip
18
- #ensure
19
- #Process.kill 9, p.pid
20
- #end
21
- #end
22
- #end
23
- #rescue
24
- #end
13
+ begin
14
+ Timeout.timeout(8) do
15
+ IO.popen "ruby -Ilib ./bin/boojs ./spec/samples/jquery_ajax.js", "r" do |p|
16
+ begin
17
+ @res = p.readline.strip
18
+ ensure
19
+ Process.kill 9, p.pid
20
+ end
21
+ end
22
+ end
23
+ rescue
24
+ end
25
25
 
26
- #expect(@res).to eq("success")
27
- #ensure
28
- #Process.kill(:KILL, @web.pid)
29
- #end
30
- #end
26
+ expect(@res).to eq("success")
27
+ ensure
28
+ Process.kill(:KILL, @web.pid)
29
+ end
30
+ end
31
31
 
32
- #it "Will output to stderr on syntax error" do
33
- #begin
34
- #begin
35
- #Timeout.timeout(8) do
36
- #IO.popen "ruby -Ilib ./bin/boojs ./spec/samples/syntax_problem.js", "r" do |p|
37
- #begin
38
- #@res = p.readline.strip
39
- #ensure
40
- #Process.kill 9, p.pid
41
- #end
42
- #end
43
- #end
44
- #rescue
45
- #end
32
+ it "Will output to stderr on syntax error" do
33
+ begin
34
+ begin
35
+ Timeout.timeout(8) do
36
+ IO.popen "ruby -Ilib ./bin/boojs ./spec/samples/syntax_problem.js", "r" do |p|
37
+ begin
38
+ @res = p.readline.strip
39
+ ensure
40
+ Process.kill 9, p.pid
41
+ end
42
+ end
43
+ end
44
+ rescue
45
+ end
46
46
 
47
- #expect(@res).to eq(nil)
48
- #ensure
49
- #end
50
- #end
47
+ expect(@res).to eq(nil)
48
+ ensure
49
+ end
50
+ end
51
51
 
52
- #it "Will output '3' when running inputting set_a_stdin.js via stdin" do
53
- #stim = File.open("./spec/samples/set_a_stdin.js")
52
+ it "Will output '3' when running inputting set_a_stdin.js via stdin" do
53
+ stim = File.open("./spec/samples/set_a_stdin.js")
54
54
 
55
- #IO.popen "ruby -Ilib ./bin/boojs", "r+" do |p|
56
- #loop do
57
- #break if stim.eof
58
- #p.puts stim.gets
59
- #end
55
+ IO.popen "ruby -Ilib ./bin/boojs", "r+" do |p|
56
+ loop do
57
+ break if stim.eof
58
+ p.puts stim.gets
59
+ end
60
60
 
61
- #res = p.readline.strip
62
- #expect(res).to eq("3")
63
- #end
64
- #end
61
+ res = p.readline.strip
62
+ expect(res).to eq("3")
63
+ end
64
+ end
65
65
 
66
66
  $stdout.sync = true
67
67
  it "can run another_syntax_problem.js with the correct formatting for error" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boojs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -144,6 +144,7 @@ files:
144
144
  - spec/cli_spec.rb
145
145
  - spec/functions_spec.rb
146
146
  - spec/helpers.rb
147
+ - spec/persist_spec.rb
147
148
  - spec/ping_spec.rb
148
149
  - spec/sample_spec.rb
149
150
  - spec/samples/another_syntax_problem.js
@@ -182,6 +183,7 @@ test_files:
182
183
  - spec/cli_spec.rb
183
184
  - spec/functions_spec.rb
184
185
  - spec/helpers.rb
186
+ - spec/persist_spec.rb
185
187
  - spec/ping_spec.rb
186
188
  - spec/sample_spec.rb
187
189
  - spec/samples/another_syntax_problem.js