-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathcompiler_test.rb
68 lines (55 loc) · 1.88 KB
/
compiler_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
require "test_helper"
class CompilerTest < Minitest::Test
def remove_compilation_digest_path
Webpacker.compiler.send(:compilation_digest_path).tap do |path|
path.delete if path.exist?
end
end
def setup
remove_compilation_digest_path
end
def teardown
remove_compilation_digest_path
end
def test_custom_environment_variables
assert_nil Webpacker.compiler.send(:webpack_env)["FOO"]
Webpacker.compiler.env["FOO"] = "BAR"
assert Webpacker.compiler.send(:webpack_env)["FOO"] == "BAR"
ensure
Webpacker.compiler.env = {}
end
def test_freshness
assert Webpacker.compiler.stale?
assert !Webpacker.compiler.fresh?
end
def test_compile
assert !Webpacker.compiler.compile
end
def test_freshness_on_compile_success
status = OpenStruct.new(success?: true)
assert Webpacker.compiler.stale?
Open3.stub :capture3, [:sterr, :stdout, status] do
Webpacker.compiler.compile
assert Webpacker.compiler.fresh?
end
end
def test_freshness_on_compile_fail
status = OpenStruct.new(success?: false)
assert Webpacker.compiler.stale?
Open3.stub :capture3, [:sterr, :stdout, status] do
Webpacker.compiler.compile
assert Webpacker.compiler.fresh?
end
end
def test_compilation_digest_path
assert_equal Webpacker.compiler.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
end
def test_external_env_variables
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"]
assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"]
ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"], "foo.bar"
assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"], "/baz"
end
end