File: tilt_typescript_test.rb

package info (click to toggle)
ruby-tilt 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: ruby: 4,998; makefile: 7
file content (38 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (2)
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
require_relative 'test_helper'

checked_describe 'tilt/typescript' do
  before do
    @ts = "var x:number = 5"
    @js = 'var x = 5;'
  end

  it "is registered for '.ts' files" do
    assert_equal Tilt::TypeScriptTemplate, Tilt['test.ts']
  end

  it "is registered for '.tsx' files" do
    assert_equal Tilt::TypeScriptTemplate, Tilt['test.tsx']
  end

  it "compiles and evaluates the template on #render" do
    template = Tilt::TypeScriptTemplate.new { @ts }
    3.times { assert_includes template.render, @js }
  end

  it "supports source map" do
    template = Tilt::TypeScriptTemplate.new(inlineSourceMap: true)  { @ts }
    assert_includes template.render, 'sourceMappingURL'
  end

  it "skips options with nil value" do
    template = Tilt::TypeScriptTemplate.new(completely_bogus_option: nil) { @ts }
    assert_includes template.render, @js
  end

  it "supports options with string values" do
    template = Tilt::TypeScriptTemplate.new(target: 'ES5') { '() => this' }
    assert_includes template.render, 'function () { return _this; }'
    template = Tilt::TypeScriptTemplate.new(target: 'ES6') { '() => this' }
    assert_includes template.render, '() => this'
  end
end