How to use the execa.mockReturnValueOnce 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 nklayman / vue-cli-plugin-electron-builder / __tests__ / commands.spec.js View on Github external
const runSpectron = async (spectronOptions, launchOptions = {}) => {
    let sendData
    execa.mockReturnValueOnce({
      on: jest.fn(),
      stdout: {
        on: (event, callback) => {
          if (event === 'data') {
            // Save callback to be called later
            sendData = callback
          }
        }
      }
    })
    const testPromise = testWithSpectron(spectronOptions)
    // Mock console.log from electron:serve
    if (launchOptions.customLog) await sendData(launchOptions.customLog)
    await sendData(`$outputDir=${launchOptions.outputDir || 'dist_electron'}`)
    await sendData(
      `$WEBPACK_DEV_SERVER_URL=${launchOptions.url || 'http://localhost:8080/'}`