-
Notifications
You must be signed in to change notification settings - Fork 792
/
Copy pathtest_path_dependency_utils.rb
74 lines (63 loc) · 3.13 KB
/
test_path_dependency_utils.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
# frozen_string_literal: true
require 'minitest/autorun'
require 'sprockets/path_dependency_utils'
class TestPathDependencyUtils < Minitest::Test
include Sprockets::PathDependencyUtils
def test_entries_with_dependencies
path = File.expand_path("../fixtures", __FILE__)
filenames, deps = entries_with_dependencies(path)
assert_kind_of Array, filenames
assert filenames.size > 1
assert_equal [build_file_digest_uri(path)], deps.to_a
path = "/tmp/sprockets/missingdir"
filenames, deps = entries_with_dependencies(path)
assert_kind_of Array, filenames
assert filenames.empty?
assert_equal [build_file_digest_uri(path)], deps.to_a
end
FILES_IN_SERVER = Dir["#{File.expand_path("../fixtures/server", __FILE__)}/*"]
def test_stat_directory_with_dependencies
dirname = File.expand_path("../fixtures/server", __FILE__)
filenames, deps = stat_directory_with_dependencies(dirname)
assert_equal FILES_IN_SERVER.size, filenames.size
assert_equal [build_file_digest_uri(dirname)], deps.to_a
path, stat = filenames.first
assert_equal File.expand_path("../fixtures/server/app", __FILE__), path
assert_kind_of File::Stat, stat
dirname = File.expand_path("../fixtures/missing", __FILE__)
filenames, deps = stat_directory_with_dependencies(dirname)
assert_equal [], filenames
assert_equal [build_file_digest_uri(dirname)], deps.to_a
end
def test_stat_sorted_tree_with_dependencies
dirname = File.expand_path("../fixtures/asset/tree/all", __FILE__)
filenames, deps = stat_sorted_tree_with_dependencies(dirname)
assert_equal 11, filenames.size
assert_equal [
File.expand_path("../fixtures/asset/tree/all", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b/c", __FILE__),
File.expand_path("../fixtures/asset/tree/all/d", __FILE__)
].map { |p| build_file_digest_uri(p) }, deps.to_a
path, stat = filenames.first
assert_equal File.expand_path("../fixtures/asset/tree/all/README.md", __FILE__), path
assert_kind_of File::Stat, stat
assert_equal [
File.expand_path("../fixtures/asset/tree/all/README.md", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b.css", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b.js.erb", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b/c.js", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b/c", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b/c/d.js", __FILE__),
File.expand_path("../fixtures/asset/tree/all/b/c/e.js", __FILE__),
File.expand_path("../fixtures/asset/tree/all/d", __FILE__),
File.expand_path("../fixtures/asset/tree/all/d/c.coffee", __FILE__),
File.expand_path("../fixtures/asset/tree/all/d/e.js", __FILE__),
], filenames.map(&:first)
dirname = File.expand_path("../fixtures/missing", __FILE__)
filenames, deps = stat_sorted_tree_with_dependencies(dirname)
assert_equal [], filenames
assert_equal [build_file_digest_uri(dirname)], deps.to_a
end
end