importmap_mocha-rails 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55c9689c64ecb2902d9fcb77c63837596a8a7f6a3409d33b08384e1adb92db5d
4
- data.tar.gz: e7f7fbe95e2e778add22a79931a7b0b8ced8fe2ea5a1263a52b476826918cc85
3
+ metadata.gz: 9c9335fe6db50bcd36e033af9889ada87d1c4fd773883fe80f97bf1f316972b5
4
+ data.tar.gz: fdfd7acf390b829a4ff8abcc6e9ffdd0149bcb6e882feff0767ffb4fc07fcb1d
5
5
  SHA512:
6
- metadata.gz: b57ba9684a4778aa2304d4daaca9b8dcdc9685b7992ba3bfece3bf120736d05a9e3dd96d0153eed4e3d23e2e729ffde4c7530b7acd0f9a855a997640e6294855
7
- data.tar.gz: 73568ec4bf12eba6c7fe126babd98cf443c4cd4a0c8c24629080d434888d5a8dc4d3c128eecec2d671c6c3556f629ca71fa1584c2c58d5c8f1376307d1d8af41
6
+ metadata.gz: d953534e4fa286fbb50030df6ac659b352d84db42d6530c88222240a028bf85447591776f93d0c66c65d10e97017b2eec5ec7511da419d939e1394134492f75a
7
+ data.tar.gz: 30b9619663f685a3f748e617db1d85be6dd10950767fe153172534a11778790d7d2c050455674cc15272a89b7f5159c2a878ccc3479039908d136b43aa079188
data/README.md CHANGED
@@ -3,6 +3,14 @@
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
+ | Library | Version |
7
+ |-------------------------------------------|---------|
8
+ | [Mocha](https://mochajs.org/) | 11.1.0 |
9
+ | [Chai](https://www.chaijs.com/) | 5.1.2 |
10
+ | [@mswjs/interceptors](https://github.com/mswjs/interceptors) | 0.37.5 |
11
+
12
+ [More useful in combination with the rails_live_reload gem](#use-with-rails_live_reload-gem)
13
+
6
14
  # Installation
7
15
 
8
16
  Assuming you have already installed importmap-rails with Rails 7, add the following to your Gemfile and run `bundle install`.
@@ -85,6 +93,39 @@ describe('clear controller', () => {
85
93
  * config.importmap_mocha_path: The location where the test code is stored. Default is `test/javascripts` and `spec/javascripts`.
86
94
  * config.importmap_mocha_scripts: The scripts to be loaded globally. e.g. `['jquery.js']`.
87
95
 
96
+ # Use with Rails_Live_Reload gem
97
+
98
+ It is strongly recommended to use with [rails_live_reload](https://github.com/railsjazz/rails_live_reload)
99
+
100
+ ![](./images/screencast01.gif)
101
+
102
+ Add this line to your application's Gemfile:
103
+
104
+ ```ruby
105
+ group :development do
106
+ gem "importmap_mocha_rails"
107
+ gem "rails_live_reload"
108
+ end
109
+ ```
110
+
111
+ And then execute:
112
+
113
+ ```
114
+ bundle install
115
+ rails generate rails_live_reload:install
116
+ ```
117
+
118
+ Edit initializer
119
+ ```ruby
120
+ # frozen_string_literal: true
121
+
122
+ RailsLiveReload.configure do |config|
123
+ config.watch %r{app/views/.+\.(erb|haml|slim)$}
124
+ # Monitor JavaScript tests in addition to default paths
125
+ config.watch %r{(app|vendor|test)/(assets|javascript|javascripts)/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*}, reload: :always
126
+ end if defined?(RailsLiveReload)
127
+ ```
128
+
88
129
  # Author
89
130
 
90
131
  Takashi Kato tohosaku@users.osdn.me
@@ -0,0 +1,36 @@
1
+ export function changeFavicon(failures) {
2
+ const links = document.getElementsByTagName('link')
3
+
4
+ for (let i=0; i<links.length; i++) {
5
+ let link = links[i];
6
+ if (link.rel == 'icon') {
7
+ const icon = failures > 0 ? favicon('red')
8
+ : favicon('green')
9
+ link.remove()
10
+ const newlink = document.createElement("link");
11
+ newlink.rel = 'icon';
12
+ newlink.href = icon;
13
+ newlink.type = 'image/svg+xml';
14
+ const head = document.getElementsByTagName("head")[0];
15
+ head.appendChild(newlink);
16
+
17
+ return;
18
+ }
19
+ }
20
+ }
21
+
22
+ function favicon(color, count) {
23
+ const icon = `<?xml version="1.0" encoding="UTF-8"?>
24
+ <svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg">
25
+ <style>circle {
26
+ fill: ${color};
27
+ stroke: ${color};
28
+ stroke-width: 3px;
29
+ }
30
+ </style>
31
+ <circle cx="50" cy="50" r="47"/>
32
+ </svg>`
33
+ const base64Svg = btoa(unescape(encodeURIComponent(icon)));
34
+
35
+ return `data:image/svg+xml;base64,${base64Svg}`;
36
+ }
@@ -6,6 +6,7 @@
6
6
  <% if Rails.application.config.importmap_mocha_scripts.size > 0 %>
7
7
  <%= javascript_include_tag *Rails.application.config.importmap_mocha_scripts %>
8
8
  <% end %>
9
+ <link rel="icon" href="data:image/png;base64,iVBORw0KGgo=">
9
10
  <%= javascript_include_tag 'mocha' %>
10
11
  <%= stylesheet_link_tag 'mocha' %>
11
12
  <%= javascript_importmap_tags 'importmap_mocha' %>
@@ -24,8 +25,10 @@
24
25
  </div>
25
26
  </div>
26
27
  </div>
27
- <script type="module">
28
- mocha.run();
29
- </script>
28
+ <script type="module">
29
+ import { changeFavicon } from 'importmap_mocha'
30
+
31
+ mocha.run(changeFavicon)
32
+ </script>
30
33
  </body>
31
34
  </html>
data/config/importmap.rb CHANGED
@@ -4,13 +4,6 @@ pin "@mswjs/interceptors", to: "@mswjs--interceptors.js"
4
4
  pin "@mswjs/interceptors/presets/browser" , to: "@mswjs--interceptors--presets--browser.js"
5
5
  pin "chai", to: "chai.js"
6
6
 
7
- pin "@open-draft/logger", to: "@open-draft--logger.js" # @0.3.0
8
- pin "is-node-process", to: "is-node-process.js" # @1.2.0
9
- pin "outvariant", to: "outvariant.js" # @1.4.0
10
- pin "@open-draft/until", to: "@open-draft--until.js" # @2.1.0
11
- pin "@open-draft/deferred-promise", to: "@open-draft--deferred-promise.js" # @2.2.0
12
- pin "strict-event-emitter", to: "strict-event-emitter.js" # @0.5.1
13
-
14
7
  Rails.application.config.importmap_mocha_path.each do |path|
15
8
  pin_all_from path
16
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImportmapMocha
4
- VERSION = '0.3.4'
4
+ VERSION = '0.3.6'
5
5
  end