HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/alq-cali.bikenow.co/node_modules/gulp-shell/test/index.js
/* eslint-env mocha */

const expect = require('chai').expect
const join = require('path').join
const Vinyl = require('vinyl')

const shell = require('..')

function expectToBeOk (stream, done) {
  stream.on('error', done).on('data', () => {
    done()
  })
}

describe('gulp-shell(commands, options)', () => {
  const fakeFile = new Vinyl({
    cwd: __dirname,
    base: __dirname,
    path: join(__dirname, 'test-file')
  })

  it('throws when `commands` is missing', () => {
    expect(shell).to.throw('Missing commands')
  })

  it('works when `commands` is a string', () => {
    expect(shell.bind(null, 'true')).to.not.throw()
  })

  it('passes file through', done => {
    const stream = shell(['true'])

    stream.on('data', file => {
      expect(file).to.equal(fakeFile)
      done()
    })

    stream.write(fakeFile)
  })

  it('executes command after interpolation', done => {
    const stream = shell([`test <%= file.path %> = ${fakeFile.path}`])

    expectToBeOk(stream, done)

    stream.write(fakeFile)
  })

  it('prepends `./node_modules/.bin` to `PATH`', done => {
    const stream = shell(
      [`echo $PATH | grep -q "${join(process.cwd(), 'node_modules/.bin')}"`],
      { shell: 'bash' }
    )

    expectToBeOk(stream, done)

    stream.write(fakeFile)
  })

  describe('.task(commands, options)', () => {
    it('returns a function which returns a callback', done => {
      const task = shell.task(['echo hello world'])

      expect(task).to.be.a('function')

      task(done)
    })
  })

  describe('options', () => {
    describe('cwd', () => {
      it('sets the current working directory when `cwd` is a string', done => {
        const stream = shell([`test $PWD = ${join(__dirname, '../..')}`], {
          cwd: '..'
        })

        expectToBeOk(stream, done)

        stream.write(fakeFile)
      })

      it('uses the process current working directory when `cwd` is not passed', done => {
        const stream = shell([`test $PWD = ${join(__dirname, '..')}`])

        expectToBeOk(stream, done)

        stream.write(fakeFile)
      })
    })

    describe('shell', () => {
      it('changes the shell', done => {
        const stream = shell(['[[ $0 = bash ]]'], { shell: 'bash' })

        expectToBeOk(stream, done)

        stream.write(fakeFile)
      })
    })

    describe('quiet', () => {
      it("won't output anything when `quiet` == true", done => {
        const stream = shell(['echo cannot see me!'], { quiet: true })

        expectToBeOk(stream, done)

        stream.write(fakeFile)
      })
    })

    describe('ignoreErrors', () => {
      it('emits error by default', done => {
        const stream = shell(['false'])

        stream.on('error', () => {
          done()
        })

        stream.write(fakeFile)
      })

      it("won't emit error when `ignoreErrors` == true", done => {
        const stream = shell(['false'], { ignoreErrors: true })

        stream.on('error', () => {
          throw new Error()
        })

        stream.on('data', () => {
          done()
        })

        stream.write(fakeFile)
      })
    })

    describe('errorMessage', () => {
      it('allows for custom messages', done => {
        const errorMessage = 'foo'
        const stream = shell(['false'], { errorMessage })

        stream.on('error', error => {
          expect(error.message).to.equal(errorMessage)
          done()
        })

        stream.write(fakeFile)
      })

      it('includes the error object in the error context', done => {
        const errorMessage = 'Foo <%= error.code %>'
        const expectedMessage = 'Foo 2'
        const stream = shell(['exit 2'], { errorMessage })

        stream.on('error', error => {
          expect(error.message).to.equal(expectedMessage)
          done()
        })

        stream.write(fakeFile)
      })
    })
  })
})