{"size": 1632, "ext": "js", "max_stars_repo_path": "packages/enchannel/__tests__/index-spec.js", "max_stars_repo_name": "lgeiger/nteract", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "packages/enchannel/__tests__/index-spec.js", "max_issues_repo_name": "lgeiger/nteract", "max_issues_repo_issues_event_min_datetime": "2018-10-19T15:07:06.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-19T15:07:06.000Z", "max_forks_repo_path": "packages/enchannel/__tests__/index-spec.js", "max_forks_repo_name": "lgeiger/nteract", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 32.64, "max_line_length": 64, "alphanum_fraction": 0.6642156863}
const enchannel = require("../");

function spoofChannels() {
  const shell = {
    next: jest.fn(),
    complete: jest.fn(),
    filter: () => shell,
    childOf: () => shell,
    map: () => shell,
    subscribe: cb => cb.call(shell)
  };
  return {
    shell,
    iopub: { complete: jest.fn() },
    stdin: { complete: jest.fn() },
    control: { complete: jest.fn() },
    heartbeat: { complete: jest.fn() }
  };
}

describe("shutdownRequest", () => {
  it("shutdowns channels", () => {
    const channels = spoofChannels();
    enchannel.shutdownRequest(channels);
    expect(channels.shell.complete).toBeCalled();
    expect(channels.iopub.complete).toBeCalled();
    expect(channels.stdin.complete).toBeCalled();
    expect(channels.control.complete).toBeCalled();
    expect(channels.heartbeat.complete).toBeCalled();
  });
  it("handles missing heartbeat", () => {
    const channels = spoofChannels();
    channels.heartbeat = undefined;
    enchannel.shutdownRequest(channels);
    expect(channels.shell.complete).toBeCalled();
    expect(channels.iopub.complete).toBeCalled();
    expect(channels.stdin.complete).toBeCalled();
    expect(channels.control.complete).toBeCalled();
  });
  it("sends shutdownRequest but doesn't close channels", () => {
    const channels = spoofChannels();
    enchannel.shutdownRequest(channels, true);
    expect(channels.shell.complete).not.toBeCalled();
    expect(channels.iopub.complete).not.toBeCalled();
    expect(channels.stdin.complete).not.toBeCalled();
    expect(channels.control.complete).not.toBeCalled();
    expect(channels.heartbeat.complete).not.toBeCalled();
  });
});
