diff --git a/lib/OSnap_Config/OSnap_Config_Global.ml b/lib/OSnap_Config/OSnap_Config_Global.ml index 9564db4..40ae28e 100644 --- a/lib/OSnap_Config/OSnap_Config_Global.ml +++ b/lib/OSnap_Config/OSnap_Config_Global.ml @@ -37,7 +37,7 @@ module YAML = struct |> OSnap_Config_Utils.YAML.get_list_option ~path "defaultSizes" - ~parser:(OSnap_Config_Utils.YAML.parse_size ~path) + ~parser:(OSnap_Config_Utils.YAML.parse_global_size ~path) |> Result.map (Option.value ~default:[]) in let* functions = diff --git a/lib/OSnap_Config/OSnap_Config_Test.ml b/lib/OSnap_Config/OSnap_Config_Test.ml index 8b1c9e8..4ce19ca 100644 --- a/lib/OSnap_Config/OSnap_Config_Test.ml +++ b/lib/OSnap_Config/OSnap_Config_Test.ml @@ -74,7 +74,10 @@ module YAML = struct |> OSnap_Config_Utils.YAML.get_list_option ~path "sizes" - ~parser:(OSnap_Config_Utils.YAML.parse_size ~path) + ~parser: + (OSnap_Config_Utils.YAML.parse_size + ~default_sizes:global_config.default_sizes + ~path) |> Result.map (Option.value ~default:global_config.default_sizes) in let* actions = diff --git a/lib/OSnap_Config/OSnap_Config_Utils.ml b/lib/OSnap_Config/OSnap_Config_Utils.ml index 4cdf699..df5ff19 100644 --- a/lib/OSnap_Config/OSnap_Config_Utils.ml +++ b/lib/OSnap_Config/OSnap_Config_Utils.ml @@ -237,13 +237,36 @@ module YAML = struct `OSnap_Config_Parse_Error (message, path)) ;; - let parse_size ~path size = + let parse_global_size ~path size = let* name = size |> get_string_option ~path "name" in let* height = size |> get_int ~path "height" in let* width = size |> get_int ~path "width" in OSnap_Config_Types.{ name; width; height } |> Result.ok ;; + let parse_size ~path ~default_sizes size = + match size with + | `String name -> + let global_size = + default_sizes + |> List.find_opt (fun (size : OSnap_Config_Types.size) -> + match size.OSnap_Config_Types.name with + | None -> false + | Some global_name -> global_name = name) + in + (match global_size with + | Some size -> Result.ok size + | None -> + Result.error + (`OSnap_Config_Parse_Error + (Printf.sprintf "No size with the name %S was found." name, path))) + | size -> + let* name = size |> get_string_option ~path "name" in + let* height = size |> get_int ~path "height" in + let* width = size |> get_int ~path "width" in + Result.ok OSnap_Config_Types.{ name; width; height } + ;; + let parse_action ~global_fns ~path a = let* size_restriction = a |> get_string_list_option ~path "@" in let* action = a |> get_string ~path "action" in diff --git a/website/docs/Setup/configuration.md b/website/docs/Setup/configuration.md index 80492d2..77e936b 100644 --- a/website/docs/Setup/configuration.md +++ b/website/docs/Setup/configuration.md @@ -37,7 +37,7 @@ The base url used for all of your tests. This gets prepended to all your test ur An array of default sizes to run your tests in. If fullScreen is set to true, the height is the minimum height of the snapshot. -You may specify an optional `name` for each size. This is useful for running actions or ignore regions only on some screen sizes. +You may specify an optional `name` for each size. This is useful for running actions, ignore regions or whole tests only on some screen sizes. --- diff --git a/website/docs/Tests/configuration.md b/website/docs/Tests/configuration.md index 2fbc718..4a0a67f 100644 --- a/website/docs/Tests/configuration.md +++ b/website/docs/Tests/configuration.md @@ -80,6 +80,19 @@ The number of times a failed test should be retried before it is reported as fai --- +### Sizes + +- **Key**: `sizes` +- **Required**: `false` +- **Type**: `Array<{name: string?, width: int, height: int} | string>` + +An array of sizes to run your test in. If fullScreen is set to true, the height is the minimum height of the snapshot. +The size can be a newly defined size or the name of an existing default size from the global config file. + +You may specify an optional `name` for each size. This is useful for running actions or ignore regions only on some screen sizes. + +--- + ### Ignore Regions - **Key**: `ignore` @@ -128,9 +141,7 @@ The smallest possible test file would look like this: threshold: 20 sizes: - - name: xl - width: 1600 - height: 768 + - xl - name: xs width: 768 height: 1024