flok 0.0.36 → 0.0.38

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -0
  3. data/app/drivers/chrome/build_context.rb +1 -1
  4. data/app/drivers/chrome/config.yml +10 -0
  5. data/app/drivers/chrome/pipe.rb +24 -1
  6. data/app/drivers/chrome/src/persist.js +29 -0
  7. data/app/drivers/chrome/src/sockio.js +3 -1
  8. data/app/drivers/chrome/src/vendor/store2.js +3 -0
  9. data/app/kern/callout.js +55 -0
  10. data/app/kern/controller.js +3 -0
  11. data/app/kern/crc32.js +22 -0
  12. data/app/kern/dispatch.js +16 -0
  13. data/app/kern/mod/event.js +3 -0
  14. data/app/kern/mod/persist.js +1 -0
  15. data/app/kern/mod/timer.js +5 -0
  16. data/app/kern/pagers/mem_pager.js +2 -0
  17. data/app/kern/pagers/sockio_pager.js +66 -0
  18. data/app/kern/pagers/spec0.js +35 -0
  19. data/app/kern/pagers/spec1.js +24 -0
  20. data/app/kern/pagers/spec2.js +31 -0
  21. data/app/kern/services/test.rb +7 -0
  22. data/app/kern/services/vm.rb +141 -0
  23. data/app/kern/spec_helper.js +5 -0
  24. data/bin/flok +27 -5
  25. data/docs/callout.md +8 -0
  26. data/docs/client_api.md +1 -1
  27. data/docs/compilation.md +14 -8
  28. data/docs/controllers.md +2 -1
  29. data/docs/datatypes.md +3 -1
  30. data/docs/environmentals.md +6 -0
  31. data/docs/interactive.md +6 -1
  32. data/docs/kernel_api.md +3 -0
  33. data/docs/mod/event.md +5 -1
  34. data/docs/mod/persist.md +14 -31
  35. data/docs/mod/timer.md +4 -2
  36. data/docs/project.md +16 -5
  37. data/docs/scheduling.md +1 -0
  38. data/docs/services.md +141 -56
  39. data/docs/services/vm.md +128 -0
  40. data/docs/services/vm/pagers.md +46 -0
  41. data/lib/flok/build.rb +11 -16
  42. data/lib/flok/platform.rb +29 -6
  43. data/lib/flok/project_template/app/scripts/script.js +3 -0
  44. data/lib/flok/project_template/app/services/service.rb +1 -0
  45. data/lib/flok/project_template/config/config.yml +1 -0
  46. data/lib/flok/project_template/config/platforms/chrome/config.yml +1 -0
  47. data/lib/flok/project_template/config/services.rb +1 -0
  48. data/lib/flok/service_compiler_templates/services.js.erb +78 -9
  49. data/lib/flok/services_compiler.rb +117 -20
  50. data/lib/flok/user_compiler.rb +14 -6
  51. data/lib/flok/user_compiler_templates/ctable.js.erb +10 -0
  52. data/lib/flok/version.rb +1 -1
  53. data/spec/env/etc.rb +1 -1
  54. data/spec/env/global.rb +2 -0
  55. data/spec/env/iface.rb +20 -4
  56. data/spec/env/kern.rb +8 -3
  57. data/spec/etc/cli_spec.rb +319 -165
  58. data/spec/etc/lib/assets/config.yml +3 -0
  59. data/spec/etc/lib/platform_spec.rb +14 -10
  60. data/spec/etc/lib/project_spec.rb +22 -0
  61. data/spec/etc/service_compiler/config0.rb +1 -0
  62. data/spec/etc/service_compiler/config1.rb +1 -0
  63. data/spec/etc/service_compiler/config2.rb +3 -0
  64. data/spec/etc/service_compiler/service0.rb +22 -6
  65. data/spec/etc/service_compiler/service1.rb +26 -0
  66. data/spec/etc/service_compiler/service_bad_type.rb +20 -0
  67. data/spec/etc/services_compiler_spec.rb +35 -16
  68. data/spec/etc/user_compiler/data.js +2 -0
  69. data/spec/etc/user_compiler_spec.rb +7 -1
  70. data/spec/iface/driver/persist_spec.rb +106 -0
  71. data/spec/iface/driver/pipe_spec.rb +5 -0
  72. data/spec/iface/kern/ping_spec.rb +4 -3
  73. data/spec/kern/assets/blank.rb +0 -0
  74. data/spec/kern/assets/service0.rb +24 -0
  75. data/spec/kern/assets/service1.rb +22 -0
  76. data/spec/kern/assets/service2.rb +27 -0
  77. data/spec/kern/assets/service_config0.rb +2 -0
  78. data/spec/kern/assets/service_config1.rb +2 -0
  79. data/spec/kern/assets/service_controller0.rb +13 -0
  80. data/spec/kern/assets/service_controller1.rb +32 -0
  81. data/spec/kern/assets/service_controller2.rb +38 -0
  82. data/spec/kern/assets/service_controller3.rb +38 -0
  83. data/spec/kern/assets/vm/config0.rb +2 -0
  84. data/spec/kern/assets/vm/config1.rb +12 -0
  85. data/spec/kern/assets/vm/config2.rb +12 -0
  86. data/spec/kern/assets/vm/config3.rb +12 -0
  87. data/spec/kern/assets/vm/controller0.rb +8 -0
  88. data/spec/kern/assets/vm/controller1.rb +18 -0
  89. data/spec/kern/assets/vm/controller2.rb +18 -0
  90. data/spec/kern/assets/vm/controller3.rb +20 -0
  91. data/spec/kern/assets/vm/controller4.rb +22 -0
  92. data/spec/kern/assets/vm/controller5.rb +22 -0
  93. data/spec/kern/assets/vm/controller6.rb +21 -0
  94. data/spec/kern/assets/vm/service0.rb +24 -0
  95. data/spec/kern/assets/vm/service_controller0.rb +7 -0
  96. data/spec/kern/callout_spec.rb +153 -0
  97. data/spec/kern/functions_spec.rb +29 -0
  98. data/spec/kern/service_controller_spec.rb +213 -0
  99. data/spec/kern/vm_service_spec.rb +195 -0
  100. metadata +98 -12
  101. data/app/kern/services/rest.rb +0 -310
  102. data/app/kern/services/timer.rb +0 -30
  103. data/docs/services/timer.md +0 -21
  104. data/spec/kern/assets/rest_service.rb +0 -20
  105. data/spec/kern/assets/timer_service.rb +0 -19
  106. data/spec/kern/timer_service_spec.rb +0 -40
