importmap_mocha-rails 0.1.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11365cfee72382ffbf5e419f2c8a197adb2fe8d327d4c6b2350448fd09be05e6
4
- data.tar.gz: c557c7151e4957c2993542bd3cd62816564f65c896676bd0e0494569c50879ec
3
+ metadata.gz: 86ad7a8af87278157916f9355aa84c1eec7564969abaf41335585f667bdc815b
4
+ data.tar.gz: 52c7eb3feaafa2f2c3dbefebe343edbe29863bf13d404a56242b13a1604b5dce
5
5
  SHA512:
6
- metadata.gz: 73912e0a9e2c03310ac7526a842ac99c669fe59b5517bc0c5ede105a96063e106f74f1c1f11b1a646c409b9704d1e036e35b79474582b0f37eeabfcea43ed555
7
- data.tar.gz: 7c5c02c7edd5fc9b5772c47635d503119b9ada153e9e6170bc40850e2807fd5859f152899604921d572bcf9dac49ffbec6c5d0a25e04b2cbb4285f15582ab7e4
6
+ metadata.gz: 298fce026b6f26defde4dd2ec9b23b2a0314b4b803cb719833594fdc47ef2b54307ee0afb2346110bc7f4c3e241b78d11b17c4055ef06e38af07dc7a1896cb6d
7
+ data.tar.gz: 147026a848c6ce0d2d2901c38b5fbf88e72c8e3f864fc00d21885f7cf096537e358386bfc91b625975720d4d9fb6d6b8f99f50923d3521f9a640e65fdb1f2767
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # importmap_mocha-rails
2
2
 
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. It integrates the [Mocha](https://mochajs.org/) JavaScript testing library (using [Chai](https://www.chaijs.com/) as the assertion library) and runs tests for ES modules delivered with importmap in the browser.
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
+ 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.
4
5
 
5
6
  # Installation
6
7
 
@@ -35,9 +36,10 @@ export default class extends Controller {
35
36
  }
36
37
  ```
37
38
 
38
- controllers/clear_controller.test.js
39
+ controllers/clear_controller.spec.js
39
40
 
40
41
  ```javascript
42
+ import { assert } from "chai"
41
43
  import { Application } from "@hotwired/stimulus"
42
44
  import ClearController from 'controllers/clear_controller'
43
45
 
@@ -46,49 +48,40 @@ const html = `<div data-controller="clear">
46
48
  <button data-action="clear#clear">test</button>
47
49
  </div>`
48
50
 
49
- const config = { attributes: true, childList: true, subtree: true };
50
-
51
- // test!! test!!
52
- describe('clear_controller', () => {
51
+ describe('clear controller', () => {
53
52
 
54
53
  let container;
55
54
 
56
- beforeEach(() => {
55
+ before(async () => {
57
56
  container = document.getElementById('container')
57
+ const app = Application.start(container);
58
+ await app.register('clear', ClearController);
59
+
58
60
  container.insertAdjacentHTML('afterbegin', html)
59
61
  });
60
62
 
61
- afterEach(() => {
63
+ after(() => {
62
64
  const clone = container.cloneNode(false);
63
65
  container.parentNode.replaceChild(clone, container);
64
66
  });
65
67
 
66
- const watch = (fn) => {
67
- const observer = new MutationObserver(fn);
68
- observer.observe(container, config);
69
- }
70
-
71
68
  describe('click', () => {
72
- it('The value of input element is cleard', () => {
73
- const app = Application.start();
74
- app.register('clear', ClearController);
75
-
69
+ it('The value of input element is cleard', async () => {
76
70
  const target = container.querySelector('#target');
77
-
78
- watch(() => target.value.to.equal(''));
79
-
80
71
  const button = container.querySelector('button');
81
- button.click()
72
+ await button.click();
73
+
74
+ assert.equal('', target.value);
82
75
  });
83
76
  });
84
77
  });
85
-
86
78
  ```
87
79
 
88
80
  # Configuration
89
81
 
90
82
  * config.importmap_mocha_style: The style of the test code, `"bdd"` or `"tdd"`. Default is `"bdd"`.
91
83
  * config.importmap_mocha_path: The location where the test code is stored. Default is `test/javascripts` and `spec/javascripts`.
84
+ * config.importmap_mocha_scripts: The scripts to be loaded globally. e.g. `['jquery.js']`.
92
85
 
93
86
  # Author
94
87
 
@@ -3,7 +3,6 @@
3
3
  module ImportmapMocha
4
4
  class TestController < ActionController::Base
5
5
  layout false
6
-
7
6
  def index; end
8
7
  end
9
8
  end
@@ -3,7 +3,10 @@
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <title>Results of test execution </title>
6
- <%= javascript_include_tag 'mocha', 'chai' %>
6
+ <% if Rails.application.config.importmap_mocha_scripts.size > 0 %>
7
+ <%= javascript_include_tag *Rails.application.config.importmap_mocha_scripts %>
8
+ <% end %>
9
+ <%= javascript_include_tag 'mocha' %>
7
10
  <%= stylesheet_link_tag 'mocha' %>
8
11
  <%= javascript_importmap_tags 'importmap_mocha' %>
9
12
  <meta name="viewport" content="width=device-width, initial-scale=1">
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: importmap_mocha-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kato
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-04 00:00:00.000000000 Z
11
+ date: 2024-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: importmap-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: Add JavaScript testing tools in importmap environment.
28
42
  email:
29
43
  - tohosaku@users.osdn.me
@@ -38,11 +52,6 @@ files:
38
52
  - app/controllers/importmap_mocha/test_controller.rb
39
53
  - app/helpers/importmap_mocha/test_helper.rb
40
54
  - app/views/importmap_mocha/test/index.html.erb
41
- - config/importmap.rb
42
- - lib/importmap_mocha-rails.rb
43
- - lib/importmap_mocha/engine.rb
44
- - lib/importmap_mocha/version.rb
45
- - lib/tasks/importmap_mocha/rails_tasks.rake
46
55
  homepage: https://github.com/tohosaku/importmap_mocha-rails
47
56
  licenses:
48
57
  - MIT
@@ -50,7 +59,7 @@ metadata:
50
59
  homepage_uri: https://github.com/tohosaku/importmap_mocha-rails
51
60
  source_code_uri: https://github.com/tohosaku/importmap_mocha-rails
52
61
  changelog_uri: https://github.com/tohosaku/importmap_mocha-rails
53
- post_install_message:
62
+ post_install_message:
54
63
  rdoc_options: []
55
64
  require_paths:
56
65
  - lib
@@ -65,8 +74,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
74
  - !ruby/object:Gem::Version
66
75
  version: '0'
67
76
  requirements: []
68
- rubygems_version: 3.2.5
69
- signing_key:
77
+ rubygems_version: 3.5.3
78
+ signing_key:
70
79
  specification_version: 4
71
80
  summary: mochajs rails integration
72
81
  test_files: []
data/config/importmap.rb DELETED
@@ -1,4 +0,0 @@
1
- pin 'importmap_mocha'
2
- Rails.application.config.importmap_mocha_path.each do |path|
3
- pin_all_from path
4
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ImportmapMocha
4
- class Engine < ::Rails::Engine
5
- config.before_initialize do
6
- Rails.application.config.importmap_mocha_path = []
7
- %w[test spec].each do |d|
8
- path = Rails.root.join(d, 'javascripts')
9
- Rails.application.config.importmap_mocha_path << path if path.exist?
10
- end
11
- end
12
-
13
- initializer 'importmap_mocha.assets' do
14
- if Rails.application.config.respond_to?(:assets)
15
- Rails.application.config.assets.paths << Engine.root.join('app/assets/javascripts')
16
- Rails.application.config.assets.paths << Engine.root.join('app/assets/stylesheets')
17
- Rails.application.config.assets.paths << Engine.root.join('vendor/javascripts')
18
- Rails.application.config.assets.paths << Engine.root.join('vendor/stylesheets')
19
- Rails.application.config.assets.paths += Rails.application.config.importmap_mocha_path
20
- end
21
- end
22
-
23
- PRECOMPILE_ASSETS = %w[importmap_mocha.js chai.js mocha.js mocha.css].freeze
24
-
25
- initializer 'turbo.assets' do
26
- Rails.application.config.assets.precompile += PRECOMPILE_ASSETS if Rails.application.config.respond_to?(:assets)
27
- end
28
-
29
- initializer 'importmap_mocha.importmap', before: 'importmap' do |app|
30
- app.config.importmap.paths << Engine.root.join('config/importmap.rb') if Rails.application.respond_to?(:importmap)
31
- end
32
-
33
- initializer 'importmap_mocha.routes' do
34
- Rails.application.routes.prepend do
35
- scope module: 'importmap_mocha' do
36
- get '/rails/info/mocha' => 'test#index'
37
- end
38
- end
39
- end
40
-
41
- initializer 'importmap_mocha.config' do
42
- unless Rails.application.config.respond_to?(:importmap_mocha_style)
43
- Rails.application.config.importmap_mocha_style = 'bdd'
44
- end
45
- end
46
- end
47
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ImportmapMocha
4
- VERSION = '0.1.0'
5
- end
@@ -1,5 +0,0 @@
1
- require 'importmap_mocha/version'
2
- require 'importmap_mocha/engine'
3
-
4
- module ImportmapMocha
5
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :importmap_mocha_rails do
3
- # # Task goes here
4
- # end