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 +4 -4
- data/README.md +15 -22
- data/app/controllers/importmap_mocha/test_controller.rb +0 -1
- data/app/views/importmap_mocha/test/index.html.erb +4 -1
- metadata +20 -11
- data/config/importmap.rb +0 -4
- data/lib/importmap_mocha/engine.rb +0 -47
- data/lib/importmap_mocha/version.rb +0 -5
- data/lib/importmap_mocha-rails.rb +0 -5
- data/lib/tasks/importmap_mocha/rails_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86ad7a8af87278157916f9355aa84c1eec7564969abaf41335585f667bdc815b
|
4
|
+
data.tar.gz: 52c7eb3feaafa2f2c3dbefebe343edbe29863bf13d404a56242b13a1604b5dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
-
|
50
|
-
|
51
|
-
// test!! test!!
|
52
|
-
describe('clear_controller', () => {
|
51
|
+
describe('clear controller', () => {
|
53
52
|
|
54
53
|
let container;
|
55
54
|
|
56
|
-
|
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
|
-
|
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,10 @@
|
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8" />
|
5
5
|
<title>Results of test execution </title>
|
6
|
-
|
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
|
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:
|
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.
|
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,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
|