-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: remove bluebird #436
fix: remove bluebird #436
Changes from all commits
2ff1aa5
dd0d197
3918e8a
7b927ac
1bf8164
c436cfd
be2be9a
e33e38e
161327f
529be0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import B from 'bluebird'; | ||
import path from 'path'; | ||
import * as path from 'path'; | ||
import {exec, SubProcess} from '../lib'; | ||
import {getFixture} from './helpers'; | ||
|
||
// Windows doesn't understand SIGHUP | ||
const stopSignal = process.platform === 'win32' ? 'SIGTERM' : 'SIGHUP'; | ||
|
||
/** | ||
* @param {number} ms | ||
*/ | ||
function delay(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
|
||
describe('SubProcess', function () { | ||
let chai; | ||
let chaiAsPromised; | ||
|
@@ -65,7 +72,7 @@ describe('SubProcess', function () { | |
lines = lines.concat(newLines); | ||
}); | ||
await subproc.start(0); | ||
await B.delay(50); | ||
await delay(50); | ||
lines.should.include('bad_exit.sh'); | ||
lines.should.contain('bigbuffer.js'); | ||
lines.should.contain('echo.sh'); | ||
|
@@ -116,7 +123,7 @@ describe('SubProcess', function () { | |
}); | ||
await s.start(0); | ||
hasData.should.be.false; | ||
await B.delay(1200); | ||
await delay(1200); | ||
hasData.should.be.true; | ||
}); | ||
it('should fail even with a start timeout of 0 when command is bad', async function () { | ||
|
@@ -154,14 +161,17 @@ describe('SubProcess', function () { | |
}); | ||
|
||
describe('listening for data', function () { | ||
/** | ||
* @type {SubProcess} | ||
*/ | ||
let subproc; | ||
afterEach(async function () { | ||
try { | ||
await subproc.stop(); | ||
} catch (ign) {} | ||
}); | ||
it('should get output as params', async function () { | ||
await new B(async (resolve, reject) => { | ||
await /** @type {Promise<void>} */(new Promise((resolve, reject) => { | ||
subproc = new SubProcess(getFixture('sleepyproc'), [ | ||
'ls', | ||
path.resolve(__dirname), | ||
|
@@ -173,21 +183,17 @@ describe('SubProcess', function () { | |
resolve(); | ||
} | ||
}); | ||
await subproc.start(); | ||
}).should.eventually.not.be.rejected; | ||
return subproc.start(); | ||
})).should.eventually.not.be.rejected; | ||
}); | ||
it('should get output as params', async function () { | ||
await new B(async (resolve, reject) => { | ||
subproc = new SubProcess(getFixture('echo'), ['foo', 'bar']); | ||
subproc.on('output', (stdout, stderr) => { | ||
if (stderr && stderr.indexOf('bar') === -1) { | ||
reject(); | ||
} else { | ||
resolve(); | ||
throw new Error(); | ||
} | ||
}); | ||
await subproc.start(); | ||
}); | ||
}); | ||
|
||
it('should get output by lines', async function () { | ||
|
@@ -197,7 +203,7 @@ describe('SubProcess', function () { | |
lines = lines.concat(newLines); | ||
}); | ||
await subproc.start(0); | ||
await B.delay(50); | ||
await delay(50); | ||
lines.should.eql([ | ||
'circular-buffer-specs.js', | ||
'exec-specs.js', | ||
|
@@ -210,22 +216,18 @@ describe('SubProcess', function () { | |
|
||
describe('#stop', function () { | ||
it('should send the right signal to stop a proc', async function () { | ||
return await new B(async (resolve, reject) => { | ||
let subproc = new SubProcess('tail', ['-f', path.resolve(__filename)]); | ||
const subproc = new SubProcess('tail', ['-f', path.resolve(__filename)]); | ||
|
||
await subproc.start(); | ||
|
||
subproc.on('exit', (code, signal) => { | ||
try { | ||
signal.should.equal(stopSignal); | ||
resolve(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this change works as expected in case of a failure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the old code it would reject a promise which would return an exception and fail the test. now it just throws directly and also stops the test, so there's virtually no difference:
|
||
} catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
|
||
await subproc.stop(stopSignal); | ||
}); | ||
}); | ||
|
||
|
||
it('should time out if stop doesnt complete fast enough', async function () { | ||
let subproc = new SubProcess(getFixture('traphup'), [ | ||
'tail', | ||
|
@@ -251,7 +253,7 @@ describe('SubProcess', function () { | |
let subproc = new SubProcess('ls'); | ||
await subproc.stop().should.eventually.be.rejectedWith(/Can't stop/); | ||
await subproc.start(); | ||
await B.delay(10); | ||
await delay(10); | ||
await subproc.stop().should.eventually.be.rejectedWith(/Can't stop/); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this change would create an uncaught exception failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried flipping the
if
statement and it stops the test, so the exception doesn't hang