Skip to content

Commit f9848b3

Browse files
committed
Add full e2e phoenix app test
1 parent 277b1f8 commit f9848b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2723
-30
lines changed

mix.exs

+43-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defmodule Sentry.Mixfile do
1313
package: package(),
1414
deps: deps(),
1515
elixirc_paths: elixirc_paths(Mix.env()),
16+
test_paths: test_paths(System.get_env("SENTRY_INTEGRATION")),
1617
dialyzer: [
1718
flags: [:unmatched_returns, :error_handling, :extra_return],
1819
plt_file: {:no_warn, "plts/dialyzer.plt"},
@@ -22,7 +23,8 @@ defmodule Sentry.Mixfile do
2223
],
2324
test_coverage: [tool: ExCoveralls],
2425
preferred_cli_env: [
25-
"coveralls.html": :test
26+
"coveralls.html": :test,
27+
"test.integrations": :test
2628
],
2729
name: "Sentry",
2830
docs: [
@@ -83,6 +85,9 @@ defmodule Sentry.Mixfile do
8385
defp elixirc_paths(:test), do: ["test/support"] ++ elixirc_paths(:dev)
8486
defp elixirc_paths(_other), do: ["lib"]
8587

88+
defp test_paths(nil), do: ["test"]
89+
defp test_paths(integration), do: ["test_integrations/#{integration}/test"]
90+
8691
defp deps do
8792
[
8893
{:nimble_options, "~> 1.0"},
@@ -123,6 +128,42 @@ defmodule Sentry.Mixfile do
123128
end
124129

125130
defp aliases do
126-
[test: ["sentry.package_source_code", "test"]]
131+
[
132+
test: ["sentry.package_source_code", "test", "test.integrations"],
133+
"test.integrations": &test_integrations/1
134+
]
135+
end
136+
137+
@integrations [
138+
"phoenix_app"
139+
]
140+
141+
defp test_integrations(args) do
142+
for integration <- @integrations do
143+
run_integration_tests(integration, args)
144+
end
145+
end
146+
147+
defp run_integration_tests(integration, args) do
148+
header = if IO.ANSI.enabled?(), do: IO.ANSI.bright() <> IO.ANSI.cyan(), else: ""
149+
reset = if IO.ANSI.enabled?(), do: IO.ANSI.reset(), else: ""
150+
151+
IO.puts("\n#{header}==> Running tests for integration: #{integration}#{reset}")
152+
153+
integration_dir = Path.join("test_integrations", integration)
154+
155+
{_, status} =
156+
System.cmd("sh", ["-c", "cd #{integration_dir} && mix test #{Enum.join(args, " ")}"],
157+
into: IO.binstream(:stdio, :line)
158+
)
159+
160+
if status > 0 do
161+
error = if IO.ANSI.enabled?(), do: IO.ANSI.red(), else: ""
162+
IO.puts("#{error}Integration tests for #{integration} failed#{reset}")
163+
System.at_exit(fn _ -> exit({:shutdown, 1}) end)
164+
else
165+
success = if IO.ANSI.enabled?(), do: IO.ANSI.green(), else: ""
166+
IO.puts("#{success}Integration tests for #{integration} passed#{reset}")
167+
end
127168
end
128169
end

mix.lock

+27-27
Large diffs are not rendered by default.

test/test_helper.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ExUnit.start(assert_receive_timeout: 1000)
1+
ExUnit.start()
22

33
File.rm_rf!(Sentry.Sources.path_of_packaged_source_code())
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
import_deps: [:ecto, :ecto_sql, :phoenix],
3+
subdirectories: ["priv/*/migrations"],
4+
plugins: [Phoenix.LiveView.HTMLFormatter],
5+
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
6+
]
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Temporary files, for example, from tests.
23+
/tmp/
24+
25+
# Ignore package tarball (built via "mix hex.build").
26+
phoenix_app-*.tar
27+
28+
# Ignore assets that are produced by build tools.
29+
/priv/static/assets/
30+
31+
# Ignore digested assets cache.
32+
/priv/static/cache_manifest.json
33+
34+
# In case you use Node.js/npm, you want to ignore these.
35+
npm-debug.log
36+
/assets/node_modules/
37+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# PhoenixApp
2+
3+
To start your Phoenix server:
4+
5+
* Run `mix setup` to install and setup dependencies
6+
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
7+
8+
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
9+
10+
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
11+
12+
## Learn more
13+
14+
* Official website: https://www.phoenixframework.org/
15+
* Guides: https://hexdocs.pm/phoenix/overview.html
16+
* Docs: https://hexdocs.pm/phoenix
17+
* Forum: https://elixirforum.com/c/phoenix-forum
18+
* Source: https://github.com/phoenixframework/phoenix
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "tailwindcss/base";
2+
@import "tailwindcss/components";
3+
@import "tailwindcss/utilities";
4+
5+
/* This file is for your main application CSS */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
2+
// to get started and then uncomment the line below.
3+
// import "./user_socket.js"
4+
5+
// You can include dependencies in two ways.
6+
//
7+
// The simplest option is to put them in assets/vendor and
8+
// import them using relative paths:
9+
//
10+
// import "../vendor/some-package.js"
11+
//
12+
// Alternatively, you can `npm install some-package --prefix assets` and import
13+
// them using a path starting with the package name:
14+
//
15+
// import "some-package"
16+
//
17+
18+
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
19+
import "phoenix_html"
20+
// Establish Phoenix Socket and LiveView configuration.
21+
import {Socket} from "phoenix"
22+
import {LiveSocket} from "phoenix_live_view"
23+
import topbar from "../vendor/topbar"
24+
25+
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
26+
let liveSocket = new LiveSocket("/live", Socket, {
27+
longPollFallbackMs: 2500,
28+
params: {_csrf_token: csrfToken}
29+
})
30+
31+
// Show progress bar on live navigation and form submits
32+
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
33+
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
34+
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
35+
36+
// connect if there are any LiveViews on the page
37+
liveSocket.connect()
38+
39+
// expose liveSocket on window for web console debug logs and latency simulation:
40+
// >> liveSocket.enableDebug()
41+
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
42+
// >> liveSocket.disableLatencySim()
43+
window.liveSocket = liveSocket
44+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// See the Tailwind configuration guide for advanced usage
2+
// https://tailwindcss.com/docs/configuration
3+
4+
const plugin = require("tailwindcss/plugin")
5+
const fs = require("fs")
6+
const path = require("path")
7+
8+
module.exports = {
9+
content: [
10+
"./js/**/*.js",
11+
"../lib/phoenix_app_web.ex",
12+
"../lib/phoenix_app_web/**/*.*ex"
13+
],
14+
theme: {
15+
extend: {
16+
colors: {
17+
brand: "#FD4F00",
18+
}
19+
},
20+
},
21+
plugins: [
22+
require("@tailwindcss/forms"),
23+
// Allows prefixing tailwind classes with LiveView classes to add rules
24+
// only when LiveView classes are applied, for example:
25+
//
26+
// <div class="phx-click-loading:animate-ping">
27+
//
28+
plugin(({addVariant}) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
29+
plugin(({addVariant}) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
30+
plugin(({addVariant}) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),
31+
32+
// Embeds Heroicons (https://heroicons.com) into your app.css bundle
33+
// See your `CoreComponents.icon/1` for more information.
34+
//
35+
plugin(function({matchComponents, theme}) {
36+
let iconsDir = path.join(__dirname, "../deps/heroicons/optimized")
37+
let values = {}
38+
let icons = [
39+
["", "/24/outline"],
40+
["-solid", "/24/solid"],
41+
["-mini", "/20/solid"],
42+
["-micro", "/16/solid"]
43+
]
44+
icons.forEach(([suffix, dir]) => {
45+
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
46+
let name = path.basename(file, ".svg") + suffix
47+
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
48+
})
49+
})
50+
matchComponents({
51+
"hero": ({name, fullPath}) => {
52+
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
53+
let size = theme("spacing.6")
54+
if (name.endsWith("-mini")) {
55+
size = theme("spacing.5")
56+
} else if (name.endsWith("-micro")) {
57+
size = theme("spacing.4")
58+
}
59+
return {
60+
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
61+
"-webkit-mask": `var(--hero-${name})`,
62+
"mask": `var(--hero-${name})`,
63+
"mask-repeat": "no-repeat",
64+
"background-color": "currentColor",
65+
"vertical-align": "middle",
66+
"display": "inline-block",
67+
"width": size,
68+
"height": size
69+
}
70+
}
71+
}, {values})
72+
})
73+
]
74+
}

0 commit comments

Comments
 (0)