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

Refactor the flush method #6

Merged
merged 1 commit into from
Nov 10, 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
22 changes: 14 additions & 8 deletions lib/magic_test/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ def flush
chunks = contents.each_slice(line.to_i - 1 + @test_lines_written).to_a
indentation = chunks[1].first.match(/^(\s*)/)[0]
output = page.evaluate_script("JSON.parse(sessionStorage.getItem('testingOutput'))")
puts
puts "javascript recorded on the front-end looks like this:"
puts output
puts
puts "(writing that to `#{filepath}`.)"
if output

if output.any?
puts
puts "JavaScript recorded on the front-end looks like this:"
puts output
puts
puts "(writing that to `#{filepath}`.)"

output.each do |last|
chunks.first << indentation + "#{last["action"]} #{last["target"]}#{last["options"]}" + "\n"
@test_lines_written += 1
Expand All @@ -42,12 +44,16 @@ def flush
File.open(filepath, "w") do |file|
file.puts(contents)
end

# clear the testing output now.
empty_cache
true
else
puts "`window.testingOutput` was empty in the browser. Something must be wrong on the browser side."
puts
puts "No Javascript was recorded, please try again."
puts
false
end
true
end

def ok
Expand Down