data/spec/env/etc.rb CHANGED
@@ -1,2 +1,2 @@
1
+ require './spec/env/global.rb'
1
2
  require './spec/lib/temp_dir'
2
-
@@ -0,0 +1,2 @@
1
+ bin_path = File.join(File.dirname(__FILE__), "../../bin/")
2
+ ENV['PATH'] = "#{bin_path}:#{ENV['PATH']}"
data/spec/env/iface.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require './spec/env/global.rb'
1
2
  require 'json'
2
3
  require './spec/lib/rspec_extensions'
3
4
  require 'open3'
@@ -11,7 +12,7 @@ shared_context "iface:kern" do
11
12
  before(:each) do
12
13
  @pipe = IO.popen("rake pipe:kern", "r+")
13
14
  @pid = @pipe.pid
14
- @mods = Flok::Platform.mods ENV['PLATFORM'], ENV['FLOK_ENV']
15
+ @mods = Flok::Platform.mods ENV['FLOK_ENV']
15
16
  end
16
17
 
17
18
  after(:each) do
@@ -27,7 +28,7 @@ shared_context "iface:driver" do
27
28
  before(:each) do
28
29
  @pipe = IO.popen("rake pipe:driver", "r+")
29
30
  @pid = @pipe.pid
30
- @mods = Flok::Platform.mods ENV['PLATFORM'], ENV['FLOK_ENV']
31
+ @mods = Flok::Platform.mods ENV['FLOK_ENV']
31
32
  end
