-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test vox.new task - add flag support for installer version - print mix help info when `mix vox.new` is ran without args - add test for vox.new task * test cleanup * run installer tests in ci * loosen installer's elixir version * line wrap pipe * fix deps for CI
- Loading branch information
1 parent
0871358
commit 7781765
Showing
5 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Mix.shell(Mix.Shell.Process) | ||
|
||
defmodule MixHelper do | ||
import ExUnit.Assertions | ||
|
||
def tmp_path do | ||
Path.expand("../../tmp", __DIR__) | ||
end | ||
|
||
defp random_string(len) do | ||
len | ||
|> :crypto.strong_rand_bytes() | ||
|> Base.encode64() | ||
|> binary_part(0, len) | ||
end | ||
|
||
def in_tmp(which, function) do | ||
path = Path.join([tmp_path(), random_string(10), to_string(which)]) | ||
|
||
try do | ||
File.rm_rf!(path) | ||
File.mkdir_p!(path) | ||
File.cd!(path, function) | ||
after | ||
File.rm_rf!(path) | ||
end | ||
end | ||
|
||
def assert_file(file) do | ||
assert File.regular?(file), "Expected #{file} to exist, but does not" | ||
end | ||
|
||
def assert_file(file, match) do | ||
cond do | ||
is_list(match) -> | ||
assert_file(file, &Enum.each(match, fn m -> assert &1 =~ m end)) | ||
|
||
is_binary(match) or is_struct(match, Regex) -> | ||
assert_file(file, &assert(&1 =~ match)) | ||
|
||
is_function(match, 1) -> | ||
assert_file(file) | ||
match.(File.read!(file)) | ||
|
||
true -> | ||
raise inspect({file, match}) | ||
end | ||
end | ||
|
||
def refute_file(file) do | ||
refute File.regular?(file), "Expected #{file} to not exist, but it does" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,80 @@ | ||
Code.require_file("mix_helper.exs", __DIR__) | ||
|
||
defmodule VoxNewTest do | ||
use ExUnit.Case | ||
doctest VoxNew | ||
import MixHelper | ||
import ExUnit.CaptureIO | ||
|
||
@app_name "blog" | ||
|
||
test "returns the version" do | ||
Mix.Tasks.Vox.New.run(["-v"]) | ||
assert_received {:mix_shell, :info, ["Vox installer v" <> _]} | ||
end | ||
|
||
test "new with defaults" do | ||
in_tmp("new with defaults", fn -> | ||
Mix.Tasks.Vox.New.run([@app_name]) | ||
|
||
assert_file("#{@app_name}/mix.exs", fn file -> | ||
assert file =~ "defmodule Blog.MixProject" | ||
assert file =~ "app: :blog" | ||
refute file =~ "mod: {Blog.Application, []}" | ||
refute file =~ ":esbuild" | ||
end) | ||
|
||
assert_file("#{@app_name}/config/config.exs", fn file -> | ||
assert file =~ "src_dir = \"site\"" | ||
assert file =~ "output_dir = \"_html\"" | ||
refute file =~ "config :esbuild" | ||
end) | ||
|
||
refute_file("#{@app_name}/assets/app.js") | ||
refute_file("#{@app_name}/lib/application.ex") | ||
refute_file("#{@app_name}/lib/#{@app_name}/esbuild.ex") | ||
end) | ||
end | ||
|
||
test "new with --esbuild" do | ||
in_tmp("new with --esbuild", fn -> | ||
Mix.Tasks.Vox.New.run([@app_name, "--esbuild"]) | ||
|
||
shared_file_assertions() | ||
|
||
assert_file("#{@app_name}/mix.exs", fn file -> | ||
assert file =~ "defmodule Blog.MixProject" | ||
assert file =~ "app: :blog" | ||
assert file =~ "mod: {Blog.Application, []}" | ||
assert file =~ ":esbuild" | ||
end) | ||
|
||
assert_file("#{@app_name}/config/config.exs", fn file -> | ||
assert file =~ "src_dir = \"site\"" | ||
assert file =~ "output_dir = \"_html\"" | ||
assert file =~ "config :esbuild" | ||
end) | ||
|
||
assert_file("#{@app_name}/assets/app.js") | ||
assert_file("#{@app_name}/lib/application.ex") | ||
assert_file("#{@app_name}/lib/#{@app_name}/esbuild.ex") | ||
end) | ||
end | ||
|
||
test "new without args" do | ||
in_tmp("new without args", fn -> | ||
assert capture_io(fn -> Mix.Tasks.Vox.New.run([]) end) =~ | ||
"Generate a new Vox application." | ||
end) | ||
end | ||
|
||
test "greets the world" do | ||
assert VoxNew.hello() == :world | ||
def shared_file_assertions() do | ||
assert_file("#{@app_name}/README.md") | ||
assert_file("#{@app_name}/lib/#{@app_name}.ex") | ||
assert_file("#{@app_name}/site/_root.html.eex") | ||
assert_file("#{@app_name}/site/_template.html.eex") | ||
assert_file("#{@app_name}/site/index.html.eex") | ||
assert_file("#{@app_name}/site/posts/hello-world.html.eex") | ||
assert_file("#{@app_name}/test/test_helper.exs") | ||
assert_file("#{@app_name}/test/#{@app_name}_test.exs") | ||
end | ||
end |