Skip to content
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

100% test coverage #16

Merged
merged 9 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
files:
- test/**/*.test.js

branches: 95
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ SendStream.prototype.error = function error (status, err) {
}

const res = this.res
const msg = statuses.message[status] || String(status)
const msg = statuses.message[status]
const doc = createHtmlDocument('Error', escapeHtml(msg))

// clear existing headers
Expand Down Expand Up @@ -474,10 +474,9 @@ SendStream.prototype.pipe = function pipe (res) {
if (containsDotFile(parts)) {
let access = this._dotfiles

// legacy support
if (access === undefined) {
access = parts[parts.length - 1][0] === '.'
? (this._hidden ? 'allow' : 'ignore')
? 'ignore'
: 'allow'
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
"test": "npm run test:unit && npm run test:typescript",
"test:coverage": "tap --coverage-report=html",
"test:typescript": "tsd",
"test:unit": "tap"
}
Expand Down
28 changes: 27 additions & 1 deletion test/send-pipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ test('send(file).pipe(res)', function (t) {
})

t.test('with conditional-GET', function (t) {
t.plan(6)
t.plan(7)

t.test('should remove Content headers with 304', function (t) {
t.plan(5)
Expand All @@ -657,6 +657,32 @@ test('send(file).pipe(res)', function (t) {
})
})

t.test('should remove Content headers with 304 /2', function (t) {
t.plan(5)

const server = createServer({ root: fixtures }, function (req, res) {
res.setHeader('Content-Language', 'en-US')
res.setHeader('Content-Location', 'http://localhost/name.txt')
res.setHeader('Contents', 'foo')
res.statusCode = 304
})

request(server)
.get('/name.txt')
.expect(304, function (err, res) {
t.error(err)
request(server)
.get('/name.txt')
.set('If-None-Match', res.headers.etag)
.expect(shouldNotHaveHeader('Content-Language', t))
.expect(shouldNotHaveHeader('Content-Length', t))
.expect(shouldNotHaveHeader('Content-Type', t))
.expect('Content-Location', 'http://localhost/name.txt')
.expect('Contents', 'foo')
.expect(304, err => t.error(err))
})
})

t.test('should not remove all Content-* headers', function (t) {
t.plan(4)

Expand Down
18 changes: 18 additions & 0 deletions test/statuses.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const { test } = require('tap')
const statuses = require('statuses')

test('statuses', function (t) {
t.plan(1)

t.test('should have uses statusCodes', function (t) {
t.plan(6)
t.ok(statuses(400))
t.ok(statuses(403))
t.ok(statuses(404))
t.ok(statuses(412))
t.ok(statuses(416))
t.ok(statuses(500))
})
})