-
Notifications
You must be signed in to change notification settings - Fork 791
/
test_coffee_script_processor.rb
54 lines (48 loc) · 1.83 KB
/
test_coffee_script_processor.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
# frozen_string_literal: true
require 'sprockets_test'
require 'minitest/autorun'
require 'sprockets/cache'
require 'sprockets/coffee_script_processor'
require 'sprockets/source_map_utils'
class TestCoffeeScriptProcessor < Minitest::Test
def setup
@env = Sprockets::Environment.new
@env.append_path File.expand_path("../fixtures", __FILE__)
end
def test_compile_coffee_script_template_to_js
input = {
load_path: File.expand_path("../fixtures", __FILE__),
filename: File.expand_path("../fixtures/squared.coffee", __FILE__),
content_type: 'application/javascript',
environment: @env,
data: "square = (n) -> n * n",
name: 'squared',
cache: Sprockets::Cache.new,
metadata: { mapping: [] }
}
result = Sprockets::CoffeeScriptProcessor.call(input)
assert result[:data].match(/var square/)
assert_equal 13, Sprockets::SourceMapUtils.decode_source_map(result[:map])[:mappings].size
assert_equal ["squared.source.coffee"], result[:map]["sources"]
end
def test_changing_map_sources_for_files_with_same_content
input = {
load_path: File.expand_path("../fixtures", __FILE__),
filename: File.expand_path("../fixtures/squared.coffee", __FILE__),
content_type: 'application/javascript',
environment: @env,
data: "square = (n) -> n * n",
name: 'squared',
cache: Sprockets::Cache.new,
metadata: { mapping: [] }
}
result = Sprockets::CoffeeScriptProcessor.call(input)
assert_equal ["squared.source.coffee"], result[:map]["sources"]
input[:filename] = File.expand_path("../fixtures/peterpan.coffee", __FILE__)
result = Sprockets::CoffeeScriptProcessor.call(input)
assert_equal ["peterpan.source.coffee"], result[:map]["sources"]
end
def test_cache_key
assert Sprockets::CoffeeScriptProcessor.cache_key
end
end