-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.rb
222 lines (172 loc) · 5.93 KB
/
test.rb
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
require 'minitest/autorun'
require 'minitest/spec'
require 'minitest/pride'
describe "Elm.mk test" do
describe "help" do
it "has all commands" do
out, _err = capture_subprocess_io do
system("make -f dummy/elm.mk help")
end
assert_match %r%all%, out
assert_match %r%repl%, out
assert_match %r%serve%, out
assert_match %r%watch%, out
assert_match %r%help%, out
end
end
describe "config" do
it "shows relevant paths" do
out, _err = capture_subprocess_io do
system("make -f dummy/elm.mk config")
end
assert_match %r%src%, out
assert_match %r%styles%, out
assert_match %r%build%, out
assert_match %r%dist%, out
end
end
describe "tool targets" do
it "executables" do
["bin/devd", "bin/elm", "bin/elm-format", "bin/mo", "bin/modd", "bin/wt"].each do |bin|
File.exist?("dummy/#{bin}").must_equal true
File.executable?("dummy/#{bin}").must_equal true
end
end
end
describe "support targets" do
it ".gitignore" do
contents = File.readlines_stripped("dummy/.gitignore")
contents.wont_be_empty
contents.must_include "elm-stuff"
contents.must_include "node_modules"
contents.must_include "elm.js"
contents.must_include "build"
contents.must_include "dist"
contents.must_include "bin"
end
it "Makefile" do
contents = File.readlines_stripped("dummy/Makefile")
contents.wont_be_empty
contents.must_include "include elm.mk"
end
it "elm.json" do
contents = File.readlines_stripped("dummy/elm.json")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/elm\/html/)
end
it "modd.conf" do
contents = File.readlines_stripped("dummy/modd.conf")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/build\/main\.js/)
contents.must_have_at_least_one_matching(/build\/boot\.js/)
contents.must_have_at_least_one_matching(/build\/main\.css/)
contents.must_have_at_least_one_matching(/build\/index\.html/)
contents.must_have_at_least_one_matching(/devd/)
end
end
describe "application targets" do
it "index.html" do
contents = File.readlines_stripped("dummy/index.html")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/Loading.../)
end
it "elm source files" do
contents = File.readlines_stripped("dummy/src/Main.elm")
contents.wont_be_empty
contents.first.must_include("module Main exposing (main)")
end
end
describe "build targets" do
it "build/index.html" do
contents = File.readlines_stripped("dummy/build/index.html")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/\/main\.js/)
contents.must_have_at_least_one_matching(/\/boot\.js/)
contents.must_have_at_least_one_matching(/\/service-worker\.js/)
contents.must_have_at_least_one_matching(/\/main\.css/)
end
it "build/main.js" do
contents = File.readlines_stripped("dummy/build/main.js")
contents.wont_be_empty
end
it "build/boot.js" do
contents = File.readlines_stripped("dummy/build/boot.js")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/Elm\.Main\.init/)
end
it "build/service-worker.js" do
contents = File.readlines_stripped("dummy/build/service-worker.js")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/v1\.files/)
end
it "build/main.css" do
contents = File.readlines_stripped("dummy/build/main.css")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/body/)
end
end
end
describe "test support" do
it "elm-test" do
File.exist?("dummy/node_modules/.bin/elm-test").must_equal true
File.executable?("dummy/node_modules/.bin/elm-test").must_equal true
end
it "tests/Example.elm" do
contents = File.readlines_stripped("dummy/tests/Example.elm")
contents.wont_be_empty
end
it "elm.json" do
contents = File.readlines_stripped("dummy/elm.json")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/test-dependencies/)
end
end
describe "dist targets" do
it "uglifyjs" do
File.exist?("dummy/node_modules/.bin/uglifyjs").must_equal true
File.executable?("dummy/node_modules/.bin/uglifyjs").must_equal true
end
it "dist/index.html" do
contents = File.readlines_stripped("dummy/dist/index.html")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/\/main\.min\.js/)
contents.must_have_at_least_one_matching(/\/boot\.js/)
contents.must_have_at_least_one_matching(/\/service-worker\.js/)
contents.must_have_at_least_one_matching(/\/main\.css/)
end
it "dist/main.js" do
contents = File.readlines_stripped("dummy/dist/main.js")
contents.wont_be_empty
end
it "dist/main.min.js" do
contents = File.readlines_stripped("dummy/dist/main.min.js")
contents.wont_be_empty
end
it "dist/boot.js" do
contents = File.readlines_stripped("dummy/dist/boot.js")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/Elm\.Main\.init/)
end
it "dist/service-worker.js" do
contents = File.readlines_stripped("dummy/dist/service-worker.js")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/v1\.files/)
end
it "dist/main.css" do
contents = File.readlines_stripped("dummy/dist/main.css")
contents.wont_be_empty
contents.must_have_at_least_one_matching(/body/)
end
end
# Extensions and helpers
class File
def self.readlines_stripped(filename)
readlines(filename).map(&:strip)
end
end
module MiniTest::Assertions
def assert_at_least_one_match(strings, matcher)
refute strings.grep(matcher).empty?, "Expected #{strings} to have at least one element matching #{matcher.inspect}"
end
end
Array.infect_an_assertion :assert_at_least_one_match, :must_have_at_least_one_matching, :do_not_flip