rails/actiontext/test/javascript_package_test.rb
Matias Grunberg 2dbcb3df33 fix using actiontext.js in sprocket
actiontext.js is compiled as ESM bundle instead of UMD bundle.
This leads to issues when trying to use ActionText with sprockets because the ESM bundle declares variables like they are scoped to the file but sprockets will see them as scoped globally.
This is a problem, in particular, if you want to mix actiontext with
turbo-rails.

The problem got introduced in https://github.com/rails/rails/pull/46447.
I traced valid compilation back to
https://github.com/rails/rails/pull/42895.

This commit mimic changes made in
https://github.com/rails/rails/pull/42895 to ActiveStorage:
   Retains app/assets/javascripts/actiontext.js as a UMD package for backwards compatibility with
   bundling in the asset pipeline, but also adds app/assets/javascripts/actiontext.esm.js for use
   with ESM via importmap in the browser.
2023-11-07 00:36:53 -03:00

19 lines
475 B
Ruby

# frozen_string_literal: true
require "test_helper"
class JavascriptPackageTest < ActiveSupport::TestCase
def test_compiled_code_is_in_sync_with_source_code
compiled_files = %w[
app/assets/javascripts/actiontext.js
app/assets/javascripts/actiontext.esm.js
].map do |file|
Pathname(file).expand_path("#{__dir__}/..")
end
assert_no_changes -> { compiled_files.map(&:read) } do
system "yarn build", exception: true
end
end
end