32
33
 
33
34
  after(:each) do
@@ -43,11 +44,11 @@ end
43
44
 
44
45
  #Get a list of modules based on the platform and environment
45
46
  def mods
46
- Flok::Platform.mods ENV['PLATFORM'], ENV['FLOK_ENV']
47
+ Flok::Platform.mods ENV['FLOK_ENV']
47
48
  end
48
49
 
49
50
  def config_yml
50
- Flok::Platform.config_yml ENV['PLATFORM'], ENV['FLOK_ENV']
51
+ Flok::Platform.config_yml ENV['FLOK_ENV']
51
52
  end
52
53
 
53
54
  #Ensure this platform supports a module, or skip the test (used inside before(:each) describe block, or `it` block)
@@ -62,3 +63,18 @@ def settings_dep key, value
62
63
  raise "#{ENV["PLATFORM"].inspect} does not support #{key.inspect} configuration in config.yml" unless config_yml.include? key
63
64
  skip "#{ENV["PLATFORM"].inspect} #{key.inspect} is not #{value.inspect} in config.yml; it is #{config_yml[key].inspect}" unless value == config_yml[key]
64
65
  end
66
+
67
+ #Restart the driver but persist any data that was saved
68
+ def restart_driver_but_persist
69
+ #Ensure the pipe is fully drained before sending RESTART
70
+ @pipe.puts [[0, 0, "ping"]].to_json; @pipe.readline_timeout
71
+
72
+ @pipe.puts "RESTART"
73
+ begin
74
+ Timeout::timeout(10) do
75
+ expect(@pipe.readline).to eq("RESTART OK\n")
76
+ end
77
+ rescue Timeout::Error
78
+ raise "Tried to restart driver but timed out waiting for 'RESTART OK'"
79
+ end
80
+ end
data/spec/env/kern.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require './spec/env/global.rb'
1
2
  require 'therubyracer'
2
3
  require './spec/lib/temp_dir'
3
4
 
@@ -20,21 +21,25 @@ shared_context "kern" do
20
21
  bin_path = File.join(File.dirname(__FILE__), "../../bin/flok")
21
22
 
22
23
  #Now execute the command with a set of arguments
23
- system("#{bin_path} #{args}")
24
+ return system("#{bin_path} #{args}")
24
25
  end
25
26
 
26
27
  #Create a new flok project, add the given user_file (an .rb file containing controllers, etc.)
27
28
  #and then retrieve a V8 instance from this project's application_user.js
28
- def flok_new_user user_controllers_src
29
+ def flok_new_user user_controllers_src, service_config=nil, service_src=nil
29
30
  temp_dir = new_temp_dir
30
31
  Dir.chdir temp_dir do
31
32
  flok "new test"
32
33
  Dir.chdir "test" do
33
34
  #Put controllers in
34
35
  File.write './app/controllers/user_controller.rb', user_controllers_src
36
+ File.write './config/services.rb', service_config if service_config
37
+ File.write './app/services/service0.rb', service_src if service_src
35
38
 
36
39
  #Build
37
- flok "build" #Will generate drivers/ but we will ignore that
40
+ unless flok "build" #Will generate drivers/ but we will ignore that
41
+ raise "Build failed"
42
+ end
38
43
 
39
44
  #Execute
40
45
  @driver = FakeDriverContext.new
data/spec/etc/cli_spec.rb CHANGED
@@ -35,69 +35,124 @@ def flok_new
35
35
  end
36
36
 
37
37
  RSpec.describe "CLI" do
38
- before(:all) do
38
+ before(:all) do
39
39
  #Uninstall old gems and install the current development gem
40
40
  system("rake gem:install")
41
41
  end
42
42
 
