bpm 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/Gemfile +0 -13
- data/TODO.md +1 -0
- data/bpm.gemspec +8 -3
- data/lib/bpm/cli/base.rb +22 -20
- data/lib/bpm/generator.rb +3 -3
- data/lib/bpm/libgems_ext/dependency_installer.rb +4 -4
- data/lib/bpm/libgems_ext/installer.rb +1 -1
- data/lib/bpm/package.rb +13 -9
- data/lib/bpm/pipeline/generated_asset.rb +30 -3
- data/lib/bpm/pipeline/transport_processor.rb +20 -12
- data/lib/bpm/pipeline.rb +17 -9
- data/lib/bpm/project.rb +42 -10
- data/lib/bpm/server.rb +5 -0
- data/lib/bpm/version.rb +1 -1
- data/lib/bpm.rb +2 -0
- data/lib/vendored_sprockets.rb +7 -0
- data/spec/cli/add_spec.rb +40 -37
- data/spec/cli/build_spec.rb +5 -5
- data/spec/cli/new_spec.rb +49 -23
- data/spec/cli/push_spec.rb +5 -5
- data/spec/cli/unpack_spec.rb +14 -14
- data/spec/fixtures/{badrake-0.8.7.spd → badrake-0.8.7.bpkg} +0 -0
- data/spec/fixtures/{builder-3.0.0.spd → builder-3.0.0.bpkg} +0 -0
- data/spec/fixtures/{bundler-1.1.pre.spd → bundler-1.1.pre.bpkg} +0 -0
- data/spec/fixtures/{coffee-1.0.1.pre.spd → coffee-1.0.1.pre.bpkg} +0 -0
- data/spec/fixtures/{core-test-0.4.9.spd → core-test-0.4.9.bpkg} +0 -0
- data/spec/fixtures/{custom_generator-1.0.spd → custom_generator-1.0.bpkg} +0 -0
- data/spec/fixtures/custom_name/MyProject.json +4 -0
- data/spec/fixtures/hello_world/css/dummy.css +3 -0
- data/spec/fixtures/{highline-1.6.1.spd → highline-1.6.1.bpkg} +0 -0
- data/spec/fixtures/{ivory-0.0.1.spd → ivory-0.0.1.bpkg} +0 -0
- data/spec/fixtures/{jquery-1.4.3.spd → jquery-1.4.3.bpkg} +0 -0
- data/spec/fixtures/minitest/assets/bpm_packages.js +1 -0
- data/spec/fixtures/minitest/assets/bpm_styles.css +0 -0
- data/spec/fixtures/minitest/assets/minitest/app_package.js +1 -0
- data/spec/fixtures/minitest/lib/main.js +1 -0
- data/spec/fixtures/minitest/minitest.json +22 -0
- data/spec/fixtures/minitest/packages/uglyduck/lib/main.js +1 -0
- data/spec/fixtures/minitest/packages/uglyduck/minifier/main.js +4 -0
- data/spec/fixtures/minitest/packages/uglyduck/package.json +21 -0
- data/spec/fixtures/{optparse-1.0.1.spd → optparse-1.0.1.bpkg} +0 -0
- data/spec/fixtures/{rake-0.8.6.spd → rake-0.8.6.bpkg} +0 -0
- data/spec/fixtures/{rake-0.8.7.spd → rake-0.8.7.bpkg} +0 -0
- data/spec/fixtures/{spade-0.5.0.spd → spade-0.5.0.bpkg} +0 -0
- data/spec/fixtures/transporter/packages/transport/lib/main.js +1 -0
- data/spec/fixtures/transporter/packages/transport/package.json +1 -1
- data/spec/fixtures/transporter/packages/transport/transports/wrapper.js +5 -0
- data/spec/gauntlet_spec.rb +2 -2
- data/spec/package_spec.rb +3 -3
- data/spec/pipeline_spec.rb +175 -54
- data/spec/project_spec.rb +19 -3
- data/spec/support/fake_gem_server.rb +4 -4
- data/templates/init/project.json +3 -1
- data/templates/project/index.html +1 -1
- data/vendor/sprockets/.gitignore +7 -0
- data/vendor/sprockets/.travis.yml +6 -0
- data/vendor/sprockets/Gemfile +8 -0
- data/vendor/sprockets/LICENSE +20 -0
- data/vendor/sprockets/README.md +22 -0
- data/vendor/sprockets/Rakefile +8 -0
- data/vendor/sprockets/lib/sprockets/asset.rb +203 -0
- data/vendor/sprockets/lib/sprockets/asset_attributes.rb +161 -0
- data/vendor/sprockets/lib/sprockets/base.rb +147 -0
- data/vendor/sprockets/lib/sprockets/bundled_asset.rb +222 -0
- data/vendor/sprockets/lib/sprockets/cache/file_store.rb +41 -0
- data/vendor/sprockets/lib/sprockets/caching.rb +121 -0
- data/vendor/sprockets/lib/sprockets/charset_normalizer.rb +41 -0
- data/vendor/sprockets/lib/sprockets/context.rb +191 -0
- data/vendor/sprockets/lib/sprockets/digest.rb +73 -0
- data/vendor/sprockets/lib/sprockets/directive_processor.rb +380 -0
- data/vendor/sprockets/lib/sprockets/eco_template.rb +39 -0
- data/vendor/sprockets/lib/sprockets/ejs_template.rb +38 -0
- data/vendor/sprockets/lib/sprockets/engines.rb +92 -0
- data/vendor/sprockets/lib/sprockets/environment.rb +93 -0
- data/vendor/sprockets/lib/sprockets/errors.rb +17 -0
- data/vendor/sprockets/lib/sprockets/index.rb +80 -0
- data/vendor/sprockets/lib/sprockets/jst_processor.rb +26 -0
- data/vendor/sprockets/lib/sprockets/processing.rb +310 -0
- data/vendor/sprockets/lib/sprockets/processor.rb +32 -0
- data/vendor/sprockets/lib/sprockets/safety_colons.rb +28 -0
- data/vendor/sprockets/lib/sprockets/server.rb +270 -0
- data/vendor/sprockets/lib/sprockets/static_asset.rb +87 -0
- data/vendor/sprockets/lib/sprockets/static_compilation.rb +82 -0
- data/vendor/sprockets/lib/sprockets/trail.rb +122 -0
- data/vendor/sprockets/lib/sprockets/utils.rb +67 -0
- data/vendor/sprockets/lib/sprockets/version.rb +3 -0
- data/vendor/sprockets/lib/sprockets.rb +31 -0
- data/vendor/sprockets/sprockets.gemspec +30 -0
- data/vendor/sprockets/test/fixtures/asset/POW.png +0 -0
- data/vendor/sprockets/test/fixtures/asset/application.js +6 -0
- data/vendor/sprockets/test/fixtures/asset/bar-utf8.css +2 -0
- data/vendor/sprockets/test/fixtures/asset/charset.css +2 -0
- data/vendor/sprockets/test/fixtures/asset/circle/a.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/circle/b.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/circle/c.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/compat.js +4 -0
- data/vendor/sprockets/test/fixtures/asset/constants.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/constants.yml +1 -0
- data/vendor/sprockets/test/fixtures/asset/default_mime_type.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/filename.js.erb +1 -0
- data/vendor/sprockets/test/fixtures/asset/foo-utf8.css +2 -0
- data/vendor/sprockets/test/fixtures/asset/included_header.js +4 -0
- data/vendor/sprockets/test/fixtures/asset/jquery.tmpl.min.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/mismatch.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/multiple.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/multipleengine.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/noengine.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/noformat.coffee +1 -0
- data/vendor/sprockets/test/fixtures/asset/one.css +1 -0
- data/vendor/sprockets/test/fixtures/asset/oneengine.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/project.css +1 -0
- data/vendor/sprockets/test/fixtures/asset/project.js.erb +4 -0
- data/vendor/sprockets/test/fixtures/asset/relative/include.js +4 -0
- data/vendor/sprockets/test/fixtures/asset/relative/require.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/relative/require_outside_path.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/require_self.css +9 -0
- data/vendor/sprockets/test/fixtures/asset/require_self_twice.css +8 -0
- data/vendor/sprockets/test/fixtures/asset/semicolons/bar.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/semicolons/index.js +5 -0
- data/vendor/sprockets/test/fixtures/asset/sprite.css.erb +12 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/d.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/e.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/b/c.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/b.css +2 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/b.js.erb +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/d/c.js.coffee +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all/d/e.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all_with_require.js +7 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_directory.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_tree.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/tree/directory/application.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/tree/directory/bar.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/directory/foo.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/tree/application.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/tree/tree/bar.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/tree/foo.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/a/a.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/require_tree_with_logical_path.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/without_argument/a.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/without_argument/b.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/tree/without_argument/require_tree_without_argument.js +1 -0
- data/vendor/sprockets/test/fixtures/asset/two.css +1 -0
- data/vendor/sprockets/test/fixtures/asset/unicode.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/unknownexts.min.js +2 -0
- data/vendor/sprockets/test/fixtures/asset/users.js.erb.str +4 -0
- data/vendor/sprockets/test/fixtures/context/POW.png +0 -0
- data/vendor/sprockets/test/fixtures/context/application.js.yml +3 -0
- data/vendor/sprockets/test/fixtures/context/bar.js +1 -0
- data/vendor/sprockets/test/fixtures/context/foo.js +2 -0
- data/vendor/sprockets/test/fixtures/context/helpers.css.erb +3 -0
- data/vendor/sprockets/test/fixtures/context/properties.js.erb +7 -0
- data/vendor/sprockets/test/fixtures/context/require_glob.js +1 -0
- data/vendor/sprockets/test/fixtures/context/resolve_content_type.js.erb +4 -0
- data/vendor/sprockets/test/fixtures/context/sprite.css.embed +3 -0
- data/vendor/sprockets/test/fixtures/default/application.js.coffee +4 -0
- data/vendor/sprockets/test/fixtures/default/coffee/foo.coffee +1 -0
- data/vendor/sprockets/test/fixtures/default/coffee/index.js +3 -0
- data/vendor/sprockets/test/fixtures/default/empty +0 -0
- data/vendor/sprockets/test/fixtures/default/gallery.css.erb +3 -0
- data/vendor/sprockets/test/fixtures/default/gallery.js +1 -0
- data/vendor/sprockets/test/fixtures/default/goodbye.jst.eco +1 -0
- data/vendor/sprockets/test/fixtures/default/hello.jst.ejs +1 -0
- data/vendor/sprockets/test/fixtures/default/hello.txt +1 -0
- data/vendor/sprockets/test/fixtures/default/interpolation.js +1 -0
- data/vendor/sprockets/test/fixtures/default/missing_require.js +1 -0
- data/vendor/sprockets/test/fixtures/default/mobile/a.js +1 -0
- data/vendor/sprockets/test/fixtures/default/mobile/b.js +1 -0
- data/vendor/sprockets/test/fixtures/default/mobile/c.css +1 -0
- data/vendor/sprockets/test/fixtures/default/mobile/d.css +1 -0
- data/vendor/sprockets/test/fixtures/default/mobile/index.css +3 -0
- data/vendor/sprockets/test/fixtures/default/mobile/index.js +1 -0
- data/vendor/sprockets/test/fixtures/default/noreturn.js +1 -0
- data/vendor/sprockets/test/fixtures/default/project.js.coffee.erb +2 -0
- data/vendor/sprockets/test/fixtures/directives/code_before_comment +3 -0
- data/vendor/sprockets/test/fixtures/directives/comment_without_directives +6 -0
- data/vendor/sprockets/test/fixtures/directives/directive_word_splitting +6 -0
- data/vendor/sprockets/test/fixtures/directives/directives_after_header +16 -0
- data/vendor/sprockets/test/fixtures/directives/double_slash +9 -0
- data/vendor/sprockets/test/fixtures/directives/hash +8 -0
- data/vendor/sprockets/test/fixtures/directives/no_header +2 -0
- data/vendor/sprockets/test/fixtures/directives/slash_star +10 -0
- data/vendor/sprockets/test/fixtures/directives/slash_star_single +4 -0
- data/vendor/sprockets/test/fixtures/directives/space_between_directive_word +2 -0
- data/vendor/sprockets/test/fixtures/directives/triple_hash +10 -0
- data/vendor/sprockets/test/fixtures/encoding/ascii.js +1 -0
- data/vendor/sprockets/test/fixtures/encoding/ascii_utf8.js +2 -0
- data/vendor/sprockets/test/fixtures/encoding/utf16.js +0 -0
- data/vendor/sprockets/test/fixtures/encoding/utf8.js +1 -0
- data/vendor/sprockets/test/fixtures/encoding/utf8_bom.js +1 -0
- data/vendor/sprockets/test/fixtures/engines/hello.alert +1 -0
- data/vendor/sprockets/test/fixtures/engines/moo.js.str +1 -0
- data/vendor/sprockets/test/fixtures/public/compiled-digest-0aa2105d29558f3eb790d411d7d8fb66.js +3 -0
- data/vendor/sprockets/test/fixtures/public/compiled-digest-1c41eb0cf934a0c76babe875f982f9d1.js +1 -0
- data/vendor/sprockets/test/fixtures/server/app/javascripts/application.js +5 -0
- data/vendor/sprockets/test/fixtures/server/app/javascripts/bar.js +1 -0
- data/vendor/sprockets/test/fixtures/server/app/javascripts/foo.js +1 -0
- data/vendor/sprockets/test/fixtures/server/app/javascripts/hello.txt +2 -0
- data/vendor/sprockets/test/fixtures/server/app/javascripts/tree.js +1 -0
- data/vendor/sprockets/test/fixtures/server/vendor/javascripts/missing_require.js +1 -0
- data/vendor/sprockets/test/fixtures/server/vendor/stylesheets/missing_require.css +1 -0
- data/vendor/sprockets/test/sprockets_test.rb +56 -0
- data/vendor/sprockets/test/test_asset.rb +593 -0
- data/vendor/sprockets/test/test_asset_attributes.rb +86 -0
- data/vendor/sprockets/test/test_caching.rb +62 -0
- data/vendor/sprockets/test/test_context.rb +115 -0
- data/vendor/sprockets/test/test_directive_processor.rb +124 -0
- data/vendor/sprockets/test/test_encoding.rb +65 -0
- data/vendor/sprockets/test/test_engines.rb +73 -0
- data/vendor/sprockets/test/test_environment.rb +610 -0
- data/vendor/sprockets/test/test_server.rb +227 -0
- metadata +258 -54
- data/spec/fixtures/transporter/packages/transport/lib/wrapper.js +0 -5
@@ -0,0 +1,610 @@
|
|
1
|
+
require 'sprockets_test'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'execjs'
|
4
|
+
|
5
|
+
module EnvironmentTests
|
6
|
+
def self.test(name, &block)
|
7
|
+
define_method("test #{name.inspect}", &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "working directory is the default root" do
|
11
|
+
assert_equal Dir.pwd, @env.root
|
12
|
+
end
|
13
|
+
|
14
|
+
test "default logger level is set to fatal" do
|
15
|
+
assert_equal Logger::FATAL, @env.logger.level
|
16
|
+
end
|
17
|
+
|
18
|
+
test "active css compressor" do
|
19
|
+
assert_nil @env.css_compressor
|
20
|
+
end
|
21
|
+
|
22
|
+
test "active js compressor" do
|
23
|
+
assert_nil @env.js_compressor
|
24
|
+
end
|
25
|
+
|
26
|
+
test "current static root" do
|
27
|
+
assert_equal fixture_path("public"), @env.static_root.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
test "paths" do
|
31
|
+
assert_equal [fixture_path("default")], @env.paths.to_a
|
32
|
+
end
|
33
|
+
|
34
|
+
test "extensions" do
|
35
|
+
["coffee", "erb", "less", "sass", "scss", "str", "css", "js"].each do |ext|
|
36
|
+
assert @env.extensions.to_a.include?(".#{ext}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test "engine extensions" do
|
41
|
+
["coffee", "erb", "less", "sass", "scss", "str"].each do |ext|
|
42
|
+
assert @env.engine_extensions.include?(".#{ext}")
|
43
|
+
end
|
44
|
+
["css", "js"].each do |ext|
|
45
|
+
assert !@env.engine_extensions.include?(".#{ext}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test "format extensions" do
|
50
|
+
["css", "js"].each do |ext|
|
51
|
+
assert @env.format_extensions.include?(".#{ext}")
|
52
|
+
end
|
53
|
+
["coffee", "erb", "less", "sass", "scss", "str"].each do |ext|
|
54
|
+
assert !@env.format_extensions.include?(".#{ext}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
test "eco templates" do
|
59
|
+
asset = @env["goodbye.jst"]
|
60
|
+
context = ExecJS.compile(asset)
|
61
|
+
assert_equal "Goodbye world\n", context.call("JST['goodbye']", :name => "world")
|
62
|
+
end
|
63
|
+
|
64
|
+
test "ejs templates" do
|
65
|
+
asset = @env["hello.jst"]
|
66
|
+
context = ExecJS.compile(asset)
|
67
|
+
assert_equal "hello: world\n", context.call("JST['hello']", :name => "world")
|
68
|
+
end
|
69
|
+
|
70
|
+
test "lookup mime type" do
|
71
|
+
assert_equal "application/javascript", @env.mime_types(".js")
|
72
|
+
assert_equal "application/javascript", @env.mime_types("js")
|
73
|
+
assert_equal "text/css", @env.mime_types(:css)
|
74
|
+
assert_equal nil, @env.mime_types("foo")
|
75
|
+
assert_equal nil, @env.mime_types("foo")
|
76
|
+
end
|
77
|
+
|
78
|
+
test "lookup bundle processors" do
|
79
|
+
assert_equal [], @env.bundle_processors('application/javascript')
|
80
|
+
assert_equal [Sprockets::CharsetNormalizer], @env.bundle_processors('text/css')
|
81
|
+
end
|
82
|
+
|
83
|
+
test "resolve in environment" do
|
84
|
+
assert_equal fixture_path('default/gallery.js'),
|
85
|
+
@env.resolve("gallery.js").to_s
|
86
|
+
assert_equal fixture_path('default/gallery.js'),
|
87
|
+
@env.resolve(Pathname.new("gallery.js")).to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
test "missing file raises an exception" do
|
91
|
+
assert_raises(Sprockets::FileNotFound) do
|
92
|
+
@env.resolve("null")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
test "find bundled asset in environment" do
|
97
|
+
assert_equal "var Gallery = {};\n", @env["gallery.js"].to_s
|
98
|
+
end
|
99
|
+
|
100
|
+
test "find bundled asset with absolute path environment" do
|
101
|
+
assert_equal "var Gallery = {};\n", @env[fixture_path("default/gallery.js")].to_s
|
102
|
+
end
|
103
|
+
|
104
|
+
test "find static asset in environment" do
|
105
|
+
assert_equal "Hello world\n", @env["hello.txt"].to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
test "find static asset with leading slash in environment" do
|
109
|
+
assert_equal "Hello world\n", @env[fixture_path("default/hello.txt")].to_s
|
110
|
+
end
|
111
|
+
|
112
|
+
test "find asset with digest" do
|
113
|
+
digest = @env["hello.txt"].digest
|
114
|
+
assert_equal "Hello world\n", @env["hello-#{digest}.txt"].to_s
|
115
|
+
end
|
116
|
+
|
117
|
+
test "find asset with invalid digest" do
|
118
|
+
assert_nil @env["hello-ffffffff.txt"]
|
119
|
+
end
|
120
|
+
|
121
|
+
test "find index.js in directory" do
|
122
|
+
assert_equal "var A;\nvar B;\n", @env["mobile.js"].to_s
|
123
|
+
end
|
124
|
+
|
125
|
+
test "find index.css in directory" do
|
126
|
+
assert_equal ".c {}\n.d {}\n/*\n */\n\n", @env["mobile.css"].to_s
|
127
|
+
end
|
128
|
+
|
129
|
+
test "missing static path returns nil" do
|
130
|
+
assert_nil @env[fixture_path("default/missing.png")]
|
131
|
+
end
|
132
|
+
|
133
|
+
test "find static directory returns nil" do
|
134
|
+
assert_nil @env["images"]
|
135
|
+
end
|
136
|
+
|
137
|
+
test "missing asset returns nil" do
|
138
|
+
assert_equal nil, @env["missing.js"]
|
139
|
+
end
|
140
|
+
|
141
|
+
test "missing asset path returns nil" do
|
142
|
+
assert_nil @env[fixture_path("default/missing.js")]
|
143
|
+
end
|
144
|
+
|
145
|
+
test "asset with missing requires raises an exception" do
|
146
|
+
assert_raises Sprockets::FileNotFound do
|
147
|
+
@env["missing_require.js"]
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
test "asset logical path for absolute path" do
|
152
|
+
assert_equal "gallery.js",
|
153
|
+
@env[fixture_path("default/gallery.js")].logical_path
|
154
|
+
assert_equal "application.js",
|
155
|
+
@env[fixture_path("default/application.js.coffee")].logical_path
|
156
|
+
assert_equal "mobile/a.js",
|
157
|
+
@env[fixture_path("default/mobile/a.js")].logical_path
|
158
|
+
end
|
159
|
+
|
160
|
+
test "path for asset" do
|
161
|
+
digest = @env["gallery.js"].digest
|
162
|
+
assert_equal "/gallery-#{digest}.js", @env.path("gallery.js")
|
163
|
+
assert_equal "/gallery.js", @env.path("gallery.js", false)
|
164
|
+
assert_equal "/gallery-#{digest}.js", @env.path("/gallery.js")
|
165
|
+
assert_equal "/assets/gallery-#{digest}.js",
|
166
|
+
@env.path("gallery.js", true, "/assets")
|
167
|
+
end
|
168
|
+
|
169
|
+
test "url for asset" do
|
170
|
+
env = Rack::MockRequest.env_for("/")
|
171
|
+
digest = @env["gallery.js"].digest
|
172
|
+
|
173
|
+
assert_equal "http://example.org/gallery-#{digest}.js",
|
174
|
+
@env.url(env, "gallery.js")
|
175
|
+
assert_equal "http://example.org/gallery.js",
|
176
|
+
@env.url(env, "gallery.js", false)
|
177
|
+
assert_equal "http://example.org/gallery-#{digest}.js",
|
178
|
+
@env.url(env, "/gallery.js")
|
179
|
+
assert_equal "http://example.org/assets/gallery-#{digest}.js",
|
180
|
+
@env.url(env, "gallery.js", true, "assets")
|
181
|
+
end
|
182
|
+
|
183
|
+
test "missing path for asset" do
|
184
|
+
assert_equal "/missing.js", @env.path("missing.js")
|
185
|
+
end
|
186
|
+
|
187
|
+
test "precompile" do
|
188
|
+
digest = @env["gallery.js"].digest
|
189
|
+
filename = fixture_path("public/gallery-#{digest}.js")
|
190
|
+
filename_gz = "#{filename}.gz"
|
191
|
+
|
192
|
+
sandbox filename, filename_gz do
|
193
|
+
assert !File.exist?(filename)
|
194
|
+
@env.precompile("gallery.js")
|
195
|
+
assert File.exist?(filename)
|
196
|
+
assert File.exist?(filename_gz)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
test "precompile glob" do
|
201
|
+
dirname = fixture_path("public/mobile")
|
202
|
+
|
203
|
+
a_digest = @env["mobile/a.js"].digest
|
204
|
+
b_digest = @env["mobile/b.js"].digest
|
205
|
+
c_digest = @env["mobile/c.css"].digest
|
206
|
+
|
207
|
+
sandbox dirname do
|
208
|
+
assert !File.exist?(dirname)
|
209
|
+
@env.precompile("mobile/*")
|
210
|
+
|
211
|
+
assert File.exist?(dirname)
|
212
|
+
[nil, '.gz'].each do |gzipped|
|
213
|
+
assert File.exist?(File.join(dirname, "a-#{a_digest}.js#{gzipped}"))
|
214
|
+
assert File.exist?(File.join(dirname, "b-#{b_digest}.js#{gzipped}"))
|
215
|
+
assert File.exist?(File.join(dirname, "c-#{c_digest}.css#{gzipped}"))
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
test "precompile regexp" do
|
221
|
+
dirname = fixture_path("public/mobile")
|
222
|
+
|
223
|
+
a_digest = @env["mobile/a.js"].digest
|
224
|
+
b_digest = @env["mobile/b.js"].digest
|
225
|
+
c_digest = @env["mobile/c.css"].digest
|
226
|
+
|
227
|
+
sandbox dirname do
|
228
|
+
assert !File.exist?(dirname)
|
229
|
+
@env.precompile(/mobile\/.*/)
|
230
|
+
|
231
|
+
assert File.exist?(dirname)
|
232
|
+
[nil, '.gz'].each do |gzipped|
|
233
|
+
assert File.exist?(File.join(dirname, "a-#{a_digest}.js#{gzipped}"))
|
234
|
+
assert File.exist?(File.join(dirname, "b-#{b_digest}.js#{gzipped}"))
|
235
|
+
assert File.exist?(File.join(dirname, "c-#{c_digest}.css#{gzipped}"))
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
test "precompile static asset" do
|
241
|
+
digest = @env["hello.txt"].digest
|
242
|
+
filename = fixture_path("public/hello-#{digest}.txt")
|
243
|
+
|
244
|
+
sandbox filename do
|
245
|
+
assert !File.exist?(filename)
|
246
|
+
@env.precompile("hello.txt")
|
247
|
+
assert File.exist?(filename)
|
248
|
+
assert !File.exist?("#{filename}.gz")
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
test "CoffeeScript files are compiled in a closure" do
|
253
|
+
script = @env["coffee"].to_s
|
254
|
+
assert_equal "undefined", ExecJS.exec(script)
|
255
|
+
end
|
256
|
+
|
257
|
+
test "assets environment reference is its caller" do
|
258
|
+
assert_equal @env, @env["gallery.js"].environment
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
class WhitespaceCompressor
|
263
|
+
def self.compress(source)
|
264
|
+
source.gsub(/\s+/, "")
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
class TestEnvironment < Sprockets::TestCase
|
269
|
+
include EnvironmentTests
|
270
|
+
|
271
|
+
def new_environment
|
272
|
+
Sprockets::Environment.new(".") do |env|
|
273
|
+
env.append_path(fixture_path('default'))
|
274
|
+
env.static_root = fixture_path('public')
|
275
|
+
env.cache = {}
|
276
|
+
yield env if block_given?
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def setup
|
281
|
+
@env = new_environment
|
282
|
+
end
|
283
|
+
|
284
|
+
test "changing logger" do
|
285
|
+
@env.logger = Logger.new($stderr)
|
286
|
+
end
|
287
|
+
|
288
|
+
test "changing paths" do
|
289
|
+
old_digest = @env.digest
|
290
|
+
|
291
|
+
@env.clear_paths
|
292
|
+
@env.append_path(fixture_path('asset'))
|
293
|
+
|
294
|
+
assert_not_equal old_digest, @env.digest
|
295
|
+
end
|
296
|
+
|
297
|
+
test "register mime type" do
|
298
|
+
old_digest = @env.digest
|
299
|
+
assert !@env.mime_types("jst")
|
300
|
+
|
301
|
+
@env.register_mime_type("application/javascript", "jst")
|
302
|
+
|
303
|
+
assert_equal "application/javascript", @env.mime_types("jst")
|
304
|
+
assert_not_equal old_digest, @env.digest
|
305
|
+
end
|
306
|
+
|
307
|
+
test "register bundle processor" do
|
308
|
+
old_digest = @env.digest
|
309
|
+
assert !@env.bundle_processors('text/css').include?(WhitespaceCompressor)
|
310
|
+
|
311
|
+
@env.register_bundle_processor 'text/css', WhitespaceCompressor
|
312
|
+
|
313
|
+
assert @env.bundle_processors('text/css').include?(WhitespaceCompressor)
|
314
|
+
assert_not_equal old_digest, @env.digest
|
315
|
+
end
|
316
|
+
|
317
|
+
test "unregister custom block preprocessor" do
|
318
|
+
old_size = @env.preprocessors('text/css').size
|
319
|
+
@env.register_preprocessor('text/css', :foo) { |context, data| data }
|
320
|
+
assert_equal old_size+1, @env.preprocessors('text/css').size
|
321
|
+
@env.unregister_preprocessor('text/css', :foo)
|
322
|
+
assert_equal old_size, @env.preprocessors('text/css').size
|
323
|
+
end
|
324
|
+
|
325
|
+
test "unregister custom block postprocessor" do
|
326
|
+
old_size = @env.postprocessors('text/css').size
|
327
|
+
@env.register_postprocessor('text/css', :foo) { |context, data| data }
|
328
|
+
assert_equal old_size+1, @env.postprocessors('text/css').size
|
329
|
+
@env.unregister_postprocessor('text/css', :foo)
|
330
|
+
assert_equal old_size, @env.postprocessors('text/css').size
|
331
|
+
end
|
332
|
+
|
333
|
+
test "unregister custom block bundle processor" do
|
334
|
+
old_size = @env.bundle_processors('text/css').size
|
335
|
+
@env.register_bundle_processor('text/css', :foo) { |context, data| data }
|
336
|
+
assert_equal old_size+1, @env.bundle_processors('text/css').size
|
337
|
+
@env.unregister_bundle_processor('text/css', :foo)
|
338
|
+
assert_equal old_size, @env.bundle_processors('text/css').size
|
339
|
+
end
|
340
|
+
|
341
|
+
test "changing css compressor expires old assets" do
|
342
|
+
old_digest = @env.digest
|
343
|
+
assert_equal ".gallery {\n color: red;\n}\n", @env["gallery.css"].to_s
|
344
|
+
|
345
|
+
@env.css_compressor = WhitespaceCompressor
|
346
|
+
|
347
|
+
assert_equal ".gallery{color:red;}", @env["gallery.css"].to_s
|
348
|
+
assert_not_equal old_digest, @env.digest
|
349
|
+
end
|
350
|
+
|
351
|
+
test "setting css compressor to nil clears current compressor" do
|
352
|
+
old_digest = @env.digest
|
353
|
+
@env.css_compressor = WhitespaceCompressor
|
354
|
+
assert @env.css_compressor
|
355
|
+
@env.css_compressor = nil
|
356
|
+
assert_nil @env.css_compressor
|
357
|
+
end
|
358
|
+
|
359
|
+
test "changing js compressor expires old assets" do
|
360
|
+
old_digest = @env.digest
|
361
|
+
assert_equal "var Gallery = {};\n", @env["gallery.js"].to_s
|
362
|
+
|
363
|
+
@env.js_compressor = WhitespaceCompressor
|
364
|
+
|
365
|
+
assert_equal "varGallery={};", @env["gallery.js"].to_s
|
366
|
+
assert_not_equal old_digest, @env.digest
|
367
|
+
end
|
368
|
+
|
369
|
+
test "setting js compressor to nil clears current compressor" do
|
370
|
+
@env.js_compressor = WhitespaceCompressor
|
371
|
+
assert @env.js_compressor
|
372
|
+
@env.js_compressor = nil
|
373
|
+
assert_nil @env.js_compressor
|
374
|
+
end
|
375
|
+
|
376
|
+
test "changing paths expires old assets" do
|
377
|
+
old_digest = @env.digest
|
378
|
+
assert @env["gallery.css"]
|
379
|
+
|
380
|
+
@env.clear_paths
|
381
|
+
|
382
|
+
assert_not_equal old_digest, @env.digest
|
383
|
+
assert_nil @env["gallery.css"]
|
384
|
+
end
|
385
|
+
|
386
|
+
test "changing digest implementation class" do
|
387
|
+
old_digest = @env.digest
|
388
|
+
old_asset_digest = @env["gallery.js"].digest
|
389
|
+
|
390
|
+
require 'digest/sha1'
|
391
|
+
@env.digest_class = Digest::SHA1
|
392
|
+
|
393
|
+
assert_not_equal old_digest, @env.digest
|
394
|
+
assert_not_equal old_asset_digest, @env["gallery.js"].digest
|
395
|
+
end
|
396
|
+
|
397
|
+
test "changing digest version" do
|
398
|
+
old_digest = @env.digest
|
399
|
+
old_asset_digest = @env["gallery.js"].digest
|
400
|
+
|
401
|
+
@env.version = 'v2'
|
402
|
+
|
403
|
+
assert_not_equal old_digest, @env.digest
|
404
|
+
assert_not_equal old_asset_digest, @env["gallery.js"].digest
|
405
|
+
end
|
406
|
+
|
407
|
+
test "bundled asset is stale if its mtime is updated or deleted" do
|
408
|
+
filename = File.join(fixture_path("default"), "tmp.js")
|
409
|
+
|
410
|
+
sandbox filename do
|
411
|
+
assert_nil @env["tmp.js"]
|
412
|
+
|
413
|
+
File.open(filename, 'w') { |f| f.puts "foo;" }
|
414
|
+
assert_equal "foo;\n", @env["tmp.js"].to_s
|
415
|
+
|
416
|
+
File.open(filename, 'w') { |f| f.puts "bar;" }
|
417
|
+
time = Time.now + 60
|
418
|
+
File.utime(time, time, filename)
|
419
|
+
assert_equal "bar;\n", @env["tmp.js"].to_s
|
420
|
+
|
421
|
+
File.unlink(filename)
|
422
|
+
assert_nil @env["tmp.js"]
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
test "static asset is stale if its mtime is updated or deleted" do
|
427
|
+
filename = File.join(fixture_path("default"), "tmp.png")
|
428
|
+
|
429
|
+
sandbox filename do
|
430
|
+
assert_nil @env["tmp.png"]
|
431
|
+
|
432
|
+
File.open(filename, 'w') { |f| f.puts "foo" }
|
433
|
+
assert_equal "foo\n", @env["tmp.png"].to_s
|
434
|
+
|
435
|
+
File.open(filename, 'w') { |f| f.puts "bar" }
|
436
|
+
time = Time.now + 60
|
437
|
+
File.utime(time, time, filename)
|
438
|
+
assert_equal "bar\n", @env["tmp.png"].to_s
|
439
|
+
|
440
|
+
File.unlink(filename)
|
441
|
+
assert_nil @env["tmp.png"]
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
test "seperate contexts classes for each instance" do
|
446
|
+
e1 = new_environment
|
447
|
+
e2 = new_environment
|
448
|
+
|
449
|
+
assert_raises(NameError) { e1.context_class.instance_method(:foo) }
|
450
|
+
assert_raises(NameError) { e2.context_class.instance_method(:foo) }
|
451
|
+
|
452
|
+
e1.context_class.class_eval do
|
453
|
+
def foo; end
|
454
|
+
end
|
455
|
+
|
456
|
+
assert_nothing_raised(NameError) { e1.context_class.instance_method(:foo) }
|
457
|
+
assert_raises(NameError) { e2.context_class.instance_method(:foo) }
|
458
|
+
end
|
459
|
+
|
460
|
+
test "registering engine adds to the environments extensions" do
|
461
|
+
old_digest = @env.digest
|
462
|
+
assert !@env.engines[".foo"]
|
463
|
+
assert !@env.extensions.include?(".foo")
|
464
|
+
|
465
|
+
@env.register_engine ".foo", Tilt::StringTemplate
|
466
|
+
|
467
|
+
assert @env.engines[".foo"]
|
468
|
+
assert @env.extensions.include?(".foo")
|
469
|
+
assert_not_equal old_digest, @env.digest
|
470
|
+
end
|
471
|
+
|
472
|
+
test "seperate engines for each instance" do
|
473
|
+
e1 = new_environment
|
474
|
+
e2 = new_environment
|
475
|
+
|
476
|
+
assert_nil e1.engines[".foo"]
|
477
|
+
assert_nil e2.engines[".foo"]
|
478
|
+
|
479
|
+
e1.register_engine ".foo", Tilt::StringTemplate
|
480
|
+
|
481
|
+
assert e1.engines[".foo"]
|
482
|
+
assert_nil e2.engines[".foo"]
|
483
|
+
end
|
484
|
+
|
485
|
+
test "disabling default directive preprocessor" do
|
486
|
+
@env.unregister_preprocessor('application/javascript', Sprockets::DirectiveProcessor)
|
487
|
+
assert_equal "// =require \"notfound\"\n;\n", @env["missing_require.js"].to_s
|
488
|
+
end
|
489
|
+
|
490
|
+
test "changing directive preprocessor changes digest" do
|
491
|
+
old_digest = @env.digest
|
492
|
+
@env.unregister_preprocessor('application/javascript', Sprockets::DirectiveProcessor)
|
493
|
+
assert_not_equal old_digest, @env.digest
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
class TestIndex < Sprockets::TestCase
|
498
|
+
include EnvironmentTests
|
499
|
+
|
500
|
+
def new_environment
|
501
|
+
Sprockets::Environment.new(".") do |env|
|
502
|
+
env.append_path(fixture_path('default'))
|
503
|
+
env.static_root = fixture_path('public')
|
504
|
+
env.cache = {}
|
505
|
+
yield env if block_given?
|
506
|
+
end.index
|
507
|
+
end
|
508
|
+
|
509
|
+
def setup
|
510
|
+
@env = new_environment
|
511
|
+
end
|
512
|
+
|
513
|
+
test "does not allow static root to be changed" do
|
514
|
+
assert_raises TypeError do
|
515
|
+
@env.static_root = fixture_path('public')
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
test "does not allow new mime types to be added" do
|
520
|
+
assert_raises TypeError do
|
521
|
+
@env.register_mime_type "application/javascript", ".jst"
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
test "change in environment mime types does not affect index" do
|
526
|
+
env = Sprockets::Environment.new(".")
|
527
|
+
env.register_mime_type "application/javascript", ".jst"
|
528
|
+
index = env.index
|
529
|
+
|
530
|
+
assert_equal "application/javascript", index.mime_types("jst")
|
531
|
+
env.register_mime_type nil, ".jst"
|
532
|
+
assert_equal "application/javascript", index.mime_types("jst")
|
533
|
+
end
|
534
|
+
|
535
|
+
test "does not allow new bundle processors to be added" do
|
536
|
+
assert_raises TypeError do
|
537
|
+
@env.register_bundle_processor 'text/css', WhitespaceCompressor
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
test "does not allow bundle processors to be removed" do
|
542
|
+
assert_raises TypeError do
|
543
|
+
@env.unregister_bundle_processor 'text/css', WhitespaceCompressor
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
test "change in environment bundle_processors does not affect index" do
|
548
|
+
env = Sprockets::Environment.new(".")
|
549
|
+
index = env.index
|
550
|
+
|
551
|
+
assert !index.bundle_processors('text/css').include?(WhitespaceCompressor)
|
552
|
+
env.register_bundle_processor 'text/css', WhitespaceCompressor
|
553
|
+
assert !index.bundle_processors('text/css').include?(WhitespaceCompressor)
|
554
|
+
end
|
555
|
+
|
556
|
+
test "change in environment static root does not affect index" do
|
557
|
+
env = Sprockets::Environment.new(".")
|
558
|
+
env.static_root = fixture_path('public')
|
559
|
+
index = env.index
|
560
|
+
|
561
|
+
assert_equal fixture_path('public'), index.static_root.to_s
|
562
|
+
env.static_root = fixture_path('static')
|
563
|
+
assert_equal fixture_path('public'), index.static_root.to_s
|
564
|
+
end
|
565
|
+
|
566
|
+
test "does not allow css compressor to be changed" do
|
567
|
+
assert_raises TypeError do
|
568
|
+
@env.css_compressor = WhitespaceCompressor
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
test "change in environment css compressor does not affect index" do
|
573
|
+
env = Sprockets::Environment.new(".")
|
574
|
+
env.css_compressor = WhitespaceCompressor
|
575
|
+
index = env.index
|
576
|
+
|
577
|
+
assert index.css_compressor
|
578
|
+
env.css_compressor = nil
|
579
|
+
assert index.css_compressor
|
580
|
+
end
|
581
|
+
|
582
|
+
test "does not allow js compressor to be changed" do
|
583
|
+
assert_raises TypeError do
|
584
|
+
@env.js_compressor = WhitespaceCompressor
|
585
|
+
end
|
586
|
+
end
|
587
|
+
|
588
|
+
test "change in environment js compressor does not affect index" do
|
589
|
+
env = Sprockets::Environment.new(".")
|
590
|
+
env.js_compressor = WhitespaceCompressor
|
591
|
+
index = env.index
|
592
|
+
|
593
|
+
assert index.js_compressor
|
594
|
+
env.js_compressor = nil
|
595
|
+
assert index.js_compressor
|
596
|
+
end
|
597
|
+
|
598
|
+
test "change in environment engines does not affect index" do
|
599
|
+
env = Sprockets::Environment.new
|
600
|
+
index = env.index
|
601
|
+
|
602
|
+
assert_nil env.engines[".foo"]
|
603
|
+
assert_nil index.engines[".foo"]
|
604
|
+
|
605
|
+
env.register_engine ".foo", Tilt::StringTemplate
|
606
|
+
|
607
|
+
assert env.engines[".foo"]
|
608
|
+
assert_nil index.engines[".foo"]
|
609
|
+
end
|
610
|
+
end
|