Skip to content

Commit

Permalink
Compile tests on the request instead of caching it.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdotdesign committed Sep 19, 2023
1 parent f933036 commit 0860274
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
25 changes: 8 additions & 17 deletions src/test_runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Mint
@artifacts : TypeChecker::Artifacts?
@reporter : Reporter
@browser_path : String?
@script : String?
@browser : {Process, String}? = nil

@failed = [] of Message
Expand All @@ -51,21 +50,13 @@ module Mint

def watch
workspace = Workspace.current
workspace.on "change" { |result| run_tests }
workspace.on "change" { run_tests }
workspace.watch

setup_kemal
run_tests

Server.run "Test", @flags.host, @flags.port
end

def compile
terminal.measure "#{COG} Compiling tests..." do
compile_ast.tap do |a|
@script = compile_script(a)
end
end
Server.run "Test", @flags.host, @flags.port, false
end

def run_tests
Expand All @@ -74,8 +65,10 @@ module Mint
terminal.reset

begin
type_checker = TypeChecker.new(ast)
type_checker.check

@reporter.reset
compile
open_page
rescue error : Error
terminal.reset
Expand All @@ -87,8 +80,6 @@ module Mint
end

def run : Bool
ast = compile

if ast.try(&.suites.empty?)
terminal.puts
terminal.puts "There are no tests to run!"
Expand All @@ -108,7 +99,7 @@ module Mint
@failed.empty?
end

def compile_ast
def ast
file_argument =
@arguments.test

Expand All @@ -130,7 +121,7 @@ module Mint
end
end

def compile_script(ast)
def script
type_checker = TypeChecker.new(ast)
type_checker.check

Expand Down Expand Up @@ -293,7 +284,7 @@ module Mint
end

get "/tests" do
@script
script
end

ws "/" do |socket|
Expand Down
4 changes: 2 additions & 2 deletions src/utils/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ module Mint
true
end

def run(name, host = "127.0.0.1", port = 3000)
def run(name, host = "127.0.0.1", port = 3000, verbose = true)
config = Kemal.config
config.logging = false
config.setup

if port_open?(host, port)
server = HTTP::Server.new(config.handlers)
terminal.puts "#{COG} #{name} server started on http://#{host}:#{port}/"
terminal.puts "#{COG} #{name} server started on http://#{host}:#{port}/" if verbose
elsif STDIN.tty?
new_port = config.port + 1
until port_open?(host, new_port)
Expand Down

0 comments on commit 0860274

Please sign in to comment.