-
Notifications
You must be signed in to change notification settings - Fork 796
/
Copy pathtest_sprocketize.rb
90 lines (74 loc) · 2.86 KB
/
test_sprocketize.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
# frozen_string_literal: true
require 'sprockets_test'
require 'shellwords'
require 'tmpdir'
class TestSprockets < Sprockets::TestCase
parallelize_me!
def setup
super
@env = Sprockets::Environment.new(".") do |env|
env.append_path(fixture_path('default'))
end
@dir = Dir.mktmpdir("sprockets")
end
def teardown
FileUtils.rm_rf @dir
super
end
test "show version for -v flag" do
output = sprockets "-v"
assert_equal "#{Sprockets::VERSION}\n", output
end
test "show help for -h flag" do
output = sprockets "-h"
assert_match "Usage: sprockets", output
end
test "show help for no flags or inputs" do
output = sprockets
assert_match "Usage: sprockets", output
end
test "error if load path is missing" do
sprockets fixture_path("default/gallery.js")
assert_equal 1, $?.exitstatus
end
test "compile simple file" do
output = sprockets "-I", fixture_path("default"), fixture_path("default/gallery.js")
assert_equal "var Gallery = {};\n", output
end
test "show error if multiple files are given" do
sprockets fixture_path("default/gallery.js"), fixture_path("default/application.js")
assert_equal 1, $?.exitstatus
end
test "compile file with dependencies" do
output = sprockets "-I", fixture_path("asset"), fixture_path("asset/application.js")
assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\n\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n", output
end
test "compile asset to output directory" do
digest_path = @env['gallery.js'].digest_path
output = sprockets "-I", fixture_path("default"), "-o", @dir, fixture_path("default/gallery.js")
assert_equal "", output
assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
test "compile multiple assets to output directory" do
digest_path1, digest_path2 = @env['gallery.js'].digest_path, @env['gallery.css'].digest_path
output = sprockets "-I", fixture_path("default"), "-o", @dir, "gallery.js", "gallery.css"
assert_equal "", output
assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path1}")
assert File.exist?("#{@dir}/#{digest_path2}")
end
test "minify js with uglify" do
output = sprockets "-I", fixture_path("default"), "--js-compressor", "uglify", "gallery.js"
assert_equal "var Gallery={};\n", output
end
test "compress css with sass" do
output = sprockets "-I", fixture_path("default"), "--css-compressor", "sass", "gallery.css"
assert_equal ".gallery{color:red}\n", output
end
def sprockets(*args)
script = File.expand_path("../../bin/sprockets", __FILE__)
lib = File.expand_path("../../lib", __FILE__)
`ruby -I#{lib} #{script} #{Shellwords.join(args)} 2>&1`
end
end