Skip to content

Commit

Permalink
Tests for esbuild
Browse files Browse the repository at this point in the history
Ensures:

1. The esbuild NPM package is installed as a dependency
2. The esbuild command is used as a build script
3. The Procfile.dev is copied / modified
  • Loading branch information
ksylvest committed Jan 12, 2024
1 parent 24e88ca commit a1e93e8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/installer/esbuild_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "json"
require "test_helper"

class EsbuildInstallerTest < ActiveSupport::TestCase
include RailsAppHelpers

test "installer for esbuild" do
with_new_rails_app do
_out, _err = run_command("bin/rails", "javascript:install:esbuild")

assert_equal File.read("#{__dir__}/../../lib/install/Procfile.dev"), File.read("Procfile.dev")

JSON.parse(File.read("package.json")).tap do |package|
assert_not_nil package["dependencies"]["esbuild"]
assert_match "esbuild", package["scripts"]["build"]
end

if sprockets?
assert_match "//= link_tree ../builds", File.read("app/assets/config/manifest.js")
end
end
end

test "installer with pre-existing Procfile" do
with_new_rails_app do
File.write("Procfile.dev", "pre: existing\n")
_out, _err = run_command("bin/rails", "javascript:install:esbuild")

assert_equal <<~YAML, File.read("Procfile.dev")
pre: existing
js: yarn build --watch
YAML
end
end
end

0 comments on commit a1e93e8

Please sign in to comment.