|
3 | 3 | This plugin makes it easy to test ES modules with [importmap-rails](https://github.com/rails/importmap-rails) when using Rails 7 or later. |
4 | 4 | It integrates the [Mocha](https://mochajs.org/) JavaScript testing library (using [Chai](https://www.chaijs.com/) as the assertion library, [@mswjs/interceptors](https://github.com/mswjs/interceptors) as the mocking library) and runs tests for ES modules delivered with importmap in the browser. |
5 | 5 |
|
| 6 | +[More useful in combination with the rails_live_reload gem](#use-with-rails_live_reload-gem) |
| 7 | + |
6 | 8 | # Installation |
7 | 9 |
|
8 | 10 | Assuming you have already installed importmap-rails with Rails 7, add the following to your Gemfile and run `bundle install`. |
@@ -85,6 +87,39 @@ describe('clear controller', () => { |
85 | 87 | * config.importmap_mocha_path: The location where the test code is stored. Default is `test/javascripts` and `spec/javascripts`. |
86 | 88 | * config.importmap_mocha_scripts: The scripts to be loaded globally. e.g. `['jquery.js']`. |
87 | 89 |
|
| 90 | +# Use with Rails_Live_Reload gem |
| 91 | + |
| 92 | +It is strongly recommended to use with [rails_live_reload](https://github.com/railsjazz/rails_live_reload) |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +Add this line to your application's Gemfile: |
| 97 | + |
| 98 | +```ruby |
| 99 | +group :development do |
| 100 | + gem "importmap_mocha_rails" |
| 101 | + gem "rails_live_reload" |
| 102 | +end |
| 103 | +``` |
| 104 | + |
| 105 | +And then execute: |
| 106 | + |
| 107 | +``` |
| 108 | +bundle install |
| 109 | +rails generate rails_live_reload:install |
| 110 | +``` |
| 111 | + |
| 112 | +Edit initializer |
| 113 | +```ruby |
| 114 | +# frozen_string_literal: true |
| 115 | + |
| 116 | +RailsLiveReload.configure do |config| |
| 117 | + config.watch %r{app/views/.+\.(erb|haml|slim)$} |
| 118 | + # Monitor JavaScript tests in addition to default paths |
| 119 | + config.watch %r{(app|vendor|test)/(assets|javascript|javascripts)/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*}, reload: :always |
| 120 | +end if defined?(RailsLiveReload) |
| 121 | +``` |
| 122 | + |
88 | 123 | # Author |
89 | 124 |
|
90 | 125 | Takashi Kato tohosaku@users.osdn.me |
|
0 commit comments