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

Fix Tests & coverage #132

Merged
merged 4 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ node_js:
- 11
sudo: false
language: node_js
script: "npm run-script test-travis"
script: "npm run-script test-cov"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ async function send (ctx, path, opts = {}) {
encodingExt = '.gz'
}

if (extensions && !/\.[^/]*$/.exec(path)) {
if (extensions && !/\./.exec(basename(path))) {
const list = [].concat(extensions)
for (let i = 0; i < list.length; i++) {
let ext = list[i]
if (typeof ext !== 'string') {
throw new TypeError('option extensions must be array of strings or false')
}
if (!/^\./.exec(ext)) ext = '.' + ext
if (await fs.exists(path + ext)) {
path = path + ext
if (!/^\./.exec(ext)) ext = `.${ext}`
if (await fs.exists(`${path}${ext}`)) {
path = `${path}${ext}`
break
}
}
Expand All @@ -109,7 +109,7 @@ async function send (ctx, path, opts = {}) {
// so that you can do both `/directory` and `/directory/`
if (stats.isDirectory()) {
if (format && index) {
path += '/' + index
path += `/${index}`
stats = await fs.stat(path)
} else {
return
Expand All @@ -130,7 +130,7 @@ async function send (ctx, path, opts = {}) {
ctx.set('Content-Length', stats.size)
if (!ctx.response.get('Last-Modified')) ctx.set('Last-Modified', stats.mtime.toUTCString())
if (!ctx.response.get('Cache-Control')) {
const directives = ['max-age=' + (maxage / 1000 | 0)]
const directives = [`max-age=${(maxage / 1000 | 0)}`]
if (immutable) {
directives.push('immutable')
}
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"files": [
"index.js"
],
"nyc": {
"reporter": [
"lcov",
"text-summary"
],
"report-dir": "./coverage"
},
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
Expand All @@ -20,9 +27,9 @@
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"iltorb": "^2.3.2",
"istanbul": "^0.4.5",
"koa": "^2.5.1",
"mocha": "^5.2.0",
"nyc": "^15.0.0",
"should": "^13.2.1",
"supertest": "^3.1.0"
},
Expand All @@ -36,8 +43,7 @@
"scripts": {
"lint": "eslint --fix .",
"test": "mocha --require should --reporter spec --exit",
"test-cov": "istanbul cover ./node_modules/.bin/_mocha -- --require should --exit",
"test-travis": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- --require should --exit"
"test-cov": "nyc npm run test"
},
"engines": {
"node": ">= 7.6.0"
Expand Down