Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test runner to serve assets #659

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
serve assets in the test runner
  • Loading branch information
farism committed Sep 13, 2023
commit b8f146fc7a9b141ac05b5512975445560b0050f6
22 changes: 22 additions & 0 deletions src/test_runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Mint
error InvalidBrowser
error InvalidReporter

@artifacts : TypeChecker::Artifacts?
@reporter : Reporter
@browser_path : String?
@script : String?
Expand Down Expand Up @@ -102,6 +103,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 @@ -218,6 +221,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