From a90b15b928947aa7090f2b09853b987e3c8a8c3d Mon Sep 17 00:00:00 2001 From: Faris Mustafa Date: Sun, 17 Sep 2023 12:35:18 -0700 Subject: [PATCH] Update test runner to serve assets (#659) --- src/test_runner.cr | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test_runner.cr b/src/test_runner.cr index 83355feca..1634ba591 100644 --- a/src/test_runner.cr +++ b/src/test_runner.cr @@ -29,6 +29,7 @@ module Mint error InvalidBrowser error InvalidReporter + @artifacts : TypeChecker::Artifacts? @reporter : Reporter @browser_path : String? @script : String? @@ -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 @@ -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