Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup and test scripts #14

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@
- Brew may ask you to upgrade your database upon installation: `brew postgresql-upgrade-database`
- Start Postgres with `brew services start postgresql`
- If this is the first time you've used it, you may need to create a database. Run `createdb`
- asdf: `brew install asdf`
- `asdf install`
- You may need to run `asdf plugin add` some of `erlang`, `elixir`, or `nodejs` first.
- `mise` or `asdf`:
- `mise`:
- `curl https://mise.run | sh` or `brew install mise`
- `mise install`
- `asdf`:
- `brew install asdf`
- You may need to run `asdf plugin add` some of `erlang`, `elixir`, or `nodejs`.
- `asdf install`

## Set up

- `asdf install`
- `mix setup`
- `bin/setup` (rerun after any dependencies are updated)

Run the server with `mix phx.server`.

Now you can visit [`localhost:4001`](http://localhost:4001) from your browser.

## Tests

Run `bin/test` to run all backend and frontend test suites.

Run `mix test test/path/to/file_test.exs` or `npm run test:jest -- js/path/to/file.test.ts` to run a specific unit test.

See [`bin/test`](bin/test), [`mix.exs`](mix.exs), and [`package.json`](package.json) for other test commands.

## Docker

To run the Docker container locally, run `docker compose up --build`.
Expand Down
39 changes: 39 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env sh

# Exit if any subcommand fails
set -e
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set -ex and remove the echos below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whaaat I never knew about set -x. That's cool.

Having tried it, it is slightly different than the echos:

  • It shows all commands, even the command -v mise which is useful if you're debugging exactly what's happening, but is too verbose for navigating all the text scrolling down your terminal.
  • It can't do the little bits of editorializing I put in the echos (pointing out that mix ecto.setup is in (dev), and combining local.hex and local.rebar)

What do you think about adding it to bin/test, but keeping the echos in bin/setup?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Points taken! That works for me 👍


runtime_manager=$(command -v mise || command -v asdf)

echo "# asdf/mise install"
$runtime_manager install
echo ""

echo "# mix local.hex and local.rebar"
mix local.hex --force
mix local.rebar --force
echo ""

echo "# mix deps.get"
mix deps.get
echo ""

echo "# mix deps.compile (dev)"
mix deps.compile
echo ""

echo "# mix ecto.setup (dev)"
mix ecto.setup
echo ""

echo "# mix deps.compile (test)"
env MIX_ENV=test mix deps.compile
echo ""

echo "# mix ecto.setup (test)"
env MIX_ENV=test mix ecto.setup
echo ""

echo "# npm ci"
npm ci
echo ""
8 changes: 8 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh

set -ex

mix test_all
# dialyzer isn't included in `test_all` because it has to run in MIX_ENV=dev
mix dialyzer
npm test
39 changes: 34 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ defmodule Orbit.MixProject do
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
preferred_cli_env: [
test_all: :test
],
deps: deps(),
dialzyer: [
plt_add_apps: [:mix]
Expand Down Expand Up @@ -74,11 +77,37 @@ defmodule Orbit.MixProject do
# See the documentation for `Mix` for more info on aliases.
defp aliases do
[
setup: ["deps.get", "ecto.setup", "assets.build"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test", "credo"],
sobelow: ["sobelow --config"]
"ecto.setup": [
"ecto.create",
"ecto.migrate",
# only run seeds.exs in dev,
if Mix.env() == :dev do
"run priv/repo/seeds.exs"
else
# noop
fn _args -> :ok end
end
],
"ecto.reset": [
"ecto.drop",
"ecto.setup"
],
test: [
"ecto.create --quiet",
"ecto.migrate --quiet",
"test"
],
sobelow: ["sobelow --config"],
# Must be separate from `test` so that you can pass args to `test`,
# and only run `test` on those files and not `credo` on all files.
# runs in MIX_ENV=test because of preferred_cli_env above
test_all: [
"test",
"credo",
"format --check-formatted",
"sobelow"
# dialyzer for some reason has to be in MIX_ENV=dev, so run it separately.
]
]
end
end
Loading