bpm 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,56 @@
|
|
|
1
|
+
require "test/unit"
|
|
2
|
+
require "sprockets"
|
|
3
|
+
require "tilt"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
if defined? Encoding
|
|
7
|
+
Encoding.default_external = 'utf-8'
|
|
8
|
+
Encoding.default_internal = 'utf-8'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Sprockets::TestCase < Test::Unit::TestCase
|
|
12
|
+
FIXTURE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "fixtures"))
|
|
13
|
+
|
|
14
|
+
undef_method :default_test if method_defined? :default_test
|
|
15
|
+
|
|
16
|
+
def self.test(name, &block)
|
|
17
|
+
define_method("test #{name.inspect}", &block)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def fixture(path)
|
|
21
|
+
IO.read(fixture_path(path))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def fixture_path(path)
|
|
25
|
+
File.join(FIXTURE_ROOT, path)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def sandbox(*paths)
|
|
29
|
+
backup_paths = paths.select { |path| File.exist?(path) }
|
|
30
|
+
remove_paths = paths.select { |path| !File.exist?(path) }
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
backup_paths.each do |path|
|
|
34
|
+
FileUtils.cp(path, "#{path}.orig")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
yield
|
|
38
|
+
ensure
|
|
39
|
+
backup_paths.each do |path|
|
|
40
|
+
if File.exist?("#{path}.orig")
|
|
41
|
+
FileUtils.mv("#{path}.orig", path)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
assert !File.exist?("#{path}.orig")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
remove_paths.each do |path|
|
|
48
|
+
if File.exist?(path)
|
|
49
|
+
FileUtils.rm_rf(path)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
assert !File.exist?(path)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
require "sprockets_test"
|
|
2
|
+
|
|
3
|
+
module AssetTests
|
|
4
|
+
def self.test(name, &block)
|
|
5
|
+
define_method("test #{name.inspect}", &block)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "pathname is a Pathname that exists" do
|
|
9
|
+
assert_kind_of Pathname, @asset.pathname
|
|
10
|
+
assert @asset.pathname.exist?
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "logical path can find itself" do
|
|
14
|
+
assert_equal @asset, @env[@asset.logical_path]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "mtime" do
|
|
18
|
+
assert @asset.mtime
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "digest" do
|
|
22
|
+
assert @asset.digest
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test "stale?" do
|
|
26
|
+
assert !@asset.stale?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "fresh?" do
|
|
30
|
+
assert @asset.fresh?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test "dependencies are an Array" do
|
|
34
|
+
assert_kind_of Array, @asset.dependencies
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test "splat asset" do
|
|
38
|
+
assert_kind_of Array, @asset.to_a
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test "body is a String" do
|
|
42
|
+
assert_kind_of String, @asset.body
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test "write to file" do
|
|
46
|
+
target = fixture_path('asset/tmp.js')
|
|
47
|
+
begin
|
|
48
|
+
@asset.write_to(target)
|
|
49
|
+
assert File.exist?(target)
|
|
50
|
+
assert_equal @asset.mtime, File.mtime(target)
|
|
51
|
+
ensure
|
|
52
|
+
FileUtils.rm(target) if File.exist?(target)
|
|
53
|
+
assert !File.exist?(target)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test "write to gzipped file" do
|
|
58
|
+
target = fixture_path('asset/tmp.js.gz')
|
|
59
|
+
begin
|
|
60
|
+
@asset.write_to(target)
|
|
61
|
+
assert File.exist?(target)
|
|
62
|
+
assert_equal @asset.mtime, File.mtime(target)
|
|
63
|
+
ensure
|
|
64
|
+
FileUtils.rm(target) if File.exist?(target)
|
|
65
|
+
assert !File.exist?(target)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class StaticAssetTest < Sprockets::TestCase
|
|
71
|
+
def setup
|
|
72
|
+
@env = Sprockets::Environment.new
|
|
73
|
+
@env.append_path(fixture_path('asset'))
|
|
74
|
+
@env.cache = {}
|
|
75
|
+
|
|
76
|
+
@asset = @env['POW.png']
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
include AssetTests
|
|
80
|
+
|
|
81
|
+
test "class" do
|
|
82
|
+
assert_kind_of Sprockets::StaticAsset, @asset
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
test "content type" do
|
|
86
|
+
assert_equal "image/png", @asset.content_type
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
test "length" do
|
|
90
|
+
assert_equal 42917, @asset.length
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
test "splat" do
|
|
94
|
+
assert_equal [@asset], @asset.to_a
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test "dependencies" do
|
|
98
|
+
assert_equal [], @asset.dependencies
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
test "to path" do
|
|
102
|
+
assert_equal fixture_path('asset/POW.png'), @asset.to_path
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
test "body is entire contents" do
|
|
106
|
+
assert_equal @asset.to_s, @asset.body
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
test "asset is fresh if its mtime and contents are the same" do
|
|
110
|
+
assert @asset.fresh?
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
test "asset is stale if its environment has changed" do
|
|
114
|
+
assert @asset.fresh?
|
|
115
|
+
@env.prepend_path fixture_path('default')
|
|
116
|
+
assert @asset.stale?
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
test "asset is fresh if its mtime is changed but its contents is the same" do
|
|
120
|
+
filename = fixture_path('asset/POW.png')
|
|
121
|
+
|
|
122
|
+
sandbox filename do
|
|
123
|
+
File.open(filename, 'w') { |f| f.write "a" }
|
|
124
|
+
asset = @env['POW.png']
|
|
125
|
+
|
|
126
|
+
assert asset.fresh?
|
|
127
|
+
|
|
128
|
+
File.open(filename, 'w') { |f| f.write "a" }
|
|
129
|
+
mtime = Time.now + 1
|
|
130
|
+
File.utime(mtime, mtime, filename)
|
|
131
|
+
|
|
132
|
+
assert asset.fresh?
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
test "asset is stale when its contents has changed" do
|
|
137
|
+
filename = fixture_path('asset/POW.png')
|
|
138
|
+
|
|
139
|
+
sandbox filename do
|
|
140
|
+
File.open(filename, 'w') { |f| f.write "a" }
|
|
141
|
+
asset = @env['POW.png']
|
|
142
|
+
|
|
143
|
+
assert asset.fresh?
|
|
144
|
+
|
|
145
|
+
File.open(filename, 'w') { |f| f.write "b" }
|
|
146
|
+
mtime = Time.now + 1
|
|
147
|
+
File.utime(mtime, mtime, filename)
|
|
148
|
+
|
|
149
|
+
assert asset.stale?
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
test "asset is stale if the file is removed" do
|
|
154
|
+
filename = fixture_path('asset/POW.png')
|
|
155
|
+
|
|
156
|
+
sandbox filename do
|
|
157
|
+
File.open(filename, 'w') { |f| f.write "a" }
|
|
158
|
+
asset = @env['POW.png']
|
|
159
|
+
|
|
160
|
+
assert asset.fresh?
|
|
161
|
+
|
|
162
|
+
File.unlink(filename)
|
|
163
|
+
|
|
164
|
+
assert asset.stale?
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
test "serializing asset to and from hash" do
|
|
169
|
+
expected = @asset
|
|
170
|
+
hash = {}
|
|
171
|
+
@asset.encode_with(hash)
|
|
172
|
+
actual = @env.asset_from_hash(hash)
|
|
173
|
+
|
|
174
|
+
assert_kind_of Sprockets::StaticAsset, actual
|
|
175
|
+
assert_equal expected.logical_path, actual.logical_path
|
|
176
|
+
assert_equal expected.pathname, actual.pathname
|
|
177
|
+
assert_equal expected.content_type, actual.content_type
|
|
178
|
+
assert_equal expected.length, actual.length
|
|
179
|
+
assert_equal expected.digest, actual.digest
|
|
180
|
+
|
|
181
|
+
assert_equal expected.dependencies, actual.dependencies
|
|
182
|
+
assert_equal expected.to_a, actual.to_a
|
|
183
|
+
assert_equal expected.body, actual.body
|
|
184
|
+
assert_equal expected.to_s, actual.to_s
|
|
185
|
+
|
|
186
|
+
assert actual.eql?(expected)
|
|
187
|
+
assert expected.eql?(actual)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
class BundledAssetTest < Sprockets::TestCase
|
|
192
|
+
def setup
|
|
193
|
+
@env = Sprockets::Environment.new
|
|
194
|
+
@env.append_path(fixture_path('asset'))
|
|
195
|
+
@env.cache = {}
|
|
196
|
+
|
|
197
|
+
@asset = @env['application.js']
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
include AssetTests
|
|
201
|
+
|
|
202
|
+
test "class" do
|
|
203
|
+
assert_kind_of Sprockets::BundledAsset, @asset
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
test "content type" do
|
|
207
|
+
assert_equal "application/javascript", @asset.content_type
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
test "length" do
|
|
211
|
+
assert_equal 157, @asset.length
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
test "to_s" do
|
|
215
|
+
assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n", @asset.to_s
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
test "each" do
|
|
219
|
+
body = ""
|
|
220
|
+
@asset.each { |part| body << part }
|
|
221
|
+
assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n", body
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
test "requiring the same file multiple times has no effect" do
|
|
225
|
+
assert_equal read("project.js")+"\n", asset("multiple.js").to_s
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
test "requiring a file of a different format raises an exception" do
|
|
229
|
+
assert_raise Sprockets::ContentTypeMismatch do
|
|
230
|
+
asset("mismatch.js")
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
test "splatted asset includes itself" do
|
|
235
|
+
assert_equal [resolve("project.js")], asset("project.js").to_a.map(&:pathname)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
test "asset includes self as dependency" do
|
|
239
|
+
assert_equal [], asset("project.js").dependencies.map(&:pathname)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
test "asset with child dependencies" do
|
|
243
|
+
assert_equal [resolve("project.js"), resolve("users.js")],
|
|
244
|
+
asset("application.js").dependencies.map(&:pathname)
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
test "splatted asset with child dependencies" do
|
|
248
|
+
assert_equal [resolve("project.js"), resolve("users.js"), resolve("application.js")],
|
|
249
|
+
asset("application.js").to_a.map(&:pathname)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
test "bundled asset body is just its own contents" do
|
|
253
|
+
assert_equal "\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n",
|
|
254
|
+
asset("application.js").body
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
test "bundling joins files with blank line" do
|
|
258
|
+
assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n",
|
|
259
|
+
asset("application.js").to_s
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
test "dependencies appear in the source before files that required them" do
|
|
263
|
+
assert_match(/Project.+Users.+focus/m, asset("application.js").to_s)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
test "processing a source file with no engine extensions" do
|
|
267
|
+
assert_equal read("users.js"), asset("noengine.js").to_s
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
test "processing a source file with one engine extension" do
|
|
271
|
+
assert_equal read("users.js"), asset("oneengine.js").to_s
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
test "processing a source file with multiple engine extensions" do
|
|
275
|
+
assert_equal read("users.js"), asset("multipleengine.js").to_s
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
test "processing a source file with unknown extensions" do
|
|
279
|
+
assert_equal read("users.js") + "var jQuery;\n", asset("unknownexts.min.js").to_s
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
test "processing a source file in compat mode" do
|
|
283
|
+
assert_equal read("project.js") + "\n" + read("users.js"),
|
|
284
|
+
asset("compat.js").to_s
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
test "included dependencies are inserted after the header of the dependent file" do
|
|
288
|
+
assert_equal "# My Application\n" + read("project.js") + "\n\nhello();\n",
|
|
289
|
+
asset("included_header.js").to_s
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
test "requiring a file with a relative path" do
|
|
293
|
+
assert_equal read("project.js") + "\n",
|
|
294
|
+
asset("relative/require.js").to_s
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
test "including a file with a relative path" do
|
|
298
|
+
assert_equal "// Included relatively\n" + read("project.js") + "\n\nhello();\n", asset("relative/include.js").to_s
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
test "can't require files outside the load path" do
|
|
302
|
+
assert_raise Sprockets::FileNotFound do
|
|
303
|
+
asset("relative/require_outside_path.js")
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
test "require_directory requires all child files in alphabetical order" do
|
|
308
|
+
assert_equal(
|
|
309
|
+
"ok(\"b.js.erb\");\n",
|
|
310
|
+
asset("tree/all_with_require_directory.js").to_s
|
|
311
|
+
)
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
test "require_directory current directory includes self last" do
|
|
315
|
+
assert_equal(
|
|
316
|
+
"var Bar;\nvar Foo;\nvar App;\n",
|
|
317
|
+
asset("tree/directory/application.js").to_s
|
|
318
|
+
)
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
test "require_tree requires all descendant files in alphabetical order" do
|
|
322
|
+
assert_equal(
|
|
323
|
+
asset("tree/all_with_require.js").to_s,
|
|
324
|
+
asset("tree/all_with_require_tree.js").to_s
|
|
325
|
+
)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
test "require_tree without an argument defaults to the current directory" do
|
|
329
|
+
assert_equal(
|
|
330
|
+
"a();\nb();\n",
|
|
331
|
+
asset("tree/without_argument/require_tree_without_argument.js").to_s
|
|
332
|
+
)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
test "require_tree with current directory includes self last" do
|
|
336
|
+
assert_equal(
|
|
337
|
+
"var Bar;\nvar Foo;\nvar App;\n",
|
|
338
|
+
asset("tree/tree/application.js").to_s
|
|
339
|
+
)
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
test "require_tree with a logical path argument raises an exception" do
|
|
343
|
+
assert_raise(Sprockets::ArgumentError) do
|
|
344
|
+
asset("tree/with_logical_path/require_tree_with_logical_path.js").to_s
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
test "require_self inserts the current file's body at the specified point" do
|
|
349
|
+
assert_equal "/* b.css */\n\nb { display: none }\n/*\n */\n.one {}\n\n\nbody {}\n.two {}\n.project {}\n", asset("require_self.css").to_s
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
test "multiple require_self directives raises and error" do
|
|
353
|
+
assert_raise(Sprockets::ArgumentError) do
|
|
354
|
+
asset("require_self_twice.css")
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
test "circular require raises an error" do
|
|
359
|
+
assert_raise(Sprockets::CircularDependencyError) do
|
|
360
|
+
asset("circle/a.js")
|
|
361
|
+
end
|
|
362
|
+
assert_raise(Sprockets::CircularDependencyError) do
|
|
363
|
+
asset("circle/b.js")
|
|
364
|
+
end
|
|
365
|
+
assert_raise(Sprockets::CircularDependencyError) do
|
|
366
|
+
asset("circle/c.js")
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
test "__FILE__ is properly set in templates" do
|
|
371
|
+
assert_equal %(var filename = "#{resolve("filename.js")}";\n),
|
|
372
|
+
asset("filename.js").to_s
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
test "asset inherits the format extension and content type of the original file" do
|
|
376
|
+
asset = asset("project.js")
|
|
377
|
+
assert_equal "application/javascript", asset.content_type
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
if Tilt::CoffeeScriptTemplate.respond_to?(:default_mime_type)
|
|
381
|
+
test "asset falls back to engines default mime type" do
|
|
382
|
+
asset = asset("default_mime_type.js")
|
|
383
|
+
assert_equal "application/javascript", asset.content_type
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
test "asset is a rack response body" do
|
|
388
|
+
body = ""
|
|
389
|
+
asset("project.js").each { |part| body += part }
|
|
390
|
+
assert_equal asset("project.js").to_s, body
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
test "asset length is source length" do
|
|
394
|
+
assert_equal 46, asset("project.js").length
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
test "asset length is source length with unicode characters" do
|
|
398
|
+
assert_equal 8, asset("unicode.js").length
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
test "asset digest" do
|
|
402
|
+
assert asset("project.js").digest
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
test "asset is fresh if its mtime and contents are the same" do
|
|
406
|
+
assert asset("application.js").fresh?
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
test "asset is stale if its environment has changed" do
|
|
410
|
+
asset = asset("application.js")
|
|
411
|
+
assert asset.fresh?
|
|
412
|
+
@env.prepend_path fixture_path("default")
|
|
413
|
+
assert asset.stale?
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
test "asset is stale when its contents has changed" do
|
|
417
|
+
filename = fixture_path('asset/test.js')
|
|
418
|
+
|
|
419
|
+
sandbox filename do
|
|
420
|
+
File.open(filename, 'w') { |f| f.write "a;" }
|
|
421
|
+
asset = @env['test.js']
|
|
422
|
+
|
|
423
|
+
assert asset.fresh?
|
|
424
|
+
|
|
425
|
+
File.open(filename, 'w') { |f| f.write "b;" }
|
|
426
|
+
mtime = Time.now + 1
|
|
427
|
+
File.utime(mtime, mtime, filename)
|
|
428
|
+
|
|
429
|
+
assert asset.stale?
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
test "asset is stale if the file is removed" do
|
|
434
|
+
filename = fixture_path('asset/test.js')
|
|
435
|
+
|
|
436
|
+
sandbox filename do
|
|
437
|
+
File.open(filename, 'w') { |f| f.write "a;" }
|
|
438
|
+
asset = @env['test.js']
|
|
439
|
+
|
|
440
|
+
assert asset.fresh?
|
|
441
|
+
|
|
442
|
+
File.unlink(filename)
|
|
443
|
+
|
|
444
|
+
assert asset.stale?
|
|
445
|
+
end
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
test "asset is stale when one of its source files is modified" do
|
|
449
|
+
main = fixture_path('asset/test-main.js')
|
|
450
|
+
dep = fixture_path('asset/test-dep.js')
|
|
451
|
+
|
|
452
|
+
sandbox main, dep do
|
|
453
|
+
File.open(main, 'w') { |f| f.write "//= require test-dep\n" }
|
|
454
|
+
File.open(dep, 'w') { |f| f.write "a;" }
|
|
455
|
+
asset = @env['test-main.js']
|
|
456
|
+
|
|
457
|
+
assert asset.fresh?
|
|
458
|
+
|
|
459
|
+
File.open(dep, 'w') { |f| f.write "b;" }
|
|
460
|
+
mtime = Time.now + 1
|
|
461
|
+
File.utime(mtime, mtime, dep)
|
|
462
|
+
|
|
463
|
+
assert asset.stale?
|
|
464
|
+
end
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
test "asset if stale if once of its source files is removed" do
|
|
468
|
+
main = fixture_path('asset/test-main.js')
|
|
469
|
+
dep = fixture_path('asset/test-dep.js')
|
|
470
|
+
|
|
471
|
+
sandbox main, dep do
|
|
472
|
+
File.open(main, 'w') { |f| f.write "//= require test-dep\n" }
|
|
473
|
+
File.open(dep, 'w') { |f| f.write "a;" }
|
|
474
|
+
asset = @env['test-main.js']
|
|
475
|
+
|
|
476
|
+
assert asset.fresh?
|
|
477
|
+
|
|
478
|
+
File.unlink(dep)
|
|
479
|
+
|
|
480
|
+
assert asset.stale?
|
|
481
|
+
end
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
test "asset is stale if a file is added to its require directory" do
|
|
485
|
+
asset = asset("tree/all_with_require_directory.js")
|
|
486
|
+
assert asset.fresh?
|
|
487
|
+
|
|
488
|
+
dirname = File.join(fixture_path("asset"), "tree/all")
|
|
489
|
+
filename = File.join(dirname, "z.js")
|
|
490
|
+
|
|
491
|
+
sandbox filename do
|
|
492
|
+
File.open(filename, 'w') { |f| f.write "z" }
|
|
493
|
+
mtime = Time.now + 1
|
|
494
|
+
File.utime(mtime, mtime, dirname)
|
|
495
|
+
|
|
496
|
+
assert asset.stale?
|
|
497
|
+
end
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
test "asset is stale if a file is added to its require tree" do
|
|
501
|
+
asset = asset("tree/all_with_require_tree.js")
|
|
502
|
+
assert asset.fresh?
|
|
503
|
+
|
|
504
|
+
dirname = File.join(fixture_path("asset"), "tree/all/b/c")
|
|
505
|
+
filename = File.join(dirname, "z.js")
|
|
506
|
+
|
|
507
|
+
sandbox filename do
|
|
508
|
+
File.open(filename, 'w') { |f| f.write "z" }
|
|
509
|
+
mtime = Time.now + 1
|
|
510
|
+
File.utime(mtime, mtime, dirname)
|
|
511
|
+
|
|
512
|
+
assert asset.stale?
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
test "asset is stale if its declared dependency changes" do
|
|
517
|
+
sprite = fixture_path('asset/sprite.css.erb')
|
|
518
|
+
image = fixture_path('asset/POW.png')
|
|
519
|
+
|
|
520
|
+
sandbox sprite, image do
|
|
521
|
+
asset = @env['sprite.css']
|
|
522
|
+
|
|
523
|
+
assert asset.fresh?
|
|
524
|
+
|
|
525
|
+
File.open(image, 'w') { |f| f.write "(change)" }
|
|
526
|
+
mtime = Time.now + 1
|
|
527
|
+
File.utime(mtime, mtime, image)
|
|
528
|
+
|
|
529
|
+
assert asset.stale?
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
test "legacy constants.yml" do
|
|
534
|
+
assert_equal "var Prototype = { version: '2.0' };\n",
|
|
535
|
+
asset("constants.js").to_s
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
test "multiple charset defintions are stripped from css bundle" do
|
|
539
|
+
assert_equal "@charset \"UTF-8\";\n.foo {}\n\n.bar {}\n", asset("charset.css").to_s
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
test "appends missing semicolons" do
|
|
543
|
+
assert_equal "var Bar\n;\n\n(function() {\n var Foo\n})\n;\n",
|
|
544
|
+
asset("semicolons.js").to_s
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
test "serializing asset to and from hash" do
|
|
548
|
+
expected = @asset
|
|
549
|
+
hash = {}
|
|
550
|
+
@asset.encode_with(hash)
|
|
551
|
+
actual = @env.asset_from_hash(hash)
|
|
552
|
+
|
|
553
|
+
assert_kind_of Sprockets::BundledAsset, actual
|
|
554
|
+
assert_equal expected.logical_path, actual.logical_path
|
|
555
|
+
assert_equal expected.pathname, actual.pathname
|
|
556
|
+
assert_equal expected.body, actual.body
|
|
557
|
+
assert_equal expected.to_s, actual.to_s
|
|
558
|
+
assert_equal expected.content_type, actual.content_type
|
|
559
|
+
assert_equal expected.length, actual.length
|
|
560
|
+
assert_equal expected.digest, actual.digest
|
|
561
|
+
assert_equal expected.dependencies, actual.dependencies
|
|
562
|
+
assert_equal expected.to_a, actual.to_a
|
|
563
|
+
assert_equal expected.to_s, actual.to_s
|
|
564
|
+
|
|
565
|
+
assert actual.eql?(expected)
|
|
566
|
+
assert expected.eql?(actual)
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
test "should not fail if home is not set in environment" do
|
|
570
|
+
begin
|
|
571
|
+
home, ENV["HOME"] = ENV["HOME"], nil
|
|
572
|
+
assert_nothing_raised do
|
|
573
|
+
env = Sprockets::Environment.new
|
|
574
|
+
env.append_path(fixture_path('asset'))
|
|
575
|
+
env['application.js']
|
|
576
|
+
end
|
|
577
|
+
ensure
|
|
578
|
+
ENV["HOME"] = home
|
|
579
|
+
end
|
|
580
|
+
end
|
|
581
|
+
|
|
582
|
+
def asset(logical_path)
|
|
583
|
+
@env[logical_path]
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
def resolve(logical_path)
|
|
587
|
+
@env.resolve(logical_path)
|
|
588
|
+
end
|
|
589
|
+
|
|
590
|
+
def read(logical_path)
|
|
591
|
+
File.read(resolve(logical_path))
|
|
592
|
+
end
|
|
593
|
+
end
|