Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

midi

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

midi - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

6

CHANGELOG.md
# node-midi Changelog
## Version 1.0.2
* Add a 'send' alias for 'sendMessage'.
* Use the NAN module init.
* Ensure promises can be resolved inside on('message') callbacks (Malvineous)
## Version 1.0.1

@@ -4,0 +10,0 @@

2

package.json
{
"name": "midi",
"version": "1.0.1",
"version": "1.0.2",
"scripts": {

@@ -5,0 +5,0 @@ "test": "mocha test/unit/*.js && node test/virtual-loopback-test-automated.js"

@@ -87,2 +87,70 @@ var should = require('should');

describe(".on('message')", function() {
it('allows promises to resolve', async function() {
const portName = 'node-midi Virtual Loopback';
// Create a promise we can use to pass/fail the whole test.
let resolveTestPromise, rejectTestPromise;
const testPromise = new Promise((resolve, reject) => {
resolveTestPromise = resolve;
rejectTestPromise = reject;
});
// Create a promise to resolve in the on('message') callback.
let resolvePendingPromise, rejectPendingPromise;
const promise = new Promise((resolve, reject) => {
resolvePendingPromise = resolve;
rejectPendingPromise = reject;
});
// Create a virtual loopback MIDI port.
var input = new Midi.Input();
input.on('message', function(deltaTime, message) {
// Resolve the promise now we have received a MIDI message.
resolvePendingPromise(message);
});
input.openVirtualPort(portName);
let awaitComplete = false;
setTimeout(function() {
input.closePort();
if (!awaitComplete) {
// If the `await` statement below has not yet returned, then this is
// a failure.
rejectTestPromise(new Error('Await did not return in time'));
}
}, 1500); // Must be under 2000 or Mocha fails us for being too slow.
// Find the other end of the virtual MIDI port we created above.
const output = new Midi.Output();
for (var i = 0; i < output.getPortCount(); ++i) {
if (output.getPortName(i).includes(portName)) {
output.openPort(i);
}
}
if (!output.isPortOpen()) {
throw Error('Unable to find virtual loopback port');
}
// Send a message, which should end up calling the on('message') handler.
output.sendMessage([176, 22, 1]);
output.closePort();
// Wait for the promise resolved by on('message'). If everything is
// working, this promise has already been resolved and will complete
// immediately. However if the event loop is starved, it will block
// until the next event arrives, resulting in a timeout.
const result = await promise;
awaitComplete = true;
// Resolve the promise for this test, which will have no effect if the
// promise has already been rejected because the `await` took too long.
resolveTestPromise();
// Wait for the test promise, which will cause an exception to be thrown
// if the test promise was rejected.
await testPromise;
});
});
});

@@ -93,2 +93,22 @@ var should = require('should');

});
describe('.send', function() {
var output = new Midi.Output();
it('should require an array argument', function() {
(function() {
output.send();
}).should.throw('First argument must be an array');
});
});
describe('.sendMessage', function() {
var output = new Midi.Output();
it('should require an array argument', function() {
(function() {
output.sendMessage();
}).should.throw('First argument must be an array');
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc