tracing_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require 'spec_helper'
  2. require 'tmpdir'
  3. RSpec.describe 'Tracing', skip: Puppeteer.env.firefox? do
  4. let(:output_file) { "trace-#{SecureRandom.hex(8)}.json" }
  5. after do
  6. File.delete(output_file) if File.exist?(output_file)
  7. end
  8. it 'should output a trace', sinatra: true do
  9. page.tracing.start(screenshots: true, path: output_file)
  10. page.goto("#{server_prefix}/grid.html")
  11. page.tracing.stop
  12. expect(File.exist?(output_file)).to eq(true)
  13. end
  14. it 'should run with custom categories if provided' do
  15. page.tracing.start(
  16. path: output_file,
  17. categories: ['-*', 'disabled-by-default-v8.cpu_profiler.hires'],
  18. )
  19. page.tracing.stop
  20. trace_json = JSON.parse(File.read(output_file))
  21. trace_config = JSON.parse(trace_json.dig('metadata', 'trace-config'))
  22. expect(trace_config['included_categories']).to eq(['disabled-by-default-v8.cpu_profiler.hires'])
  23. expect(trace_config['excluded_categories']).to eq(['*'])
  24. end
  25. it 'should throw if tracing on two pages' do
  26. page.tracing.start(path: output_file)
  27. new_page = page.browser.new_page
  28. expect { new_page.tracing.start(path: output_file) }.to raise_error(/Tracing has already been started/)
  29. end
  30. it 'should return a buffer', sinatra: true do
  31. page.tracing.start(screenshots: true, path: output_file)
  32. page.goto("#{server_prefix}/grid.html")
  33. trace = page.tracing.stop
  34. expect(trace).to eq(File.read(output_file))
  35. end
  36. it 'should work without options', sinatra: true do
  37. page.tracing.start
  38. page.goto("#{server_prefix}/grid.html")
  39. trace = page.tracing.stop
  40. expect(trace.length).to be > 1000
  41. end
  42. it 'should support a buffer without a path', sinatra: true do
  43. page.tracing.start(screenshots: true)
  44. page.goto("#{server_prefix}/grid.html")
  45. trace = page.tracing.stop
  46. expect(trace).to include('screenshot')
  47. end
  48. it 'should properly fail if readProtocolStream errors out' do
  49. page.tracing.start(path: File.expand_path(__dir__))
  50. expect { page.tracing.stop }.to raise_error(/Is a directory/)
  51. end
  52. end