From fa5c12feffa37a87ee173bb6632fef98068244c8 Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Tue, 16 Jul 2024 14:55:06 -0700 Subject: [PATCH 1/2] Add test coverage measuring This adds excoveralls (which is the state of the art coverage tool) and a `mix spec` command which will run the whole suite with an HTML export of coverage. Closes #37 --- config/test.exs | 1 + coveralls.json | 6 ++++++ mix.exs | 17 ++++++++++++++--- mix.lock | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 coveralls.json diff --git a/config/test.exs b/config/test.exs index 4de769f8..3da5bf15 100644 --- a/config/test.exs +++ b/config/test.exs @@ -9,6 +9,7 @@ config :dpul_collections, DpulCollections.Repo, username: "postgres", password: "postgres", hostname: "localhost", + port: 5434, database: "dpul_collections_test#{System.get_env("MIX_TEST_PARTITION")}", pool: Ecto.Adapters.SQL.Sandbox, pool_size: System.schedulers_online() * 2 diff --git a/coveralls.json b/coveralls.json new file mode 100644 index 00000000..806d0c01 --- /dev/null +++ b/coveralls.json @@ -0,0 +1,6 @@ +{ + "coverage_options": { + "minimum_coverage": 100, + "floor_coverage": true + } +} diff --git a/mix.exs b/mix.exs index 08286ef8..11bf5dcb 100644 --- a/mix.exs +++ b/mix.exs @@ -9,7 +9,16 @@ defmodule DpulCollections.MixProject do elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, aliases: aliases(), - deps: deps() + deps: deps(), + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + coveralls: :test, + "coveralls.detail": :test, + "coveralls.post": :test, + "coveralls.html": :test, + "coveralls.cobertura": :test, + spec: :test + ] ] end @@ -57,7 +66,8 @@ defmodule DpulCollections.MixProject do {:gettext, "~> 0.20"}, {:jason, "~> 1.2"}, {:dns_cluster, "~> 0.1.1"}, - {:bandit, "~> 1.2"} + {:bandit, "~> 1.2"}, + {:excoveralls, "~> 0.18", only: :test} ] end @@ -79,7 +89,8 @@ defmodule DpulCollections.MixProject do "tailwind dpul_collections --minify", "esbuild dpul_collections --minify", "phx.digest" - ] + ], + spec: ["coveralls.html"] ] end end diff --git a/mix.lock b/mix.lock index 75f2d292..e0fbf8d1 100644 --- a/mix.lock +++ b/mix.lock @@ -7,6 +7,7 @@ "ecto": {:hex, :ecto, "3.11.2", "e1d26be989db350a633667c5cda9c3d115ae779b66da567c68c80cfb26a8c9ee", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c38bca2c6f8d8023f2145326cc8a80100c3ffe4dcbd9842ff867f7fc6156c65"}, "ecto_sql": {:hex, :ecto_sql, "3.11.2", "c7cc7f812af571e50b80294dc2e535821b3b795ce8008d07aa5f336591a185a8", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "73c07f995ac17dbf89d3cfaaf688fcefabcd18b7b004ac63b0dc4ef39499ed6b"}, "esbuild": {:hex, :esbuild, "0.8.1", "0cbf919f0eccb136d2eeef0df49c4acf55336de864e63594adcea3814f3edf41", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "25fc876a67c13cb0a776e7b5d7974851556baeda2085296c14ab48555ea7560f"}, + "excoveralls": {:hex, :excoveralls, "0.18.1", "a6f547570c6b24ec13f122a5634833a063aec49218f6fff27de9df693a15588c", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "d65f79db146bb20399f23046015974de0079668b9abb2f5aac074d078da60b8d"}, "expo": {:hex, :expo, "0.5.2", "beba786aab8e3c5431813d7a44b828e7b922bfa431d6bfbada0904535342efe2", [:mix], [], "hexpm", "8c9bfa06ca017c9cb4020fabe980bc7fdb1aaec059fd004c2ab3bff03b1c599c"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "finch": {:hex, :finch, "0.18.0", "944ac7d34d0bd2ac8998f79f7a811b21d87d911e77a786bc5810adb75632ada4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "69f5045b042e531e53edc2574f15e25e735b522c37e2ddb766e15b979e03aa65"}, From 61c75ae8ef6c623e44991ae9c2ce9c5cb50ae0c2 Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Wed, 17 Jul 2024 14:11:14 -0700 Subject: [PATCH 2/2] Add README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index db46567d..19296c61 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,12 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html). +## Running Tests + +`mix spec` + +This will run all your tests and store your coverage data in `./cover`. + ## Build & Run Production Docker Image Locally Build Docker Image: `docker build . -t dpul-collections`