43
- it "Can be executed via bundle exec" do
44
- flok_new do
45
- flok "build"
46
- end
47
- end
48
-
49
- it "Can create a new project with correct directories" do
50
- flok_new do
51
- #Should include all entities in the project template with the exception
52
- #of erb extenseded entities (which will still be included, but they each
53
- #will not have the erb ending
54
- template_nodes = nil
55
- Dir.chdir File.join(File.dirname(__FILE__), "../../lib/flok/project_template") do
56
- template_nodes = Dir["**/*"].map{|e| e.gsub(/\.erb$/i, "")}
57
- end
58
- new_proj_nodes = Dir["**/*"]
59
- expect(new_proj_nodes.sort).to eq(template_nodes.sort)
60
-
61
- expect(files).to include("Gemfile")
62
- end
63
- end
64
-
65
- it "Can build a project with every type of platform" do
66
- platform = ENV['PLATFORM']
67
- flok_new do
68
- #Build a new project
69
- flok "build"
70
-
71
- #Check it's products directory
72
- expect(dirs).to include "products"
73
- Dir.chdir "products" do
74
- #Has a platform folder
75
- expect(dirs).to include platform
76
- Dir.chdir platform do
77
- #Has an application_user.js file
78
- expect(files).to include "application_user.js"
79
-
80
- #The application_user.js contains both the glob/application.js and the glob/user_compiler.js
81
- glob_application_js = File.read('glob/application.js')
82
- glob_user_compiler_js = File.read('glob/user_compiler.js')
83
- application_user_js = File.read('application_user.js')
84
- expect(application_user_js).to include(glob_application_js)
85
- expect(application_user_js).to include(glob_user_compiler_js)
86
-
87
- #Contains the same files as the kernel in the drivers directory
88
- expect(dirs).to include "drivers"
89
- end
90
- end
91
- end
92
- end
93
-
94
- it "Can build a project with a controller file for each platform" do
43
+ #it "Can be executed via bundle exec" do flok_new do
44
+ #flok "build"
45
+ #end
46
+ #end
47
+
48
+ ##When this sets FLOK_CONFIG, the defines is added to the project config.yml
49
+ ##to show spec_helper_defines_spec_test. This text should show up in the final
50
+ ##source code
51
+ #it "Does set the FLOK_CONFIG to the correct file based on PLATFORM" do
52
+ #flok_new do
53
+ ##Set spec_test in project configuration
54
+ #config_yml = YAML.load_file("./config/platforms/#{ENV['PLATFORM']}/config.yml")
55
+ #config_yml["DEBUG"]["defines"] = ["spec_test"]
56
+ #File.write("./config/platforms/#{ENV['PLATFORM']}/config.yml", config_yml.to_yaml)
57
+
58
+ ##Now commit a build
59
+ #flok "build"
60
+
61
+ ##Now read the application_user file, it should contain the string located in `./app/kern/spec_helper.js`
62
+ ##that will only show if the correct defines is set
63
+ #application_user = File.read("./products/#{ENV['PLATFORM']}/application_user.js")
64
+ #expect(application_user).to include("spec_helper_defines_spec_test")
65
+ #end
66
+ #end
67
+
68
+ #it "Can create a new project with correct directories" do
69
+ #flok_new do
70
+ ##Should include all entities in the project template with the exception
71
+ ##of erb extenseded entities (which will still be included, but they each
72
+ ##will not have the erb ending
73
+ #template_nodes = nil
74
+ #Dir.chdir File.join(File.dirname(__FILE__), "../../lib/flok/project_template") do
75
+ #template_nodes = Dir["**/*"].map{|e| e.gsub(/\.erb$/i, "")}
76
+ #end
77
+ #new_proj_nodes = Dir["**/*"]
78
+ #expect(new_proj_nodes.sort).to eq(template_nodes.sort)
79
+
80
+ #expect(files).to include("Gemfile")
81
+ #end
82
+ #end
83
+
84
+ #it "Can build a project with every type of platform" do
85
+ #platform = ENV['PLATFORM']
86
+ #flok_new do
87
+ ##Build a new project
88
+ #flok "build"
89
+
90
+ ##Check it's products directory
91
+ #expect(dirs).to include "products"
92
+ #Dir.chdir "products" do
93
+ ##Has a platform folder
94
+ #expect(dirs).to include platform
95
+ #Dir.chdir platform do
96
+ ##Has an application_user.js file
97
+ #expect(files).to include "application_user.js"
98
+
99
+ ##The application_user.js contains both the glob/application.js and the glob/user_compiler.js
100
+ #glob_application_js = File.read('glob/application.js')
101
+ #glob_user_compiler_js = File.read('glob/user_compiler.js')
102
+ #application_user_js = File.read('application_user.js')
103
+ #expect(application_user_js).to include(glob_application_js)
104
+ #expect(application_user_js).to include(glob_user_compiler_js)
105
+
106
+ ##Contains the same files as the kernel in the drivers directory
107
+ #expect(dirs).to include "drivers"
108
+ #end
109
+ #end
110
+ #end
111
+ #end
112
+
113
+ #it "Can build a project with a controller file for each platform" do
114
+ ##Compile and then return the length of the application_user.js file
115
+ #def compile_with_file path=nil
116
+ ##Custom controller to test source with
117
+ #controller_src = File.read(path) if path
118
+ #flok_new do
119
+ #File.write "./app/controllers/controller0.rb", controller_src if path
120
+
121
+ ##Build a new project
122
+ #flok "build"
123
+
124
+ ##Check it's products directory
125
+ #Dir.chdir "products" do
126
+ ##Has a platform folder
127
+ #Dir.chdir @platform do
128
+ #glob_application_js = File.read('glob/application.js')
129
+ #glob_user_compiler_js = File.read('glob/user_compiler.js')
130
+ #application_user_js = File.read('application_user.js')
131
+
132
+ #return application_user_js.split("\n").count
133
+ #end
134
+ #end
135
+ #end
136
+ #end
137
+
138
+ #platform = ENV['PLATFORM']
139
+ #@platform = platform
140
+ #controller_rb = File.read('./spec/etc/user_compiler/controller0.rb')
141
+
142
+ ##The file with content should be longer when compiled into the flat application_user.js
143
+ #len_with_content = compile_with_file "./spec/etc/user_compiler/controller0.rb"
144
+ #len_no_content = compile_with_file
145
+
146
+ #expect(len_no_content).to be < len_with_content
147
+ #end
148
+
149
+ it "Can build a project with a javascript file for each platform" do
95
150
  #Compile and then return the length of the application_user.js file
