Skip to content

Commit

Permalink
Add mocking setup
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Dec 11, 2023
1 parent 9a4a116 commit 169b02f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/lightning_css.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ defmodule LightningCSS do
require Logger

def start(_, _) do
unless Application.get_env(:lightning_css, :version) do
unless LightningCSS.Versions.configured() do
Logger.warning("""
lightning_css version is not configured. Please set it in your config files:
config :lightning_css, :version, "#{LightningCSS.Versions.latest()}"
""")
end

configured_version = LightningCSS.Versions.configured()
configured_version = LightningCSS.Versions.to_use()

case LightningCSS.Versions.bin() do
{:ok, ^configured_version} ->
Expand Down
2 changes: 1 addition & 1 deletion lib/lightning_css/installer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule LightningCSS.Installer do
Installs lightning_css with `configured_version/0`.
"""
def install do
version = LightningCSS.Versions.configured()
version = LightningCSS.Versions.to_use()
tmp_opts = if System.get_env("MIX_XDG"), do: %{os: :linux}, else: %{}
target = LightningCSS.Architectures.target()

Expand Down
12 changes: 10 additions & 2 deletions lib/lightning_css/versions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ defmodule LightningCSS.Versions do
@doc """
Returns the version of Lightning CSS that this package should use.
"""
@spec configured() :: String.t()
@spec configured() :: String.t() | nil
def configured do
Application.get_env(:lightning_css, :version, latest())
Application.get_env(:lightning_css, :version)
end

@doc """
Returns the configured version falling back to the latest if there's no version configured.
"""
@spec to_use() :: String.t()
def to_use do
configured() || latest()
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/lightning_css.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule Mix.Tasks.LightningCss.Install do
end

defp latest_version?() do
version = LightningCSS.Versions.configured()
version = LightningCSS.Versions.to_use()
match?({:ok, ^version}, LightningCSS.Versions.bin())
end
end
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ defmodule LightningCSS.MixProject do
{:modulex, "~> 0.7.0", runtime: false},
{:boundary, "~> 0.10", runtime: false},
{:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:mimic, "~> 1.7", only: :test}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"mimic": {:hex, :mimic, "1.7.4", "cd2772ffbc9edefe964bc668bfd4059487fa639a5b7f1cbdf4fd22946505aa4f", [:mix], [], "hexpm", "437c61041ecf8a7fae35763ce89859e4973bb0666e6ce76d75efc789204447c3"},
"modulex": {:hex, :modulex, "0.7.0", "f25dfb787f432a936815fe6b824fc85c008d83278554a58fb3825c2e85333b0d", [:mix], [{:boundary, "~> 0.10", [hex: :boundary, repo: "hexpm", optional: false]}], "hexpm", "34033198548fd01b82575d3caaa9f6bf56edc54228a6ecb86898fdcf26175e68"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
}
9 changes: 9 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
Application.ensure_all_started(:lightning_css)

Mimic.copy(LightningCSS.Architectures)
Mimic.copy(LightningCSS.Configuration)
Mimic.copy(LightningCSS.Installer)
Mimic.copy(LightningCSS.Paths)
Mimic.copy(LightningCSS.Runner)
Mimic.copy(LightningCSS.Versions)

ExUnit.start()

0 comments on commit 169b02f

Please sign in to comment.