How to use the execa.mockImplementation function in execa

To help you get started, we’ve selected a few execa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github okonet / lint-staged / test / runAll.spec.js View on Github external
it('should skip updating stash if there are errors during linting', async () => {
    expect.assertions(4)
    hasPartiallyStagedFiles.mockImplementationOnce(() => Promise.resolve(true))
    getStagedFiles.mockImplementationOnce(async () => ['sample.js'])
    execa.mockImplementation(() =>
      Promise.resolve({
        stdout: '',
        stderr: 'Linter finished with error',
        code: 1,
        failed: true,
        cmd: 'mock cmd'
      })
    )

    try {
      await runAll({ config: { '*.js': ['echo "sample"'] } })
    } catch (err) {
      console.log(err)
    }
    expect(console.printHistory()).toMatchSnapshot()
    expect(gitStashSave).toHaveBeenCalledTimes(1)
github primer / deploy / src / __tests__ / now.js View on Github external
const execa = require('execa')
const mockedEnv = require('mocked-env')
const now = require('../now')

const {NOW_BIN} = now

jest.mock('execa')
execa.mockImplementation(() => Promise.resolve({stderr: '', stdout: ''}))

describe('now()', () => {
  let restoreEnv = () => {}
  afterEach(() => restoreEnv())

  it('throws if process.env.NOW_TOKEN is falsy', () => {
    mockEnv({NOW_TOKEN: ''})
    expect(() => now()).toThrow()
  })

  it('calls `npx now --token=$NOW_TOKEN` with no additional args', () => {
    mockEnv({NOW_TOKEN: 'xyz'})
    now()
    expect(execa).lastCalledWith(NOW_BIN, ['--token=xyz'], {stderr: 'inherit'})
  })
github primer / publish / src / __tests__ / publish.js View on Github external
beforeEach(() => {
    execa.mockImplementation(() => Promise.resolve({stdout: '', stderr: ''}))
    actionStatus.mockImplementation(() => Promise.resolve())
  })