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

Add timestamps to the HTML reports #2027

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/hurl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ pub mod tests {
time_in_ms: 0,
success,
cookies: vec![],
timestamp: 1,
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/hurl/src/report/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct HTMLResult {
pub id: String,
pub time_in_ms: u128,
pub success: bool,
pub timestamp: i64,
}

impl HTMLResult {
Expand All @@ -46,6 +47,7 @@ impl HTMLResult {
id: testcase.id.clone(),
time_in_ms: testcase.time_in_ms,
success: testcase.success,
timestamp: testcase.timestamp,
}
}
}
29 changes: 26 additions & 3 deletions packages/hurl/src/report/html/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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>>()
Expand All @@ -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>
"#
Expand Down Expand Up @@ -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>
Expand All @@ -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,
}
]
);
Expand Down
3 changes: 2 additions & 1 deletion packages/hurl/src/report/html/resources/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h2>Report</h2>
<thead>
<td>File</td>
<td>Status</td>
<td>Start Time</td>
<td>Duration</td>
</thead>
<tbody>
Expand All @@ -28,4 +29,4 @@ <h2>Report</h2>
</table>
</div>
</body>
</html>
</html>
2 changes: 2 additions & 0 deletions packages/hurl/src/report/html/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Testcase {
pub success: bool,
pub time_in_ms: u128,
pub errors: Vec<Error>,
pub timestamp: i64,
}

impl Testcase {
Expand All @@ -43,6 +44,7 @@ impl Testcase {
time_in_ms: hurl_result.time_in_ms,
success: hurl_result.success,
errors,
timestamp: hurl_result.timestamp,
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/hurl/src/report/junit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions packages/hurl/src/report/junit/testcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ mod test {
time_in_ms: 230,
success: true,
cookies: vec![],
timestamp: 1,
};

let mut buffer = Vec::new();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/hurl/src/runner/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct HurlResult {
pub time_in_ms: u128,
pub success: bool,
pub cookies: Vec<Cookie>,
pub timestamp: i64,
}

impl HurlResult {
Expand Down
4 changes: 4 additions & 0 deletions packages/hurl/src/runner/hurl_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -230,6 +233,7 @@ pub fn run(
time_in_ms,
success,
cookies,
timestamp,
})
}

Expand Down
Loading