text: /*global describe, it */
  
  var partty = require('../');
  var assert = require('assert');
  
  var tests = [
    {
      name: 'should be correctly setup',
      command: [ 'children/void.js' ],
      options: { cwd: __dirname },
      test: function() {
        assert.equal(this.file, process.execPath);
      }
    }, {
      name: 'should support stdin',
      command: [ 'children/stdin.js' ],
      options: { cwd: __dirname },
      test: function() {
        this.write('☃');
      }
    }, {
      name: 'should support resize',
      command: [ 'children/resize.js' ],
      options: { cwd: __dirname },
      test: function() {
        this.resize(100, 100);
      }
    }, {
      name: 'should change uid/gid',
      command: [ 'children/uidgid.js' ],
      options: { cwd: __dirname, uid: 777, gid: 777 },
      test: function() {}
    }
  ];
  
  describe('partty', function() {
    tests.forEach(function(testCase) {
      if (testCase.options.uid && testCase.options.gid && (process.platform === 'win32' || process.getgid() !== 0)) {
        // Skip tests that contains user impersonation if we are not able to do so.
        return it.skip(testCase.name);
      }
      it(testCase.name, function(done) {
        var term = partty.fork(process.execPath, testCase.command, testCase.options);
        term.pipe(process.stderr);
  
        // any output is considered failure. this is only a workaround
        // until the actual error code is passed through
        var count = 0;
        term.on('data', function(/* data */) {
          count++;
        });
        term.on('exit', function() {
          // XXX Temporary until we find out why this gets emitted twice:
          if (done.done) {
            return;
          }
          done.done = true;
  
          assert.equal(count, 0);
          done();
        });
  
        // Wait for partty to be ready
        setTimeout(testCase.test.bind(term), 1000);
      });
    });
  });
  