-
Notifications
You must be signed in to change notification settings - Fork 125
/
Rakefile
71 lines (59 loc) · 1.35 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require "rake/testtask"
require "bundler/gem_tasks"
require "open3"
task default: :test
task test: [ "test:helpers", "test:assets", "test:javascripts" ]
namespace :test do
Rake::TestTask.new(:helpers) do |t|
t.pattern = "test/helpers/*test.rb"
end
task assets: [ "assets:compile", "assets:verify" ]
task :javascripts do
system "yarn start"
end
end
namespace :assets do
desc "Compile assets"
task :compile do
puts "[compile] JS assets"
system "yarn build"
end
desc "Verify compiled assets"
task :verify do
verify_file "app/assets/javascripts/local-time.es2017-umd.js"
verify_file "test/javascripts/builds/index.js"
verify_requireable
end
end
def verify_file(file)
pathname = Pathname.new("#{__dir__}/#{file}")
print "[verify] #{file} exists "
if pathname.exist?
puts "[OK]"
else
puts "[FAIL]"
fail
end
print "[verify] #{file} is a UMD module "
if pathname.read =~ /module\.exports.*define\.amd/m
puts "[OK]"
else
$stderr.puts "[FAIL]"
fail
end
end
def verify_requireable
print "[verify] #{__dir__} can be required as a module "
js = <<-JS
window = {}
document = { documentElement: {} }
require("#{__dir__}")
JS
_, stderr, status = Open3.capture3("node", "--print", js)
if status.success?
puts "[OK]"
else
puts "[FAIL]\n#{stderr}"
fail
end
end