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
|
# frozen_string_literal: true
require 'sprockets_test'
require 'rake/sprocketstask'
require 'rake'
class TestRakeTask < Sprockets::TestCase
def setup
@rake = Rake::Application.new
Rake.application = @rake
@env = Sprockets::Environment.new(".") do |env|
env.append_path(fixture_path('default'))
end
@dir = Dir.mktmpdir
FileUtils.mkdir_p(@dir)
@manifest_custom_dir = Sprockets::Manifest.new(@env, @dir)
@manifest_custom_path = Sprockets::Manifest.new(@env, @dir, File.join(@dir, 'manifest.json'))
Rake::SprocketsTask.new do |t|
t.environment = @env
t.output = @dir
t.assets = ['application.js']
t.log_level = :fatal
end
end
def teardown
Rake.application = nil
FileUtils.remove_entry_secure(@dir) if File.exist?(@dir)
assert Dir["#{@dir}/*"].empty?
end
test "assets" do
skip "coffee-script is not available"
digest_path = @env['application.js'].digest_path
assert !File.exist?("#{@dir}/#{digest_path}")
@rake[:assets].invoke
assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
test "clobber" do
skip "coffee-script is not available"
digest_path = @env['application.js'].digest_path
@rake[:assets].invoke
assert File.exist?("#{@dir}/#{digest_path}")
# set a cache key
result = @env.cache.set('foo', 'bar')
assert_equal result, @env.cache.get('foo')
@rake[:clobber_assets].invoke
assert !File.exist?("#{@dir}/#{digest_path}")
# verify the cache key was cleared
assert_nil @env.cache.get('foo')
end
test "clean" do
digest_path = @env['application.js'].digest_path
filename = fixture_path('default/application.coffee')
sandbox filename do
@rake[:assets].invoke
assert File.exist?("#{@dir}/#{digest_path}")
File.open(filename, 'w') { |f| f.write "change;" }
changed_digest_path = @env['application.js'].digest_path
@rake[:assets].invoke
@rake[:clean_assets].invoke(1, 0)
assert File.exist?("#{@dir}/#{digest_path}")
refute File.exist?("#{@dir}/#{changed_digest_path}")
end
end
test "custom manifest directory" do
skip "coffee-script is not available"
Rake::SprocketsTask.new do |t|
t.environment = nil
t.manifest = @manifest_custom_dir
t.assets = ['application.js']
t.log_level = :fatal
end
digest_path = @env['application.js'].digest_path
assert !File.exist?("#{@dir}/#{digest_path}")
@rake[:assets].invoke
assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
test "custom manifest path" do
Rake::SprocketsTask.new do |t|
t.environment = nil
t.manifest = @manifest_custom_path
t.assets = ['application.js']
t.log_level = :fatal
end
digest_path = @env['application.js'].digest_path
assert !File.exist?("#{@dir}/#{digest_path}")
@rake[:assets].invoke
assert Dir["#{@dir}/manifest.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
test "lazy custom manifest" do
skip "coffee-script is not available"
Rake::SprocketsTask.new do |t|
t.environment = nil
t.manifest = lambda { @manifest_custom_dir }
t.assets = ['application.js']
t.log_level = :fatal
end
digest_path = @env['application.js'].digest_path
assert !File.exist?("#{@dir}/#{digest_path}")
@rake[:assets].invoke
assert Dir["#{@dir}/.sprockets-manifest-*.json"].first
assert File.exist?("#{@dir}/#{digest_path}")
end
end
|