|
| 1 | +require "test_helper" |
| 2 | +require "minitest/mock" |
| 3 | + |
| 4 | +class Tailwindcss::CommandsTest < ActiveSupport::TestCase |
| 5 | + test ".platform is a string containing just the cpu and os (not the version)" do |
| 6 | + expected = "#{Gem::Platform.local.cpu}-#{Gem::Platform.local.os}" |
| 7 | + assert_equal(expected, Tailwindcss::Commands.platform) |
| 8 | + end |
| 9 | + |
| 10 | + def mock_exe_directory(platform) |
| 11 | + Dir.mktmpdir do |dir| |
| 12 | + FileUtils.mkdir(File.join(dir, platform)) |
| 13 | + path = File.join(dir, platform, "tailwindcss") |
| 14 | + FileUtils.touch(path) |
| 15 | + Gem::Platform.stub(:match, true) do |
| 16 | + yield(dir, path) |
| 17 | + end |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + test ".executable returns the absolute path to the binary" do |
| 22 | + mock_exe_directory("sparc-solaris2.8") do |dir, executable| |
| 23 | + expected = File.expand_path(File.join(dir, "sparc-solaris2.8", "tailwindcss")) |
| 24 | + assert_equal(expected, executable, "assert on setup") |
| 25 | + assert_equal(expected, Tailwindcss::Commands.executable(exe_path: dir)) |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + test ".executable raises UnsupportedPlatformException when we're not on a supported platform" do |
| 30 | + Gem::Platform.stub(:match, false) do # nothing is supported |
| 31 | + assert_raises(Tailwindcss::Commands::UnsupportedPlatformException) do |
| 32 | + Tailwindcss::Commands.executable |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + test ".executable raises ExecutableNotFoundException when we can't find the executable we expect" do |
| 38 | + Dir.mktmpdir do |dir| # empty directory |
| 39 | + assert_raises(Tailwindcss::Commands::ExecutableNotFoundException) do |
| 40 | + Tailwindcss::Commands.executable(exe_path: dir) |
| 41 | + end |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + test ".compile_command" do |
| 46 | + mock_exe_directory("sparc-solaris2.8") do |dir, executable| |
| 47 | + Rails.stub(:root, File) do # Rails.root won't work in this test suite |
| 48 | + actual = Tailwindcss::Commands.compile_command(exe_path: dir) |
| 49 | + assert_kind_of(Array, actual) |
| 50 | + assert_equal(executable, actual.first) |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + test ".watch_command" do |
| 56 | + mock_exe_directory("sparc-solaris2.8") do |dir, executable| |
| 57 | + Rails.stub(:root, File) do # Rails.root won't work in this test suite |
| 58 | + actual = Tailwindcss::Commands.watch_command(exe_path: dir) |
| 59 | + assert_kind_of(Array, actual) |
| 60 | + assert_equal(executable, actual.first) |
| 61 | + assert_includes(actual, "-w") |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | +end |
0 commit comments