
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
importmap_mocha-rails
Advanced tools
This plugin makes it easy to test ES modules with importmap-rails when using Rails 7 or later. It integrates the Mocha JavaScript testing library (using Chai as the assertion library, @mswjs/interceptors as the mocking library) and runs tests for ES modules delivered with importmap in the browser.
Library | Version |
---|---|
Mocha | 11.1.0 |
Chai | 5.1.2 |
@mswjs/interceptors | 0.37.5 |
More useful in combination with the rails_live_reload gem
Assuming you have already installed importmap-rails with Rails 7, add the following to your Gemfile and run bundle install
.
group :test, :development do
gem 'importmap_mocha-rails'
end
Write your JavaScript tests in test/javascripts
or spec/javascripts
. One-to-one tests are named foo.test.js for a module named foo.js. Access http://localhost:3000/rails/info/mocha
in the Rails testing or development environment to view the test results.
By default, importmap-rails manages ES modules under app/javascript
, app/assets/javascripts
, and vendor/javascripts
.
controllers/clear_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["clear"];
clear(e) {
this.clearTargets.forEach(o => { o.value = ''});
}
}
controllers/clear_controller.spec.js
import { assert } from "chai"
import { Application } from "@hotwired/stimulus"
import ClearController from 'controllers/clear_controller'
const html = `<div data-controller="clear">
<input id="target" type="text" value="foo" data-clear-target="clear">
<button data-action="clear#clear">test</button>
</div>`
describe('clear controller', () => {
let container;
before(async () => {
container = document.getElementById('container')
const app = Application.start(container);
await app.register('clear', ClearController);
container.insertAdjacentHTML('afterbegin', html)
});
after(() => {
const clone = container.cloneNode(false);
container.parentNode.replaceChild(clone, container);
});
describe('click', () => {
it('The value of input element is cleard', async () => {
const target = container.querySelector('#target');
const button = container.querySelector('button');
await button.click();
assert.equal('', target.value);
});
});
});
"bdd"
or "tdd"
. Default is "bdd"
.test/javascripts
and spec/javascripts
.['jquery.js']
.It is strongly recommended to use with rails_live_reload
Add this line to your application's Gemfile:
group :development do
gem "importmap_mocha_rails"
gem "rails_live_reload"
end
And then execute:
bundle install
rails generate rails_live_reload:install
Edit initializer
# frozen_string_literal: true
RailsLiveReload.configure do |config|
config.watch %r{app/views/.+\.(erb|haml|slim)$}
# Monitor JavaScript tests in addition to default paths
config.watch %r{(app|vendor|test)/(assets|javascript|javascripts)/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*}, reload: :always
end if defined?(RailsLiveReload)
Takashi Kato tohosaku@users.osdn.me
MIT
FAQs
Unknown package
We found that importmap_mocha-rails demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.