text: /*!
   * Copyright (c) 2015-2017 Cisco Systems, Inc. See LICENSE file.
   */
  
  const fs = require(`fs`);
  const exists = require(`./lib/exists`);
  const {pidFile} = require(`./lib/paths`);
  const spawn = require(`./lib/spawn`);
  
  Promise.resolve()
    .then(() => {
      const pid = parseInt(fs.readFileSync(pidFile), 10);
      return spawn(`kill`, [`-TERM`, pid]);
    })
    .then(() => new Promise((resolve, reject) => {
    // eslint-disable-next-line prefer-const
      let interval;
      const timeout = setTimeout(() => {
        clearInterval(interval);
        reject(`Failed to disconnect from Sauce Labs`);
      }, 60000);
  
      interval = setInterval(() => {
        clearTimeout(timeout);
        if (!exists(pidFile)) {
          clearInterval(interval);
          resolve();
        }
      }, 1000);
    }))
    .catch((reason) => {
      console.error(reason.stack);
      process.exit(1);
    });
  