-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
Target localhost by default if $PORT is set, closes #146. #147
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1febec9
Target localhost by default if $PORT is set, closes #146.
goto-bus-stop 2e9d5b0
Throw if URL is invalid and `PORT` is not available.
goto-bus-stop e89133e
Exit CLI if URL is not available.
goto-bus-stop 39afa7d
Switch URL existence check and validation
goto-bus-stop 4ea63b1
Add documentation line for PORT env var.
goto-bus-stop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,61 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const split = require('split2') | ||
const path = require('path') | ||
const childProcess = require('child_process') | ||
const helper = require('./helper') | ||
|
||
const lines = [ | ||
/Running 1s test @ .*$/, | ||
/10 connections.*$/, | ||
/$/, | ||
/Stat.*Avg.*Stdev.*Max.*$/, | ||
/Latency \(ms\).*$/, | ||
/Req\/Sec.*$/, | ||
/Bytes\/Sec.*$/, | ||
/$/, | ||
/.* requests in \d+s, .* read/ | ||
] | ||
|
||
t.plan(lines.length * 2 + 2) | ||
|
||
const server = helper.startServer() | ||
const port = server.address().port | ||
const url = '/path' // no hostname | ||
|
||
const child = childProcess.spawn(process.execPath, [path.join(__dirname, '..'), '-d', '1', url], { | ||
cwd: __dirname, | ||
env: Object.assign({}, process.env, { | ||
PORT: port | ||
}), | ||
stdio: ['ignore', 'pipe', 'pipe'], | ||
detached: false | ||
}) | ||
|
||
t.tearDown(() => { | ||
child.kill() | ||
}) | ||
|
||
child | ||
.stderr | ||
.pipe(split()) | ||
.on('data', (line) => { | ||
const regexp = lines.shift() | ||
t.ok(regexp, 'we are expecting this line') | ||
t.ok(regexp.test(line), 'line matches ' + regexp) | ||
}) | ||
.on('end', () => { | ||
t.ok(server.autocannonConnects > 0, 'targeted the correct port') | ||
}) | ||
|
||
const noPortChild = childProcess.spawn(process.execPath, [path.join(__dirname, '..'), url], { | ||
cwd: __dirname, | ||
env: process.env, | ||
stdio: ['ignore', 'pipe', 'pipe'], | ||
detached: false | ||
}) | ||
|
||
noPortChild.on('exit', (code) => { | ||
t.equal(code, 1, 'should exit with error when a hostless URL is passed and no PORT var is available') | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you throw an error if
URL
is not available?