Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 })
})
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 })
})
{
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 })
})