-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathsourcemap_spec.rb
84 lines (76 loc) · 2.06 KB
/
sourcemap_spec.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
75
76
77
78
79
80
81
82
83
84
gem 'minitest'
require 'minitest/autorun'
require 'ruby2js/filter/functions'
require 'ruby2js/filter/node'
require 'ruby2js/filter/require'
describe "sourcemap" do
def to_sm(string, *filters)
_(Ruby2JS.convert(string, filters: filters, file: __FILE__).sourcemap)
end
it "should handle null input" do
to_sm("").
must_equal(
version: 3,
file: __FILE__,
sources: [],
names: [],
mappings: ""
)
end
describe "simple filters" do
it "should work without filters" do
to_sm("x = 123; puts x").
must_equal(
version: 3,
file: __FILE__,
sources: [__FILE__],
names: ["x"],
mappings: "AAAAA,QAAI,GAAJ,EAAS,KAAKA,CAAL"
)
end
it "should produce different results with a filter" do
to_sm("x = 123; puts x", Ruby2JS::Filter::Functions).
must_equal(
version: 3,
file: __FILE__,
sources: [__FILE__],
names: ["x"],
mappings: "AAAAA,QAAI,GAAJ,SAAS,KAAKA,CAAL"
)
end
end
describe "prepended imports" do
it "should work without filters" do
to_sm("system 'echo hi'\n").
must_equal(
version: 3,
file: __FILE__,
sources: [__FILE__],
names: [],
mappings: "AAAA,OAAO,SAAP"
)
end
it "should work with a filter that inserts import statements" do
to_sm("system 'echo hi'\n", Ruby2JS::Filter::Node).
must_equal(
version: 3,
file: __FILE__,
sources: [__FILE__],
names: [],
mappings: ";aAAA,UAAO,SAAP"
)
end
end
it "should handle requires" do
dir = File.join(__dir__, 'require')
sources = [File.join(dir, "test2.rb"), File.join(dir, "test1.rb"), File.join(dir, "test3.js.rb")]
to_sm('require "require/test1.rb"', Ruby2JS::Filter::Require).
must_equal(
version: 3,
file: __FILE__,
sources: sources,
names: ['console'],
mappings: "AAAAA,YAAY,OAAZ,eEAY,OAAZ"
)
end
end