Skip to content

Commit b9ffcef

Browse files
committed
test: Cover mocking non-zero exit codes
1 parent 8b4f5ef commit b9ffcef

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/shell.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ describe('sh mock mode', () => {
103103
const result = await sh('blah');
104104
expect(result).to.equal('');
105105
});
106+
107+
it('should make `sh` error if mock exit code is nonzero', async () => {
108+
sh.mock()
109+
.returns({
110+
exitCode: 1,
111+
stdout: 'here is some output',
112+
stderr: 'something went wrong',
113+
});
114+
115+
await expect(sh('fail')).to.eventually.be.rejectedWith(
116+
'Command failed: fail\nsomething went wrong',
117+
);
118+
});
106119
});
107120

108121
describe('matching mocks', () => {
@@ -143,6 +156,20 @@ describe('sh mock mode', () => {
143156
const result = await sh('a');
144157
expect(result).to.equal('');
145158
});
159+
160+
it('should make `sh` error if mock exit code is nonzero', async () => {
161+
sh.mock()
162+
.command('fail')
163+
.returns({
164+
exitCode: 1,
165+
stdout: 'here is some output',
166+
stderr: 'something went wrong',
167+
});
168+
169+
await expect(sh('fail')).to.eventually.be.rejectedWith(
170+
'Command failed: fail\nsomething went wrong',
171+
);
172+
});
146173
});
147174

148175
describe('assertDone', () => {

0 commit comments

Comments
 (0)