Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): begin covering child process utils
- Loading branch information
Showing
8 changed files
with
75 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { mustExist, Optional } from '../../src/utils'; | ||
import { ChildStreams, waitForChild } from '../../src/utils/Child'; | ||
import { describeLeaks, itLeaks } from '../helpers/async'; | ||
import { ChildProcessError } from '../../src'; | ||
|
||
type Closer = (status: number) => Promise<void>; | ||
|
||
function createChild(): ChildStreams & { closer: Optional<Closer> } { | ||
return { | ||
closer /* Optional<Closer> */ : undefined, | ||
on(event: string, fn: Closer) { | ||
if (event === 'close') { | ||
this.closer = fn; | ||
} | ||
}, | ||
stderr: { | ||
on() { | ||
/* noop */ | ||
}, | ||
}, | ||
stdout: { | ||
on() { | ||
/* noop */ | ||
}, | ||
}, | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
} as any; | ||
} | ||
|
||
describeLeaks('child process utils', async () => { | ||
describeLeaks('wait for child helper', async () => { | ||
itLeaks('should read stdout data', async () => { | ||
const child = createChild(); | ||
|
||
const resultPromise = waitForChild(child); | ||
await mustExist(child.closer)(0); | ||
|
||
const result = await resultPromise; | ||
expect(result.status).to.equal(0); | ||
}); | ||
|
||
itLeaks('should read stderr data'); | ||
itLeaks('should resolve on success status'); | ||
|
||
itLeaks('should reject on failure status', async () => { | ||
const child = createChild(); | ||
|
||
const resultPromise = waitForChild(child); | ||
await mustExist(child.closer)(1); | ||
|
||
return expect(resultPromise).to.eventually.be.rejectedWith(ChildProcessError); | ||
}); | ||
}); | ||
}); |