import { expect } from 'aegir/utils/chai.js';
import {
  getDescribe,
  getIt
} from '../utils/mocha.js';
import { isWebWorker } from 'ipfs-utils/src/env.js';
import { ipfsOptionsWebsocketsFilterAll } from '../utils/ipfs-options-websockets-filter-all.js';
export function testConnect(factory, options) {
  const ipfsOptions = ipfsOptionsWebsocketsFilterAll();
  const describe = getDescribe(options);
  const it = getIt(options);
  describe('.swarm.connect', function () {
    this.timeout(80 * 1000);
    let ipfsA;
    let ipfsB;
    let ipfsBId;
    before(async () => {
      ipfsA = (await factory.spawn({
        type: 'proc',
        ipfsOptions
      })).api;
      ipfsB = (await factory.spawn({ type: isWebWorker ? 'go' : undefined })).api;
      ipfsBId = await ipfsB.id();
    });
    after(() => factory.clean());
    it('should connect to a peer', async () => {
      let peers;
      peers = await ipfsA.swarm.peers();
      expect(peers).to.have.length(0);
      await ipfsA.swarm.connect(ipfsBId.addresses[0]);
      peers = await ipfsA.swarm.peers();
      expect(peers).to.have.length.above(0);
    });
  });
}