Skip to content

Commit

Permalink
Merge pull request #77 from feross/gh-actions
Browse files Browse the repository at this point in the history
Add GitHub Actions CI
  • Loading branch information
LinusU committed Mar 17, 2022
2 parents 2cf41cd + 91f7557 commit 498f8d5
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Node CI

on:
pull_request:
branches:
- master

jobs:
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
node: [10.0.0, 12.0.0, 14.0.0, 16.0.0]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules/
yarn.lock
package-lock.json
/node_modules/
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"string-to-stream": "^3.0.0",
"tape": "^5.0.0"
},
"engines": {
"node": ">=10"
},
"files": [
"index.js"
],
"homepage": "https://github.com/feross/simple-get",
"keywords": [
"request",
Expand Down
46 changes: 46 additions & 0 deletions test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,49 @@ test('basic auth', function (t) {
})
})
})

test('basic auth + host', function (t) {
t.plan(5)

const server = http.createServer(function (req, res) {
t.equal(req.headers.authorization, 'Basic Zm9vOmJhcg==')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
const port = server.address().port
get({ auth: 'foo:bar', host: 'localhost', port }, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
concat(res, function (err, data) {
t.error(err)
t.equal(data.toString(), 'response')
server.close()
})
})
})
})

test('basic auth + hostname', function (t) {
t.plan(5)

const server = http.createServer(function (req, res) {
t.equal(req.headers.authorization, 'Basic Zm9vOmJhcg==')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
const port = server.address().port
get({ auth: 'foo:bar', hostname: 'localhost', port }, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
concat(res, function (err, data) {
t.error(err)
t.equal(data.toString(), 'response')
server.close()
})
})
})
})
23 changes: 23 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ test('rewrite POST redirects to GET', function (t) {
})
})
})

test('simple get hostname + url', function (t) {
t.plan(5)

const server = http.createServer(function (req, res) {
t.equal(req.url, '/path')
res.statusCode = 200
res.end('response')
})

server.listen(0, function () {
const port = server.address().port
get({ host: 'localhost', port, url: '/path' }, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
concat(res, function (err, data) {
t.error(err)
t.equal(data.toString(), 'response')
server.close()
})
})
})
})
32 changes: 32 additions & 0 deletions test/redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,35 @@ test('redirect should clear explicitly specified `Host` (note uppercase) header'
})
})
})

test('follow redirects without "url" option', function (t) {
t.plan(15)

let num = 0
const server = http.createServer(function (req, res) {
t.equal(req.url, '/' + num, 'visited /' + num)

if (num < 10) {
num += 1
res.statusCode = 301
res.setHeader('Location', '/' + num)
res.end()
} else {
res.statusCode = 200
res.end('response')
}
})

server.listen(0, function () {
const port = server.address().port
get({ hostname: 'localhost', port, path: '/0' }, function (err, res) {
t.error(err)
t.equal(res.statusCode, 200)
concat(res, function (err, data) {
t.error(err)
t.equal(data.toString(), 'response')
server.close()
})
})
})
})

0 comments on commit 498f8d5

Please sign in to comment.