importmap_mocha-rails 0.1.0 → 0.3.0
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
- data/config/importmap.rb +13 -1
- data/lib/importmap_mocha/engine.rb +3 -0
- data/lib/importmap_mocha/version.rb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c388a45ec1e48c3a10e9089dda0e7d7d3b76254c56944e1afea65dc4efa8f22
|
4
|
+
data.tar.gz: 5f799c2abad1d0ab33b4210d3181e8b8963bef9dcb5ff19b13eea16619926975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e638055ed8b76d94e3a81fb29aa099525278fc70435b685af24f5e71d2cff6009a5f3b0ea2b11dbfb85224aae02788a55059c1782db83e488bd8526321c1fec7
|
7
|
+
data.tar.gz: 067d16cbcd80f4dc2f3d1c56f5c4e9b8879db7eab43198492f087a1dd66cb57ba04acd14e76374be56a5bca8cfcdb3d1d24b389d9bffe751b1ad6b115a1ba07c
|
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">
|
data/config/importmap.rb
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
-
pin
|
1
|
+
pin "importmap_mocha"
|
2
|
+
|
3
|
+
pin "@mswjs/interceptors", to: "@mswjs--interceptors.js"
|
4
|
+
pin "@mswjs/interceptors/presets/browser" , to: "@mswjs--interceptors--presets--browser.js"
|
5
|
+
pin "chai", to: "chai.js"
|
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
|
+
|
2
14
|
Rails.application.config.importmap_mocha_path.each do |path|
|
3
15
|
pin_all_from path
|
4
16
|
end
|
@@ -42,6 +42,9 @@ module ImportmapMocha
|
|
42
42
|
unless Rails.application.config.respond_to?(:importmap_mocha_style)
|
43
43
|
Rails.application.config.importmap_mocha_style = 'bdd'
|
44
44
|
end
|
45
|
+
unless Rails.application.config.respond_to?(:importmap_mocha_scripts)
|
46
|
+
Rails.application.config.importmap_mocha_scripts = []
|
47
|
+
end
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
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.
|
4
|
+
version: 0.3.0
|
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-04 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
|
@@ -50,7 +64,7 @@ metadata:
|
|
50
64
|
homepage_uri: https://github.com/tohosaku/importmap_mocha-rails
|
51
65
|
source_code_uri: https://github.com/tohosaku/importmap_mocha-rails
|
52
66
|
changelog_uri: https://github.com/tohosaku/importmap_mocha-rails
|
53
|
-
post_install_message:
|
67
|
+
post_install_message:
|
54
68
|
rdoc_options: []
|
55
69
|
require_paths:
|
56
70
|
- lib
|
@@ -65,8 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
79
|
- !ruby/object:Gem::Version
|
66
80
|
version: '0'
|
67
81
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
69
|
-
signing_key:
|
82
|
+
rubygems_version: 3.5.3
|
83
|
+
signing_key:
|
70
84
|
specification_version: 4
|
71
85
|
summary: mochajs rails integration
|
72
86
|
test_files: []
|