add timestamps to HTML reports

This commit is contained in:
Zac Pitones 2023-10-09 09:25:59 -05:00
parent b31a26f41d
commit f2e4023218
No known key found for this signature in database
GPG Key ID: 63673FF77FF557AC
9 changed files with 44 additions and 4 deletions

View File

@ -346,6 +346,7 @@ pub mod tests {
time_in_ms: 0,
success,
cookies: vec![],
timestamp: 1,
},
}
}

View File

@ -36,6 +36,7 @@ struct HTMLResult {
pub id: String,
pub time_in_ms: u128,
pub success: bool,
pub timestamp: i64,
}
impl HTMLResult {
@ -46,6 +47,7 @@ impl HTMLResult {
id: testcase.id.clone(),
time_in_ms: testcase.time_in_ms,
success: testcase.success,
timestamp: testcase.timestamp,
}
}
}

View File

@ -18,7 +18,7 @@
use std::io::Write;
use std::path::Path;
use chrono::{DateTime, Local};
use chrono::{DateTime, Local, NaiveDateTime};
use crate::report::html::{HTMLResult, Testcase};
use crate::report::Error;
@ -106,6 +106,8 @@ fn parse_html_report(html: &str) -> Vec<HTMLResult> {
data-filename="(?P<filename>[A-Za-z0-9_./-]+)"
\s+
data-id="(?P<id>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})"
(\s+
data-timestamp="(?P<timestamp>[0-9]{1,10})")?
"#,
)
.unwrap();
@ -115,11 +117,18 @@ fn parse_html_report(html: &str) -> Vec<HTMLResult> {
let id = cap["id"].to_string();
let time_in_ms = cap["time_in_ms"].to_string().parse().unwrap();
let success = &cap["status"] == "success";
// Older reports won't have this so make it optional
let timestamp: i64 = cap
.name("timestamp")
.map_or(0, |m| m.as_str().parse().unwrap());
HTMLResult {
filename,
id,
time_in_ms,
success,
timestamp,
}
})
.collect::<Vec<HTMLResult>>()
@ -140,11 +149,22 @@ fn create_html_table_row(result: &HTMLResult) -> String {
filename
};
let id = &result.id;
let timestamp = result.timestamp;
let displayed_time = if timestamp == 0 {
"-".to_string()
} else {
NaiveDateTime::from_timestamp_opt(timestamp, 0)
.unwrap()
.and_local_timezone(Local)
.unwrap()
.to_rfc3339()
};
format!(
r#"<tr class="{status}" data-duration="{duration_in_ms}" data-status="{status}" data-filename="{filename}" data-id="{id}">
r#"<tr class="{status}" data-duration="{duration_in_ms}" data-status="{status}" data-filename="{filename}" data-id="{id}" data-timestamp="{timestamp}">
<td><a href="store/{id}-timeline.html">{displayed_filename}</a></td>
<td>{status}</td>
<td>{displayed_time}</td>
<td>{duration_in_s}</td>
</tr>
"#
@ -179,9 +199,10 @@ mod tests {
<td>success</td>
<td>0.1s</td>
</tr>
<tr class="failure" data-duration="200" data-status="failure" data-filename="tests/failure.hurl" data-id="a6641ae3-8ce0-4d9f-80c5-3e23e032e055">
<tr class="failure" data-duration="200" data-status="failure" data-filename="tests/failure.hurl" data-id="a6641ae3-8ce0-4d9f-80c5-3e23e032e055" data-timestamp="1696473444">
<td><a href="tests/failure.hurl.html">tests/failure.hurl</a></td>
<td>failure</td>
<td>2023-10-05T02:37:24Z</td>
<td>0.2s</td>
</tr>
</tbody>
@ -197,12 +218,14 @@ mod tests {
id: "08aad14a-8d10-4ecc-892e-a72703c5b494".to_string(),
time_in_ms: 100,
success: true,
timestamp: 0,
},
HTMLResult {
filename: "tests/failure.hurl".to_string(),
id: "a6641ae3-8ce0-4d9f-80c5-3e23e032e055".to_string(),
time_in_ms: 200,
success: false,
timestamp: 1696473444,
}
]
);

View File

@ -20,6 +20,7 @@
<thead>
<td>File</td>
<td>Status</td>
<td>Start Time</td>
<td>Duration</td>
</thead>
<tbody>
@ -28,4 +29,4 @@
</table>
</div>
</body>
</html>
</html>

View File

@ -30,6 +30,7 @@ pub struct Testcase {
pub success: bool,
pub time_in_ms: u128,
pub errors: Vec<Error>,
pub timestamp: i64,
}
impl Testcase {
@ -43,6 +44,7 @@ impl Testcase {
time_in_ms: hurl_result.time_in_ms,
success: hurl_result.success,
errors,
timestamp: hurl_result.timestamp,
}
}

View File

@ -161,6 +161,7 @@ mod tests {
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};
let tc = Testcase::from(&res, content, filename);
testcases.push(tc);
@ -184,6 +185,7 @@ mod tests {
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};
let tc = Testcase::from(&res, content, filename);
testcases.push(tc);
@ -208,6 +210,7 @@ mod tests {
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};
let tc = Testcase::from(&res, content, filename);
testcases.push(tc);

View File

@ -121,6 +121,7 @@ mod test {
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};
let mut buffer = Vec::new();
@ -161,6 +162,7 @@ HTTP/1.0 200
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};
let mut buffer = Vec::new();
Testcase::from(&hurl_result, content, filename)
@ -202,6 +204,7 @@ HTTP/1.0 200
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};
let mut buffer = Vec::new();
Testcase::from(&hurl_result, content, filename)

View File

@ -28,6 +28,7 @@ pub struct HurlResult {
pub time_in_ms: u128,
pub success: bool,
pub cookies: Vec<Cookie>,
pub timestamp: i64,
}
impl HurlResult {

View File

@ -19,6 +19,8 @@ use std::collections::HashMap;
use std::thread;
use std::time::Instant;
use chrono::Utc;
use hurl_core::ast::VersionValue::VersionAnyLegacy;
use hurl_core::ast::*;
use hurl_core::error::Error;
@ -101,6 +103,7 @@ pub fn run(
hurl_file.entries.len()
};
let start = Instant::now();
let timestamp = Utc::now().timestamp();
loop {
if entry_index > n {
@ -230,6 +233,7 @@ pub fn run(
time_in_ms,
success,
cookies,
timestamp,
})
}