11require 'test_helper'
22require 'typescript-rails'
33
4+ require "action_controller/railtie"
5+ require "sprockets/railtie"
6+
7+
48class AssetsTest < ActiveSupport ::TestCase
9+ include Minitest ::PowerAssert ::Assertions
10+
511 def setup
6- require "rails"
7- require 'tzinfo'
8- require "action_controller/railtie"
9- require "sprockets/railtie"
12+ FileUtils . mkdir_p tmp_path
1013
1114 @app = Class . new ( Rails ::Application )
1215 @app . config . eager_load = false
1316 @app . config . active_support . deprecation = :stderr
1417 @app . config . assets . enabled = true
1518 @app . config . assets . cache_store = [ :file_store , "#{ tmp_path } /cache" ]
19+ @app . config . assets . paths << "#{ File . dirname ( __FILE__ ) } /fixtures/assets"
1620 @app . paths [ "log" ] = "#{ tmp_path } /log/test.log"
1721 @app . initialize!
1822 end
1923
2024 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
2426 end
2527
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
2831
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
3134 end
3235
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!";' ) }
3544 end
3645end
0 commit comments