Skip to content

Commit

Permalink
Update test runner to serve assets (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
farism authored Sep 17, 2023
1 parent 168ce02 commit a90b15b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/test_runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Mint
error InvalidBrowser
error InvalidReporter

@artifacts : TypeChecker::Artifacts?
@reporter : Reporter
@browser_path : String?
@script : String?
Expand Down Expand Up @@ -103,6 +104,8 @@ module Mint
type_checker = TypeChecker.new(ast)
type_checker.check

@artifacts = type_checker.artifacts

Compiler.compile_with_tests(type_checker.artifacts)
end

Expand Down Expand Up @@ -219,6 +222,25 @@ module Mint
SourceFiles.external_stylesheets
end

get "/#{ASSET_DIR}/:name" do |env|
filename =
env.params.url["name"]

asset =
@artifacts.try(&.assets.find(&.filename(build: false).==(filename)))

next unless asset

# Set cache to expire in 30 days.
env.response.headers["Cache-Control"] = "max-age=2592000"

# Try to figure out mime type from name.
env.response.content_type =
MIME.from_filename?(filename).to_s

asset.file_contents
end

get "/runtime.js" do
runtime
end
Expand Down

0 comments on commit a90b15b

Please sign in to comment.