Skip to content

Test json command using Minitest #209

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

Merged
merged 1 commit into from
Dec 1, 2023
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
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,3 @@ jobs:
- name: Run tests
run: |
bundle exec rake

- name: Ensure json command prints an importmap
run: |
cp lib/install/bin/importmap test/dummy/bin/importmap
test/dummy/bin/importmap json | jq -e .imports
27 changes: 27 additions & 0 deletions test/commands_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "test_helper"
require "json"

class CommandsTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation

setup do
@tmpdir = Dir.mktmpdir
FileUtils.cp_r("#{__dir__}/dummy", @tmpdir)
Dir.chdir("#{@tmpdir}/dummy")
FileUtils.cp("#{__dir__}/../lib/install/bin/importmap", "bin")
end

teardown do
FileUtils.remove_entry(@tmpdir) if @tmpdir
end

test "json command prints JSON with imports" do
out, err = run_importmap_command("json")
assert_includes JSON.parse(out), "imports"
end

private
def run_importmap_command(command, *args)
capture_subprocess_io { system("bin/importmap", command, *args, exception: true) }
end
end