-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c9d206
commit 1ba0732
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
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,8 @@ | ||
'use strict'; | ||
const http = require('http'); | ||
|
||
const server = http.createServer((request, response) => { | ||
response.end(); | ||
}); | ||
|
||
server.listen(process.argv.slice(2)[0]); |
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 |
---|---|---|
@@ -1,7 +1,37 @@ | ||
import childProcess from 'child_process'; | ||
import test from 'ava'; | ||
import execa from 'execa'; | ||
import delay from 'delay'; | ||
import noopProcess from 'noop-process'; | ||
import processExists from 'process-exists'; | ||
import getPort from 'get-port'; | ||
|
||
const noopProcessKilled = async (t, pid) => { | ||
// Ensure the noop process has time to exit | ||
await delay(100); | ||
t.false(await processExists(pid)); | ||
}; | ||
|
||
test(async t => { | ||
const {stdout} = await execa('./cli.js', ['--version']); | ||
t.true(stdout.length > 0); | ||
}); | ||
|
||
test('pid', async t => { | ||
const pid = await noopProcess(); | ||
await execa('./cli.js', ['--force', pid]); | ||
await noopProcessKilled(t, pid); | ||
}); | ||
|
||
test('kill from port', async t => { | ||
const port = await getPort(); | ||
const pid = childProcess.spawn('node', ['fixture.js', port]).pid; | ||
await execa('./cli.js', ['--force', pid]); | ||
await noopProcessKilled(t, pid); | ||
t.is(await getPort(port), port); | ||
}); | ||
|
||
test('error when process is not found', async t => { | ||
const err = await t.throws(execa('./cli.js', ['--force', 'notFoundProcess'])); | ||
t.regex(err.message, /Killing process notFoundProcess failed: Process doesn't exist/); | ||
}); |