Skip to content

Commit

Permalink
fix: Remove test app from mod (#78)
Browse files Browse the repository at this point in the history
resolves #77 

The `Test.Application` is causing apps that included this library to
crash on boot, because it's not compiled as part of the release.

Remove it so it no longer attempts to boot with
`Inngest.Test.Application`.
`v0.2.0` is essentially useless at this point, so it should be yanked
once this fix is out.

Update with some minor changes to make it comply to the latest spec.

---------

Co-authored-by: Darwin D Wu <[email protected]>
  • Loading branch information
darwin67 and darwin67 authored May 15, 2024
1 parent 5785538 commit 5f3579a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 9 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## [0.2.1] - 2024-05-15

### Bug Fixes

- Fix: remove test application from mod

### Miscellaneous Tasks

- Chore: update license to Apache2 (#76)
- Chore: make sure slug is compatible with the latest spec

## [0.2.0] - 2023-12-04

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ docs:

.PHONY: changelog
changelog:
git cliff -o CHANGELOG.md
git cliff --bump -o CHANGELOG.md

.PHONY: inngest-dev
inngest-dev:
Expand Down
9 changes: 9 additions & 0 deletions dev.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require Logger

Task.async(fn ->
{:ok, _pid} = Inngest.Test.Application.start(:normal, [])
Logger.debug("Starting SDK development server")

Process.sleep(:infinity)
end)
|> Task.await(:infinity)
4 changes: 2 additions & 2 deletions lib/inngest/function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ defmodule Inngest.Function do

@impl true
def slug() do
fn_opts()
|> Map.get(:id)
fnid = fn_opts() |> Map.get(:id)
Inngest.Util.slugify(Config.app_name() <> "-" <> fnid)
end

@impl true
Expand Down
11 changes: 11 additions & 0 deletions lib/inngest/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ defmodule Inngest.Util do
def day_in_seconds(), do: 60 * 60 * 24
def hour_in_seconds(), do: 60 * 60
def minute_in_seconds(), do: 60

def slugify(text) when is_binary(text) do
text
|> String.downcase()
|> String.trim()
|> String.normalize(:nfd)
|> String.replace(~r/[^a-z0-9\s-]/u, " ")
|> String.replace(~r/[\s-]+/, "-", global: true)
end

def slugify(_), do: ""
end
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ defmodule Inngest.MixProject do
# Run "mix help compile.app" to learn about applications.
def application do
[
mod: {Inngest.Test.Application, []},
extra_applications: [:logger]
]
end
Expand Down Expand Up @@ -119,7 +118,7 @@ defmodule Inngest.MixProject do
"fmt:check": [
"format --check-formatted mix.exs 'lib/**/*.{ex,exs}' 'test/**/*.{ex,exs}'"
],
dev: "run --no-halt"
dev: "run --no-halt dev.exs"
]
end
end
2 changes: 1 addition & 1 deletion test/inngest/function/cases/failure_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Inngest.Function.Cases.RetriableTest do

{:ok, %{"data" => events}} = DevServer.list_events()

assert %{"id" => failed_id} =
assert %{"internal_id" => failed_id} =
events
|> Enum.find(fn evt ->
Map.get(evt, "name") == "inngest/function.failed" &&
Expand Down
6 changes: 3 additions & 3 deletions test/inngest/function_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Inngest.FunctionTest do

describe "slug/0" do
test "return name of function as slug" do
assert "test-event" == TestEventFn.slug()
assert "inngestapp-test-event" == TestEventFn.slug()
end
end

Expand All @@ -31,7 +31,7 @@ defmodule Inngest.FunctionTest do
test "event function should return approprivate map" do
assert [
%{
id: "test-event",
id: "inngestapp-test-event",
name: "App / Email: Awesome Event Func",
triggers: [
%Trigger{event: "my/awesome.event"}
Expand All @@ -56,7 +56,7 @@ defmodule Inngest.FunctionTest do
test "cron function should return appropriate map" do
assert [
%{
id: "test-cron",
id: "inngestapp-test-cron",
name: "Awesome Cron Func",
triggers: [
%Trigger{cron: "TZ=America/Los_Angeles * * * * *"}
Expand Down
1 change: 1 addition & 0 deletions test/support/dev_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule Inngest.Test.DevServer do
defp client() do
middleware = [
{Tesla.Middleware.BaseUrl, @base_url},
{Tesla.Middleware.Headers, [{"cache-control", "no-cache"}]},
Tesla.Middleware.JSON
]

Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
opts = [:skip]
opts = opts ++ if System.get_env("UNIT") == "true", do: [:integration], else: []

{:ok, _} = Inngest.Test.Application.start(:normal, [])

ExUnit.start(exclude: opts)

ExUnit.after_suite(fn _ ->
Expand Down

0 comments on commit 5f3579a

Please sign in to comment.