{"size": 1904, "ext": "js", "max_stars_repo_path": "test/usecase.js", "max_stars_repo_name": "mohayonao/web-midi-test-api", "max_stars_repo_stars_event_min_datetime": "2015-06-21T14:32:09.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-18T16:56:58.000Z", "max_issues_repo_path": "test/usecase.js", "max_issues_repo_name": "mohayonao/web-midi-test-api", "max_issues_repo_issues_event_min_datetime": "2016-05-29T16:01:34.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-29T12:46:35.000Z", "max_forks_repo_path": "test/usecase.js", "max_forks_repo_name": "mohayonao/web-midi-test-api", "max_forks_repo_forks_event_min_datetime": "2016-05-30T09:55:34.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-21T11:02:46.000Z"}
{"max_stars_count": 8, "max_issues_count": 5, "max_forks_count": 2, "avg_line_length": 25.7297297297, "max_line_length": 68, "alphanum_fraction": 0.6129201681}
"use strict";

const assert = require("assert");
const test = require("eatest");
const sinon = require("sinon");
const webmidi = require("../src");

test.fork("midi-in", () => {
  const device = webmidi.createMIDIDevice();
  let input;

  return webmidi.requestMIDIAccess().then((access) => {
    input = access.inputs.values().next().value;

    input.onmidimessage = sinon.spy();

    return input.open();
  }).then(() => {
    assert(input.connection === "open");

    return device.outputs[0].send([ 0x90, 0x00, 0x00 ]);
  }).then(() => {
    assert(input.onmidimessage.callCount === 1);

    const message = input.onmidimessage.args[0][0].data;

    assert.deepEqual(message, new Uint8Array([ 0x90, 0x00, 0x00 ]));

    input.onmidimessage.reset();

    return input.close();
  }).then(() => {
    assert(input.connection === "closed");

    return device.outputs[0].send([ 0x90, 0x00, 0x00 ]);
  }).then(() => {
    assert(input.onmidimessage.callCount === 0);
  });
});

test.fork("midi-out", () => {
  const device = webmidi.createMIDIDevice();
  let output;

  device.inputs[0].onmidimessage = sinon.spy();

  return webmidi.requestMIDIAccess().then((access) => {
    output = access.outputs.values().next().value;

    return output.open();
  }).then(() => {
    assert(output.connection === "open");

    return output.send([ 0x90, 0x00, 0x00 ]);
  }).then(() => {
    assert(device.inputs[0].onmidimessage.callCount === 1);

    const message = device.inputs[0].onmidimessage.args[0][0].data;

    assert.deepEqual(message, new Uint8Array([ 0x90, 0x00, 0x00 ]));

    device.inputs[0].onmidimessage.reset();
  }).then(() => {
    return output.close();
  }).then(() => {
    assert(output.connection === "closed");

    return output.send([ 0x90, 0x00, 0x00 ]);
  }).then(() => {
    assert(output.connection === "open");
    assert(device.inputs[0].onmidimessage.callCount === 1);
  });
});
