How to use the p-map.mock function in p-map

To help you get started, we’ve selected a few p-map 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 / resolveTaskFn-chunked.spec.js View on Github external
it('should respect chunk size and concurrency', async () => {
      expect.assertions(6)

      const taskFn = resolveTaskFn({
        ...defaultOpts,
        pathsToLint: ['test1.js', 'test2.js'],
        subTaskConcurrency: 2
      })
      await taskFn()
      const [[chunks, mapper]] = pMap.mock.calls
      expect(mapper).toBeInstanceOf(Function)
      expect(pMap).toHaveBeenCalledWith([['test1.js'], ['test2.js']], mapper, { concurrency: 2 })

      // Check that calling the mapper invokes execa
      const [c1, c2] = chunks
      await mapper(c1)
      expect(execa).toHaveBeenCalledTimes(1)
      expect(execa).lastCalledWith('test', ['test1.js'], { reject: false })
      await mapper(c2)
      expect(execa).toHaveBeenCalledTimes(2)
      expect(execa).lastCalledWith('test', ['test2.js'], { reject: false })
    })
github okonet / lint-staged / test / resolveTaskFn-chunked.spec.js View on Github external
it('should invoke execa in mapper function', async () => {
      expect.assertions(3)

      const taskFn = resolveTaskFn({ ...defaultOpts })
      await taskFn()
      const [[[chunk], mapper]] = pMap.mock.calls
      expect(pMap).toHaveBeenCalledWith([['test.js']], mapper, { concurrency: 1 })
      await mapper(chunk)
      expect(execa).toHaveBeenCalledTimes(1)
      expect(execa).toHaveBeenCalledWith('test', ['test.js'], { reject: false })
    })
github okonet / lint-staged / test / runScript-mock-pMap.spec.js View on Github external
{
          stdout: 'a-ok',
          stderr: '',
          code: 0,
          failed: false,
          cmd: 'mock cmd'
        }
      ])
    )

    const [linter] = runScript(['test'], ['test1.js', 'test2.js'], {
      chunkSize: 1,
      subTaskConcurrency: 1
    })
    await linter.task()
    const [[, mapper]] = pMapMock.mock.calls
    expect(mapper).toBeInstanceOf(Function)
    expect(pMapMock).toHaveBeenCalledWith([['test1.js'], ['test2.js']], mapper, { concurrency: 1 })
  })

p-map

Map over promises concurrently

MIT
Latest version published 29 days ago

Package Health Score

85 / 100
Full package analysis