96
151
  def compile_with_file path=nil
97
152
  #Custom controller to test source with
98
153
  controller_src = File.read(path) if path
99
154
  flok_new do
100
- File.write "./app/controllers/controller0.rb", controller_src if path
155
+ File.write "./app/scripts/data.js", controller_src if path
101
156
 
102
157
  #Build a new project
103
158
  flok "build"
@@ -106,8 +161,6 @@ it "Can create a new project with correct directories" do
106
161
  Dir.chdir "products" do
107
162
  #Has a platform folder
108
163
  Dir.chdir @platform do
109
- glob_application_js = File.read('glob/application.js')
110
- glob_user_compiler_js = File.read('glob/user_compiler.js')
111
164
  application_user_js = File.read('application_user.js')
112
165
 
113
166
  return application_user_js.split("\n").count
@@ -118,119 +171,220 @@ it "Can create a new project with correct directories" do
118
171
 
119
172
  platform = ENV['PLATFORM']
120
173
  @platform = platform
121
- controller_rb = File.read('./spec/etc/user_compiler/controller0.rb')
122
-
123
174
  #The file with content should be longer when compiled into the flat application_user.js
124
- len_with_content = compile_with_file "./spec/etc/user_compiler/controller0.rb"
175
+ len_with_content = compile_with_file "./spec/etc/user_compiler/data.js"
125
176
  len_no_content = compile_with_file
126
177
 
127
178
  expect(len_no_content).to be < len_with_content
128
179
  end
129
180
 
