From 0adcb7be7c8a0aa59724426212ce818d2a17b5f2 Mon Sep 17 00:00:00 2001 From: Kevin Sylvestre Date: Fri, 12 Jan 2024 01:11:15 -0800 Subject: [PATCH] Tests for rollup Ensures: 1. The rollup NPM packages are installed as dependencies 2. The rollup command is used as a build script 3. The Procfile.dev is copied / modified --- test/installer/rollup_test.rb | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/installer/rollup_test.rb diff --git a/test/installer/rollup_test.rb b/test/installer/rollup_test.rb new file mode 100644 index 0000000..8b01c7a --- /dev/null +++ b/test/installer/rollup_test.rb @@ -0,0 +1,37 @@ +require "json" +require "test_helper" + +class RollupInstallerTest < ActiveSupport::TestCase + include RailsAppHelpers + + test "installer for rollup" do + with_new_rails_app do + _out, _err = run_command("bin/rails", "javascript:install:rollup") + + assert_equal File.read("#{__dir__}/../../lib/install/Procfile.dev"), File.read("Procfile.dev") + assert_equal File.read("#{__dir__}/../../lib/install/rollup/rollup.config.js"), File.read("rollup.config.js") + + JSON.parse(File.read("package.json")).tap do |package| + assert_not_nil package["dependencies"]["rollup"] + assert_not_nil package["dependencies"]["@rollup/plugin-node-resolve"] + assert_equal "rollup -c --bundleConfigAsCjs rollup.config.js", 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:rollup") + + assert_equal <<~YAML, File.read("Procfile.dev") + pre: existing + js: yarn build --watch + YAML + end + end +end