Skip to content

Commit 03bcb8b

Browse files
committed
feat: implement multi-tier test architecture with runtime detection
- Add comprehensive runtime detection in test_helper.exs - Detect Bun and Deno availability - Automatically exclude runtime-dependent tests when runtimes missing - Conditionally start ReactServer only when runtime available - Tag all test files by category - @moduletag :unit - Pure Elixir tests (cache, config, telemetry) - @moduletag :integration - Full integration tests with runtimes - @moduletag :requires_runtime - Tests needing Bun or Deno - Fix template test assertion - Update Deno template test to expect versioned import (react-dom@18) - Update GitHub Actions test workflow - Add Bun setup via oven-sh/setup-bun@v1 - Add Deno setup via denoland/setup-deno@v1 - Install inotify-tools for file watching support Test organization: - Unit tests run without runtime dependencies (fast feedback) - Integration tests validate real runtime behavior (comprehensive) - Easy local dev: 'mix test --only unit' or 'mix test --exclude integration' Resolves test failures in CI by allowing tests to run without runtimes
1 parent dc97828 commit 03bcb8b

File tree

14 files changed

+75
-7
lines changed

14 files changed

+75
-7
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ jobs:
2020
elixir-version: '1.18'
2121
otp-version: '28'
2222

23+
- name: Setup Bun
24+
uses: oven-sh/setup-bun@v1
25+
with:
26+
bun-version: latest
27+
28+
- name: Setup Deno
29+
uses: denoland/setup-deno@v1
30+
with:
31+
deno-version: v1.x
32+
33+
- name: Install system dependencies
34+
run: sudo apt-get update && sudo apt-get install -y inotify-tools
35+
2336
- name: Cache dependencies
2437
uses: actions/cache@v4
2538
with:

test/phoenix/mix/build/deno_integration_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Mix.Tasks.Phx.React.Deno.BundleIntegrationTest do
22
use ExUnit.Case, async: false
33

4+
@moduletag :integration
5+
46
alias Mix.Tasks.Phx.React.Deno.Bundle
57

68
describe "bundle integration tests" do

test/phoenix/mix/build/deno_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Mix.Tasks.Phx.React.Deno.BundleTest do
22
use ExUnit.Case, async: false
33

4+
@moduletag :unit
5+
46
alias Mix.Tasks.Phx.React.Deno.Bundle
57

68
describe "run/1" do

test/phoenix/mix/build/server_deno_template_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Mix.Tasks.Phx.React.Deno.ServerTemplateTest do
22
use ExUnit.Case, async: true
33

4+
@moduletag :unit
5+
46
describe "server_deno.js.eex template" do
57
test "template compiles correctly with sample files" do
68
files = [
@@ -37,7 +39,7 @@ defmodule Mix.Tasks.Phx.React.Deno.ServerTemplateTest do
3739

3840
assert String.contains?(
3941
result,
40-
"import { renderToReadableStream, renderToString, renderToStaticMarkup } from \"npm:react-dom/server\""
42+
"import { renderToReadableStream, renderToString, renderToStaticMarkup } from \"npm:react-dom@18/server\""
4143
)
4244

4345
# Check that environment variables are used

test/phoenix/react_server/cache_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Phoenix.ReactServer.CacheTest do
22
use ExUnit.Case, async: true
33

4+
@moduletag :unit
5+
46
alias Phoenix.ReactServer.Cache
57

68
setup_all do

test/phoenix/react_server/helper_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Phoenix.ReactServer.HelperTest do
22
use ExUnit.Case, async: false
33

4+
@moduletag :requires_runtime
5+
46
alias Phoenix.ReactServer.Helper
57

68
setup_all do

test/phoenix/react_server/runtime/common_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Phoenix.ReactServer.Runtime.CommonTest do
22
use ExUnit.Case, async: true
33

4+
@moduletag :unit
5+
46
alias Phoenix.ReactServer.Runtime.Common
57

68
describe "handle_result/1" do

test/phoenix/react_server/runtime/deno_integration_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Phoenix.ReactServer.Runtime.DenoIntegrationTest do
22
use ExUnit.Case, async: false
33

4+
@moduletag :integration
5+
46
alias Phoenix.ReactServer.Runtime.Deno
57

68
describe "integration tests" do

test/phoenix/react_server/runtime/deno_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Phoenix.ReactServer.Runtime.DenoTest do
22
use ExUnit.Case, async: false
33

4+
@moduletag :unit
5+
46
alias Phoenix.ReactServer.Runtime.Deno
57

68
describe "config/0" do

test/phoenix/react_server/runtime/file_watcher_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule Phoenix.ReactServer.Runtime.FileWatcherTest do
44
alias Phoenix.ReactServer.Runtime.FileWatcher
55

66
@moduletag :capture_log
7+
@moduletag :integration
78

89
setup do
910
# Create a temporary directory for testing

0 commit comments

Comments
 (0)