|
1 | 1 | import { expect } from 'chai'; |
2 | | -import type { ResultPromise } from 'execa'; |
| 2 | +import type { Options, Result, ResultPromise } from 'execa'; |
3 | 3 | import { promises as fs } from 'fs'; |
4 | 4 | import os from 'os'; |
5 | 5 | import { resolve } from 'path'; |
@@ -267,6 +267,44 @@ describe('LocalInstaller install', () => { |
267 | 267 | }); |
268 | 268 | }); |
269 | 269 |
|
| 270 | + describe('with concurrent', () => { |
| 271 | + beforeEach(() => { |
| 272 | + sut = new LocalInstaller( |
| 273 | + { '/a': ['c'], '/b': ['c'] }, |
| 274 | + { packageManager: 'npm', concurrent: 1 }, |
| 275 | + ); |
| 276 | + stubPackageJson({ |
| 277 | + '/a': 'a', |
| 278 | + '/b': 'b', |
| 279 | + c: 'c', |
| 280 | + }); |
| 281 | + helper.rmStub.resolves(); |
| 282 | + }); |
| 283 | + |
| 284 | + it('should install with the specified concurrency', async () => { |
| 285 | + const calls: ((res: Result<Options>) => void)[] = []; |
| 286 | + helper.execStub.callsFake((file, args) => { |
| 287 | + if(file === 'npm' && args?.includes('pack')) { |
| 288 | + return Promise.resolve(createExecaResult()) as ResultPromise; |
| 289 | + } |
| 290 | + return new Promise(res => { |
| 291 | + calls.push(res); |
| 292 | + }) as ResultPromise; |
| 293 | + }); |
| 294 | + |
| 295 | + const onGoingInstall = sut.install(); |
| 296 | + await tick(); |
| 297 | + await tick(); |
| 298 | + expect(calls).to.have.lengthOf(1); |
| 299 | + calls[0](createExecaResult()); |
| 300 | + await tick(); |
| 301 | + await tick(); |
| 302 | + expect(calls).to.have.lengthOf(2); |
| 303 | + calls[1](createExecaResult()); |
| 304 | + await onGoingInstall |
| 305 | + }); |
| 306 | + }); |
| 307 | + |
270 | 308 | describe('when readFile errors', () => { |
271 | 309 | it('should propagate the error', () => { |
272 | 310 | helper.readFileStub.rejects(new Error('file error')); |
@@ -320,3 +358,7 @@ describe('LocalInstaller install', () => { |
320 | 358 | }); |
321 | 359 | }; |
322 | 360 | }); |
| 361 | + |
| 362 | +function tick(): Promise<void> { |
| 363 | + return new Promise((res) => process.nextTick(res)); |
| 364 | +} |
0 commit comments