130
- include SpecHelpers
131
- it "server does build project when first run" do
132
- platform = ENV['PLATFORM']
133
- flok_new do
134
- #Now execute the command with a set of arguments
135
- sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
136
- #The server should always trigger a build on it's first run
137
- expect(dirs).to include "products"
138
- Dir.chdir "products" do
139
- #Has a platform folder
140
- expect(dirs).to include platform
141
- Dir.chdir platform do
142
- #Has an application_user.js file
143
- expect(files).to include "application_user.js"
144
-
145
- #The application_user.js contains both the glob/application.js and the glob/user_compiler.js
146
- glob_application_js = File.read('glob/application.js')
147
- glob_user_compiler_js = File.read('glob/user_compiler.js')
148
- application_user_js = File.read('application_user.js')
149
- expect(application_user_js).to include(glob_application_js)
150
- expect(application_user_js).to include(glob_user_compiler_js)
151
-
152
- #Contains the same files as the kernel in the drivers directory
153
- expect(dirs).to include "drivers"
154
- end
155
- end
156
- end
157
- end
158
- end
159
-
160
- it "server does rebuild project when a file is added" do
161
- platform = ENV['PLATFORM']
162
- flok_new do
163
- #Now execute the command with a set of arguments
164
- sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
165
- #Get the original build
166
- application_user_js = File.read("products/#{platform}/application_user.js")
167
-
168
- #Now add a file
169
- File.write "./app/controllers/test2.rb", %{
170
- controller "my_controller" do
171
- action "my_action" do
172
- on_entry %{
173
- }
174
- end
175
- end
176
- }
177
-
178
- #Wait for a rebuild
179
- expect(out).to readline_and_equal_x_within_y_seconds("BUILD RAN", 5.seconds)
180
-
181
- #Get updated version
182
- application_user_js2 = File.read("products/#{platform}/application_user.js")
183
-
184
- #Make sure the compiled file is different and it's somewhat valid (length > 30)
185
- expect(application_user_js2).not_to eq(application_user_js)
186
- expect(application_user_js2.length).to be > 30 #Magic 30 to avoid any problems
187
- end
188
- end
189
- end
190
-
191
- it "server does host products on localhost:9992" do
192
- platform = ENV['PLATFORM']
193
- flok_new do
194
- #Now execute the command with a set of arguments
195
- sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
196
- real_application_user_js = File.read("products/#{platform}/application_user.js")
197
-
198
- #Grab the application_user.js file
199
- res = wget "http://localhost:9992/application_user.js"
200
- expect(res).not_to eq(nil)
201
- expect(res.length).not_to eq(0)
202
- expect(res).to eq(real_application_user_js)
203
- end
204
- end
205
- end
206
-
207
- it "server does host products on localhost:9992 and changes the products when the files change" do
208
- platform = ENV['PLATFORM']
209
- flok_new do
210
- #Now execute the command with a set of arguments
211
- sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
212
- #Get the original
213
- application_user_js = wget "http://localhost:9992/application_user.js"
214
-
215
- #Now add a file
216
- File.write "./app/controllers/test2.rb", %{
217
- controller "my_controller" do
218
- action "my_action" do
219
- on_entry %{
220
- }
221
- end
222
- end
223
- }
224
- #Wait for a rebuild
225
- expect(out).to readline_and_equal_x_within_y_seconds("BUILD RAN", 5.seconds)
226
-
227
- #Grab new version
228
- application_user_js2 = wget "http://localhost:9992/application_user.js"
229
-
230
- #Make sure the compiled file is different and it's longer
231
- expect(application_user_js2.length).to be > application_user_js.length
232
- expect(application_user_js2.length).to be > 30 #Make sure it's at least something
233
- end
234
- end
235
- end
181
+ #it "Can build a project with an instantized service from the kernel ./app/kern/services folder" do
182
+ ##Compiled to config/services.rb
183
+ #def compile_with_file path=nil
184
+ #config_src = File.read(path) if path
185
+ #flok_new do
186
+ #File.write "./config/services.rb", config_src if path
187
+
188
+ ##Build a new project
189
+ #flok "build"
190
+
191
+ ##Check it's products directory
192
+ #Dir.chdir "products" do
193
+ ##Has a platform folder
194
+ #Dir.chdir @platform do
195
+ #application_user_js = File.read('application_user.js')
196
+
197
+ #return application_user_js.split("\n").count
198
+ #end
199
+ #end
200
+ #end
201
+ #end
202
+
203
+ #platform = ENV['PLATFORM']
204
+ #@platform = platform
205
+ #config_rb = File.read('./spec/etc/service_compiler/config0.rb')
206
+
207
+ ##The file with content should be longer when compiled into the flat application_user.js
208
+ #len_with_content = compile_with_file "./spec/etc/service_compiler/config0.rb"
209
+ #len_no_content = compile_with_file
210
+
211
+ #expect(len_no_content).to be < len_with_content
212
+ #end
213
+
214
+ #it "Can build a project with an instantized service from the user ./app/services folder" do
215
+ ##Compiled to config/services.rb
216
+ #def compile_with_file config_path=nil, src_path=nil
217
+ #config_src = File.read(config_path) if config_path
218
+ #src = File.read(src_path) if src_path
219
+ #flok_new do
220
+ #File.write "./config/services.rb", config_src if config_path
221
+ #File.write "./app/services/service0.rb", src if src_path
222
+
223
+ ##Build a new project
224
+ #flok "build"
225
+
226
+ ##Check it's products directory
227
+ #Dir.chdir "products" do
228
+ ##Has a platform folder
229
+ #Dir.chdir @platform do
230
+ #application_user_js = File.read('application_user.js')
231
+
232
+ #return application_user_js.split("\n").count
233
+ #end
234
+ #end
235
+ #end
236
+ #end
237
+
238
+ #platform = ENV['PLATFORM']
239
+ #@platform = platform
240
+ #config_rb = File.read('./spec/etc/service_compiler/config1.rb')
241
+ #service_rb = File.read('./spec/etc/service_compiler/service0.rb')
242
+
243
+ ##The file with content should be longer when compiled into the flat application_user.js
244
+ #len_with_content = compile_with_file "./spec/etc/service_compiler/config1.rb", "./spec/etc/service_compiler/service0.rb"
245
+ #len_no_content = compile_with_file
246
+
247
+ #expect(len_no_content).to be < len_with_content
248
+ #end
249
+
250
+ #it "Can build a project with an instantized service from the user ./app/services folder and this has a function of the service" do
251
+ ##Compiled to config/services.rb
252
+ #def compile_with_file config_path=nil, src_path=nil
253
+ #config_src = File.read(config_path) if config_path
254
+ #src = File.read(src_path) if src_path
255
+ #flok_new do
256
+ #File.write "./config/services.rb", config_src if config_path
257
+ #File.write "./app/services/service0.rb", src if src_path
258
+
259
+ ##Build a new project
260
+ #flok "build"
261
+
262
+ ##Check it's products directory
263
+ #Dir.chdir "products" do
264
+ ##Has a platform folder
265
+ #Dir.chdir @platform do
266
+ #application_user_js = File.read('application_user.js')
267
+
268
+ #return application_user_js
269
+ #end
270
+ #end
271
+ #end
272
+ #end
273
+
274
+ #platform = ENV['PLATFORM']
275
+ #@platform = platform
276
+ #config_rb = File.read('./spec/etc/service_compiler/config1.rb')
277
+ #service_rb = File.read('./spec/etc/service_compiler/service0.rb')
278
+
279
+ ##The file with content should be longer when compiled into the flat application_user.js
280
+ #res = compile_with_file "./spec/etc/service_compiler/config1.rb", "./spec/etc/service_compiler/service0.rb"
281
+ #expect(res).to include("function blah_on_wakeup()")
282
+ #end
283
+
284
+ #include SpecHelpers
285
+ #it "server does build project when first run" do
286
+ #platform = ENV['PLATFORM']
287
+ #flok_new do
288
+ ##Now execute the command with a set of arguments
289
+ #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
290
+ ##The server should always trigger a build on it's first run
291
+ #expect(dirs).to include "products"
292
+ #Dir.chdir "products" do
293
+ ##Has a platform folder
294
+ #expect(dirs).to include platform
295
+ #Dir.chdir platform do
296
+ ##Has an application_user.js file
297
+ #expect(files).to include "application_user.js"
298
+
299
+ ##The application_user.js contains both the glob/application.js and the glob/user_compiler.js
300
+ #glob_application_js = File.read('glob/application.js')
301
+ #glob_user_compiler_js = File.read('glob/user_compiler.js')
302
+ #application_user_js = File.read('application_user.js')
303
+ #expect(application_user_js).to include(glob_application_js)
304
+ #expect(application_user_js).to include(glob_user_compiler_js)
305
+
306
+ ##Contains the same files as the kernel in the drivers directory
307
+ #expect(dirs).to include "drivers"
308
+ #end
309
+ #end
310
+ #end
311
+ #end
312
+ #end
313
+
314
+ #it "server does rebuild project when a file is added" do
315
+ #platform = ENV['PLATFORM']
316
+ #flok_new do
317
+ ##Now execute the command with a set of arguments
318
+ #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
319
+ ##Get the original build
320
+ #application_user_js = File.read("products/#{platform}/application_user.js")
321
+
322
+ ##Now add a file
323
+ #File.write "./app/controllers/test2.rb", %{
324
+ #controller "my_controller" do
325
+ #action "my_action" do
326
+ #on_entry %{
327
+ #}
328
+ #end
329
+ #end
330
+ #}
331
+
332
+ ##Wait for a rebuild
333
+ #expect(out).to readline_and_equal_x_within_y_seconds("BUILD RAN", 5.seconds)
334
+
335
+ ##Get updated version
336
+ #application_user_js2 = File.read("products/#{platform}/application_user.js")
337
+
338
+ ##Make sure the compiled file is different and it's somewhat valid (length > 30)
339
+ #expect(application_user_js2).not_to eq(application_user_js)
340
+ #expect(application_user_js2.length).to be > 30 #Magic 30 to avoid any problems
341
+ #end
342
+ #end
343
+ #end
344
+
345
+ #it "server does host products on localhost:9992" do
346
+ #platform = ENV['PLATFORM']
347
+ #flok_new do
348
+ ##Now execute the command with a set of arguments
349
+ #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
350
+ #real_application_user_js = File.read("products/#{platform}/application_user.js")
351
+
352
+ ##Grab the application_user.js file
353
+ #res = wget "http://localhost:9992/application_user.js"
354
+ #expect(res).not_to eq(nil)
355
+ #expect(res.length).not_to eq(0)
356
+ #expect(res).to eq(real_application_user_js)
357
+ #end
358
+ #end
359
+ #end
360
+
361
+ #it "server does host products on localhost:9992 and changes the products when the files change" do
362
+ #platform = ENV['PLATFORM']
363
+ #flok_new do
364
+ ##Now execute the command with a set of arguments
365
+ #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
366
+ ##Get the original
367
+ #application_user_js = wget "http://localhost:9992/application_user.js"
368
+
369
+ ##Now add a file
370
+ #File.write "./app/controllers/test2.rb", %{
371
+ #controller "my_controller" do
372
+ #action "my_action" do
373
+ #on_entry %{
374
+ #}
375
+ #end
376
+ #end
377
+ #}
378
+ ##Wait for a rebuild
379
+ #expect(out).to readline_and_equal_x_within_y_seconds("BUILD RAN", 5.seconds)
380
+
381
+ ##Grab new version
382
+ #application_user_js2 = wget "http://localhost:9992/application_user.js"
383
+
384
+ ##Make sure the compiled file is different and it's longer
385
+ #expect(application_user_js2.length).to be > application_user_js.length
386
+ #expect(application_user_js2.length).to be > 30 #Make sure it's at least something
387
+ #end
388
+ #end
389
+ #end
236
390
  end