Skip to content

Commit

Permalink
chore: update test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed May 23, 2020
1 parent 0b6de8d commit 2b965cd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
},
"scripts": {
"pretest": "lerna bootstrap",
"test": "tape tests/*.js | tap-spec"
"test": "uvu tests"
},
"devDependencies": {
"lerna": "3.21.0",
"tap-spec": "^4.1.1",
"tape": "^4.8.0"
"uvu": "^0.0.10"
}
}
10 changes: 6 additions & 4 deletions tests/sirv-cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const test = require('tape');
const { test } = require('uvu');
const assert = require('uvu/assert');
const boot = require('../packages/sirv-cli/boot');

test('exports', t => {
t.is(typeof boot, 'function', 'exports a function');
t.end();
test('exports', () => {
assert.type(boot, 'function');
});

test.run();
50 changes: 19 additions & 31 deletions tests/sirv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const test = require('tape');
const sirv = require('../packages/sirv');
const { test } = require('uvu');
const assert = require('uvu/assert');
const { Writable } = require('stream');
const sirv = require('../packages/sirv');

function runMiddleware(fn, req) {
const out = {
Expand All @@ -26,47 +27,34 @@ function runMiddleware(fn, req) {
}).then(() => out);
}

test('exports', t => {
t.is(typeof sirv, 'function', 'exports a function');
t.end();
test('exports', () => {
assert.type(sirv, 'function');
});

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

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

t.plan(1)
runMiddleware(
sirv(__dirname),
request
)
.then(response => {
t.is(response.statusCode, 404);
t.end();
})
.catch(err => {
t.fail(err.message)
runMiddleware(handler, req).then(res => {
assert.is(res.statusCode, 404);
});
});

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

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

t.plan(1)
runMiddleware(
sirv(__dirname, { dev: true }),
request
)
.then(response => {
t.is(response.statusCode, 404);
t.end();
})
.catch(err => {
t.fail(err.message)
runMiddleware(handler, req).then(res => {
assert.is(res.statusCode, 404);
});
});

test.run();

0 comments on commit 2b965cd

Please sign in to comment.