Skip to content

Commit

Permalink
chore: remove Node 6.x test suite;
Browse files Browse the repository at this point in the history
- supporting tools use `async` syntax
  • Loading branch information
lukeed committed May 23, 2020
1 parent 5ea1761 commit 1a84c56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
nodejs: [6, 8, 10, 12]
nodejs: [8, 10, 12]
steps:
- uses: actions/checkout@master
with:
Expand All @@ -21,7 +21,7 @@ jobs:
- name: Install
run: |
npm install
npm install -g nyc@13
npm install -g nyc
- name: Test w/ Coverage
run: nyc --include=packages npm test
Expand Down
29 changes: 14 additions & 15 deletions tests/sirv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const assert = require('uvu/assert');
const { Writable } = require('stream');
const sirv = require('../packages/sirv');

function runMiddleware(fn, req) {
async function runMiddleware(fn, req) {
const out = {
headers: {},
statusCode: -1,
}
return new Promise((resolve, reject) => {

await new Promise((resolve, reject) => {
const res = new Writable({
write() {}
});
Expand All @@ -24,37 +25,35 @@ function runMiddleware(fn, req) {
Object.assign(out.headers, headers);
}
fn(req, res);
}).then(() => out);
});

return out;
}

test('exports', () => {
assert.type(sirv, 'function');
});

test('prevents directory traversal attacks :: prod', () => {
test('prevents directory traversal attacks :: prod', async () => {
const handler = sirv(__dirname, { dev: false });

const req = {
const res = await runMiddleware(handler, {
headers: {},
path: encodeURIComponent('../package.json'),
};

runMiddleware(handler, req).then(res => {
assert.is(res.statusCode, 404);
});

assert.is(res.statusCode, 404);
});

test('prevents directory traversal attacks :: dev', () => {
test('prevents directory traversal attacks :: dev', async () => {
const handler = sirv(__dirname, { dev: true });

const req = {
const res = await runMiddleware(handler, {
headers: {},
path: encodeURIComponent('../package.json'),
};

runMiddleware(handler, req).then(res => {
assert.is(res.statusCode, 404);
});

assert.is(res.statusCode, 404);
});

test.run();

0 comments on commit 1a84c56

Please sign in to comment.