1
1
require 'test_helper'
2
2
require 'typescript-rails'
3
3
4
+ require "action_controller/railtie"
5
+ require "sprockets/railtie"
6
+
7
+
4
8
class AssetsTest < ActiveSupport ::TestCase
9
+ include Minitest ::PowerAssert ::Assertions
10
+
5
11
def setup
6
- require "rails"
7
- require 'tzinfo'
8
- require "action_controller/railtie"
9
- require "sprockets/railtie"
12
+ FileUtils . mkdir_p tmp_path
10
13
11
14
@app = Class . new ( Rails ::Application )
12
15
@app . config . eager_load = false
13
16
@app . config . active_support . deprecation = :stderr
14
17
@app . config . assets . enabled = true
15
18
@app . config . assets . cache_store = [ :file_store , "#{ tmp_path } /cache" ]
19
+ @app . config . assets . paths << "#{ File . dirname ( __FILE__ ) } /fixtures/assets"
16
20
@app . paths [ "log" ] = "#{ tmp_path } /log/test.log"
17
21
@app . initialize!
18
22
end
19
23
20
24
def teardown
21
- FileUtils . rm_rf "#{ tmp_path } /cache"
22
- FileUtils . rm_rf "#{ tmp_path } /log"
23
- #File.delete "#{tmp_path}/typescript.js"
25
+ FileUtils . rm_rf tmp_path
24
26
end
25
27
26
- test "typescript.js is included in Sprockets environment" do
27
- @app . assets [ "typescript" ] . write_to ( "#{ tmp_path } /typescript.js" )
28
+ def tmp_path
29
+ "#{ File . dirname ( __FILE__ ) } /tmp"
30
+ end
28
31
29
- assert_match "/lib/ assets/javascripts/typescript.js.erb" , @app . assets [ "typescript" ] . pathname . to_s
30
- assert_match "var TypeScript" , File . open ( " #{ tmp_path } /typescript.js" ) . read
32
+ def assets
33
+ @app . assets
31
34
end
32
35
33
- def tmp_path
34
- "#{ File . dirname ( __FILE__ ) } /tmp"
36
+ test "typescript.js is included in Sprockets environment" do
37
+ assert { assets [ "typescript" ] . pathname . to_s . end_with? ( '/lib/assets/javascripts/typescript.js.erb' ) }
38
+ assert { assets [ "typescript" ] . body . include? ( 'var TypeScript' ) }
39
+ end
40
+
41
+ test "assets .js.ts is compiled from TypeScript to JavaScript" do
42
+ assert { assets [ "javascripts/hello" ] . present? }
43
+ assert { assets [ "javascripts/hello" ] . body . include? ( 'var s = "Hello, world!";' ) }
35
44
end
36
45
end
0 commit comments