st 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,79 +1,73 @@
1
- var st = require('../st.js')
2
- var test = require('tap').test
3
- var util = require('util')
4
- var path = require('path')
1
+ const { test } = require('tap')
2
+ const path = require('path')
3
+ const st = require('../st.js')
5
4
 
6
- var opts = util._extend({
5
+ const opts = Object.assign({
7
6
  index: false,
8
7
  path: path.resolve(__dirname, './fixtures'),
9
8
  url: '/',
10
9
  passthrough: true
11
10
  }, global.options || {})
12
11
 
13
- var mount = st(opts)
12
+ const mount = st(opts)
14
13
 
15
- test('call next() if passthrough is set', function (t) {
16
- var req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
17
- var res = {
18
- error: function () {
19
- t.end()
20
- },
21
- setHeader: function () {},
22
- end: function () {}
14
+ test('call next() if passthrough is set', (t) => {
15
+ const req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
16
+ const res = {
17
+ error: () => t.end(),
18
+ setHeader: () => {},
19
+ end: () => {}
23
20
  }
24
21
  t.plan(2)
25
- mount(req, res, function () {
26
- t.ok(true, "next called with nonexistant file");
27
- req.url='/';
28
- mount(req, res, function () {
29
- t.ok(true, "next called without indexing")
22
+ mount(req, res, () => {
23
+ t.ok(true, 'next called with nonexistant file')
24
+ req.url = '/'
25
+ mount(req, res, () => {
26
+ t.ok(true, 'next called without indexing')
30
27
  t.end()
31
- });
28
+ })
32
29
  })
33
30
  })
34
31
 
35
- var opts2 = util._extend({
32
+ const opts2 = Object.assign({
36
33
  autoindex: true,
37
34
  path: path.resolve(__dirname, './fixtures'),
38
35
  url: '/'
39
36
  }, global.options || {})
40
- mount2 = st(opts2)
37
+ const mount2 = st(opts2)
41
38
 
42
- test('return error if passthrough is not set', function (t) {
43
- var req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
44
- var res = {
45
- setHeader: function () {},
46
- error: function () {
47
- t.ok(true, "error used")
39
+ test('return error if passthrough is not set', (t) => {
40
+ const req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
41
+ const res = {
42
+ setHeader: () => {},
43
+ error: () => {
44
+ t.ok(true, 'error used')
48
45
  t.end()
49
46
  },
50
- end: function () {}
47
+ end: () => {}
51
48
  }
52
49
  t.plan(1)
53
- mount2(req, res, function () {
50
+ mount2(req, res, () => {
54
51
  t.end()
55
52
  })
56
53
  })
57
54
 
58
- test('does not set headers if passthrough is set', function (t){
59
- var req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
60
- var res = {
61
- error: function () {
62
- t.end()
63
- },
55
+ test('does not set headers if passthrough is set', (t) => {
56
+ const req = { method: 'GET', url: '/doesnotexist.txt', headers: {} }
57
+ const res = {
58
+ error: () => t.end(),
64
59
  _headers: [],
65
- setHeader: function (header) {
60
+ setHeader: (header) => {
66
61
  res._headers.push(header)
67
62
  },
68
- end: function () {}
63
+ end: () => {}
69
64
  }
70
65
  t.plan(2)
71
- mount(req, res, function () {
72
-
66
+ mount(req, res, () => {
73
67
  t.notOk(res._headers.length, 'headers are not set on a non-existant file')
74
- req.url='/';
68
+ req.url = '/'
75
69
 
76
- mount(req, res, function () {
70
+ mount(req, res, () => {
77
71
  t.notOk(res._headers.length, 'headers are not set with no index')
78
72
  t.end()
79
73
  })
@@ -1,60 +1,64 @@
1
- var st = require('../st.js')
2
- var tap = require('tap')
3
- var test = require('tap').test
4
- var util = require('util')
5
- var path = require('path')
6
- var http = require('http')
7
- var request = require('request')
8
- var port = process.env.PORT || 1337
1
+ const st = require('../st.js')
2
+ const { test, tearDown } = require('tap')
3
+ const path = require('path')
4
+ const http = require('http')
5
+ const request = require('request')
6
+ const port = process.env.PORT || 1337
9
7
 
10
- var opts = util._extend({
8
+ const opts = Object.assign({
11
9
  index: false,
12
10
  path: path.dirname(__dirname),
13
11
  url: '/test'
14
12
  }, global.options || {})
15
13
 
16
- var mount = st(opts)
17
- var server
18
- var cacheControl = null
14
+ const mount = st(opts)
15
+ let server
16
+ let cacheControl = null
19
17
 
20
18
  function req (url, headers, cb) {
21
- if (typeof headers === 'function') cb = headers, headers = {}
22
- request({ encoding: null,
23
- url: 'http://localhost:' + port + url,
24
- headers: headers }, cb)
19
+ if (typeof headers === 'function') {
20
+ cb = headers
21
+ headers = {}
22
+ }
23
+ request({
24
+ encoding: null,
25
+ url: 'http://localhost:' + port + url,
26
+ headers: headers
27
+ }, cb)
25
28
  }
26
29
 
27
- tap.test('setup', function (t) {
28
- server = http.createServer(function (req, res) {
29
- if (cacheControl)
30
+ test('setup', (t) => {
31
+ server = http.createServer((req, res) => {
32
+ if (cacheControl) {
30
33
  res.setHeader('cache-control', cacheControl)
34
+ }
31
35
  if (!mount(req, res)) {
32
36
  res.statusCode = 404
33
37
  return res.end('Not a match: ' + req.url)
34
38
  }
35
- }).listen(port, function () {
39
+ }).listen(port, () => {
36
40
  t.pass('listening')
37
41
  t.end()
38
42
  })
39
43
  })
40
44
 
41
- tap.tearDown(function() {
45
+ tearDown(() => {
42
46
  server.close()
43
47
  })
44
48
 
45
- tap.test('simple request', function (t) {
49
+ test('simple request', (t) => {
46
50
  cacheControl = null
47
- req('/test/st.js', function (er, res, body) {
48
- t.ifError(er)
51
+ req('/test/st.js', (er, res, body) => {
52
+ t.error(er)
49
53
  t.equal(res.headers['cache-control'], 'public, max-age=600')
50
54
  t.end()
51
55
  })
52
56
  })
53
57
 
54
- tap.test('pre-set cache-control', function (t) {
58
+ test('pre-set cache-control', (t) => {
55
59
  cacheControl = 'I\'m so excited, and I just can\'t hide it'
56
- req('/test/st.js', function (er, res, body) {
57
- t.ifError(er)
60
+ req('/test/st.js', (er, res, body) => {
61
+ t.error(er)
58
62
  t.equal(res.headers['cache-control'], cacheControl)
59
63
  t.end()
60
64
  })
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- node_modules