-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow other module file extensions through config.importmap.accept
- Loading branch information
Showing
8 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "test_helper" | ||
|
||
class CacheSweeperTest < ActiveSupport::TestCase | ||
|
||
test "sweep is triggered when asset with extra extension changes" do | ||
previous_accept = Rails.application.config.importmap.accept | ||
Rails.application.config.importmap.accept += %w[jsx] | ||
|
||
@importmap = Importmap::Map.new.tap do |map| | ||
map.draw do | ||
pin "application" | ||
pin "components/Clock" | ||
end | ||
end | ||
|
||
@importmap.cache_sweeper watches: %w[app/javascript vendor/javascript].map(&Rails.root.method(:join)) | ||
|
||
resolver = MockResolver.new(%r{components/Clock\.js\z}) | ||
imports = generate_imports(resolver: resolver) | ||
touch_asset 'components/Clock.jsx' | ||
new_imports = generate_imports(resolver: resolver) | ||
|
||
assert_not_nil imports["components/Clock"] | ||
assert_not_nil new_imports["components/Clock"] | ||
assert_not_nil imports["application"] | ||
assert_not_nil new_imports["application"] | ||
assert_not_equal imports["components/Clock"], new_imports["components/Clock"] | ||
assert_equal imports["application"], new_imports["application"] | ||
ensure | ||
Rails.application.config.importmap.accept = previous_accept | ||
end | ||
|
||
private | ||
def touch_asset(name) | ||
FileUtils.touch Rails.root.join('app', 'javascript', name) | ||
sleep 3 | ||
@importmap.cache_sweeper.execute_if_updated | ||
end | ||
|
||
def generate_imports(resolver: ApplicationController.helpers) | ||
JSON.parse(@importmap.to_json(resolver: resolver))["imports"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component } from "react"; | ||
|
||
export default class Clock extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<h1>UNIX Clock</h1> | ||
<p>The current UNIX date is {Date.now()}.</p> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { render } from "react-dom"; | ||
import Clock from "components/Clock"; | ||
|
||
render( | ||
<Clock />, | ||
document.getElementById('root') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters