Skip to content

Commit

Permalink
Fix Tests & coverage (#132)
Browse files Browse the repository at this point in the history
*  fix the failed test case 🩺..

*  add coverage package + config & updated yarn.lock 📦 ..

*  change the script name 💢 ..

* remove yarn locks ❌ ..
  • Loading branch information
3imed-jaberi authored Feb 15, 2020
1 parent f56a959 commit 8d5955d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
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

0 comments on commit 8d5955d

Please sign in to comment.