2021-04-27 14:27:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class DeployJobTest < ActiveSupport::TestCase
|
|
|
|
def site
|
|
|
|
@site ||= create :site
|
|
|
|
end
|
|
|
|
|
|
|
|
# Mockup
|
|
|
|
def job
|
|
|
|
job = BacktraceJob.new
|
|
|
|
job.instance_variable_set :@site, site
|
|
|
|
job.instance_variable_set :@params, notice
|
|
|
|
|
|
|
|
job
|
|
|
|
end
|
|
|
|
|
|
|
|
# setTimeout(() => { throw('Prueba') }, 1000)
|
|
|
|
def notice
|
|
|
|
@notice ||= {
|
2021-05-14 15:53:35 +00:00
|
|
|
'errors' => [
|
2021-04-27 14:27:17 +00:00
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'type' => '',
|
|
|
|
'message' => 'Prueba',
|
|
|
|
'backtrace' => [
|
2021-04-27 14:27:17 +00:00
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'function' => 'pt</e.prototype.notify',
|
|
|
|
'file' => 'https://tintalimon.com.ar/assets/js/pack.js',
|
|
|
|
'line' => 89,
|
|
|
|
'column' => 74_094
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'function' => 'pt</e.prototype.onerror',
|
|
|
|
'file' => 'https://tintalimon.com.ar/assets/js/pack.js',
|
|
|
|
'line' => 89,
|
|
|
|
'column' => 74_731
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'function' => 'pt</e.prototype._instrument/window.onerror',
|
|
|
|
'file' => 'https://tintalimon.com.ar/assets/js/pack.js',
|
|
|
|
'line' => 89,
|
|
|
|
'column' => 71_925
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'function' => 'setTimeout handler*',
|
|
|
|
'file' => 'debugger eval code',
|
|
|
|
'line' => 1,
|
|
|
|
'column' => 11
|
2021-04-27 14:27:17 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2021-05-14 15:53:35 +00:00
|
|
|
'context' => {
|
|
|
|
'severity' => 'error',
|
|
|
|
'history' => [
|
2021-04-27 14:27:17 +00:00
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'type' => 'error',
|
|
|
|
'target' => 'html. > head. > script.[type="text/javascript"][src="//stats.habitapp.org/piwik.js"]',
|
|
|
|
'date' => '2021-04-26T22:06:58.390Z'
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'type' => 'DOMContentLoaded',
|
|
|
|
'target' => '[object HTMLDocument]',
|
|
|
|
'date' => '2021-04-26T22:06:58.510Z'
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'type' => 'load',
|
|
|
|
'target' => '[object HTMLDocument]',
|
|
|
|
'date' => '2021-04-26T22:06:58.845Z'
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'type' => 'xhr',
|
|
|
|
'date' => '2021-04-26T22:06:58.343Z',
|
|
|
|
'method' => 'GET',
|
|
|
|
'url' => 'assets/data/site.json',
|
|
|
|
'statusCode' => 200,
|
|
|
|
'duration' => 506
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2021-05-14 15:53:35 +00:00
|
|
|
'type' => 'xhr',
|
|
|
|
'date' => '2021-04-26T22:06:58.886Z',
|
|
|
|
'method' => 'GET',
|
|
|
|
'url' => 'assets/templates/cart.html',
|
|
|
|
'statusCode' => 200,
|
|
|
|
'duration' => 591
|
2021-04-27 14:27:17 +00:00
|
|
|
}
|
|
|
|
],
|
2021-05-14 15:53:35 +00:00
|
|
|
'windowError' => true,
|
|
|
|
'notifier' => {
|
|
|
|
'name' => 'airbrake-js/browser',
|
|
|
|
'version' => '1.4.2',
|
|
|
|
'url' => 'https://github.com/airbrake/airbrake-js/tree/master/packages/browser'
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
2021-05-14 15:53:35 +00:00
|
|
|
'userAgent' => 'Mozilla/5.0 (Windows NT 6.1; rv:85.0) Gecko/20100101 Firefox/85.0',
|
|
|
|
'url' => 'https://tintalimon.com.ar/carrito/',
|
|
|
|
'rootDirectory' => 'https://tintalimon.com.ar',
|
|
|
|
'language' => 'JavaScript'
|
2021-04-27 14:27:17 +00:00
|
|
|
},
|
2021-05-14 15:53:35 +00:00
|
|
|
'params' => {},
|
|
|
|
'environment' => {},
|
|
|
|
'session' => {}
|
2021-04-27 14:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# XXX: Siempre devolvemos un duplicado porque BacktraceJob lo
|
|
|
|
# modifica
|
|
|
|
@notice.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
# Asegurarse que el sitio se destruye al terminar de usarlo
|
|
|
|
teardown do
|
|
|
|
site&.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'al recibir un backtrace enviamos un error' do
|
|
|
|
ActionMailer::Base.deliveries.clear
|
|
|
|
|
|
|
|
assert BacktraceJob.perform_now site_id: site.id, params: notice
|
|
|
|
|
|
|
|
email = ActionMailer::Base.deliveries.first
|
|
|
|
|
|
|
|
assert email
|
2021-05-14 15:53:35 +00:00
|
|
|
assert_equal ' (BacktraceJob::BacktraceException) "tintalimon.com.ar: Prueba"', email.subject
|
|
|
|
assert(%r{webpack://} =~ email.body.to_s)
|
2021-04-27 14:27:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'los errores se basan en un sitio' do
|
|
|
|
assert_equal site, job.send(:site)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'los errores tienen archivos fuente' do
|
|
|
|
assert_equal %w[https://tintalimon.com.ar/assets/js/pack.js], job.send(:sources)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'los errores tienen una url de origen' do
|
|
|
|
assert_equal 'tintalimon.com.ar', job.send(:origin)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'los errores tienen un sourcemap' do
|
|
|
|
local_job = job
|
|
|
|
sourcemap = local_job.send :sourcemap
|
|
|
|
|
|
|
|
assert_equal SourceMap::Map, sourcemap.class
|
|
|
|
assert_equal 'assets/js/pack.js', sourcemap.filename
|
|
|
|
assert sourcemap.sources.size.positive?
|
|
|
|
end
|
|
|
|
end
|