Skip to content

Commit

Permalink
Time how long it takes to collect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdeviant committed Apr 21, 2024
1 parent 91a76a6 commit 2d6005a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/startest/internal/runner/core.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import startest/test_tree
pub fn run_tests(tests: List(TestFile), ctx: Context) {
let started_at = birl.utc_now()

let total_collect_duration =
tests
|> list.fold(duration.micro_seconds(0), fn(acc, test_file) {
duration.add(acc, test_file.collect_duration)
})

let tests =
tests
|> list.flat_map(fn(test_file) {
Expand Down Expand Up @@ -87,6 +93,13 @@ pub fn run_tests(tests: List(TestFile), ctx: Context) {
birl.utc_now()
|> birl.difference(started_at)

logger.log(
ctx.logger,
"Collected "
<> int.to_string(test_count)
<> " tests in "
<> duration_to_string(total_collect_duration),
)
logger.log(
ctx.logger,
"Ran "
Expand Down
14 changes: 13 additions & 1 deletion src/startest/locator.gleam
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import birl
import birl/duration.{type Duration}
import gleam/dynamic.{type Dynamic}
import gleam/list
import gleam/regex
Expand All @@ -18,6 +20,8 @@ pub type TestFile {
filepath: String,
/// The list of tests in the file.
tests: List(TestTree),
/// The time it took to collect the tests in the file.
collect_duration: Duration,
)
}

Expand Down Expand Up @@ -90,6 +94,8 @@ fn identify_tests_in_file(
test_file: TestSourceFile,
ctx: Context,
) -> Result(TestFile, Nil) {
let started_at = birl.utc_now()

let #(standalone_tests, test_functions) =
test_file.tests
|> list.partition(is_standalone_test(_, ctx))
Expand Down Expand Up @@ -122,12 +128,18 @@ fn identify_tests_in_file(

case tests {
[] -> Error(Nil)
tests ->
tests -> {
let collect_duration =
birl.utc_now()
|> birl.difference(started_at)

Ok(TestFile(
module_name: test_file.module_name,
filepath: test_file.filepath,
tests: tests,
collect_duration: collect_duration,
))
}
}
}

Expand Down

0 comments on commit 2d6005a

Please sign in to comment.