How to use the execa.mockImplementationOnce 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 stashing changes if no lint-staged files are changed', async () => {
    expect.assertions(4)
    hasPartiallyStagedFiles.mockImplementationOnce(() => Promise.resolve(true))
    getStagedFiles.mockImplementationOnce(async () => ['sample.java'])
    execa.mockImplementationOnce(() =>
      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(0)
github okonet / lint-staged / test / runScript.spec.js View on Github external
it('should throw error for failed linters', async () => {
    expect.assertions(1)
    mockFn.mockImplementationOnce(() =>
      Promise.resolve({
        stdout: 'Mock error',
        stderr: '',
        code: 0,
        failed: true,
        cmd: 'mock cmd'
      })
    )

    const [linter] = runScript('mock-fail-linter', ['test.js'])
    try {
      await linter.task()
    } catch (err) {
      expect(err.privateMsg).toMatch(dedent`
        ${
          logSymbols.error