forked from choojs/bankai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
79 lines (71 loc) · 2.14 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const getPort = require('get-server-port')
const browserify = require('browserify')
const concat = require('concat-stream')
const isHtml = require('is-html')
const http = require('http')
const test = require('tape')
const bankai = require('./')
test('html', function (t) {
t.test('returns data', function (t) {
t.plan(2)
const html = bankai.html()
const server = http.createServer(function (req, res) {
html(req, res).pipe(res)
})
server.listen()
http.get('http://localhost:' + getPort(server), function (res) {
res.pipe(concat({ string: true }, function (str) {
t.equal(res.headers['content-type'], 'text/html')
t.ok(isHtml(str), 'is html')
server.close()
}))
})
})
})
test('css', function (t) {
t.test('asserts input types', function (t) {
t.plan(1)
t.throws(bankai.css.bind(null, 'foo'), /object/)
})
t.test('returns data', function (t) {
t.plan(2)
const css = bankai.css({ basedir: __dirname })
bankai.js(browserify, './test/css.js')
const server = http.createServer(function (req, res) {
css(req, res).pipe(res)
})
server.listen()
process.nextTick(function () {
http.get('http://localhost:' + getPort(server), function (res) {
res.pipe(concat(function (buf) {
const str = String(buf)
t.equal(res.headers['content-type'], 'text/css')
console.log(str)
t.ok(/\.foo {}/.test(str), 'css is equal')
server.close()
}))
})
})
})
})
test('js', function (t) {
t.test('js asserts input types', function (t) {
t.plan(2)
t.throws(bankai.js, /browserify/)
t.throws(bankai.js.bind(null, browserify), /src/)
})
t.test('js returns data', function (t) {
t.plan(1)
const js = bankai.js(browserify, './test/fixture.js')
const server = http.createServer(function (req, res) {
js(req, res).pipe(res)
})
server.listen()
http.get('http://localhost:' + getPort(server), function (res) {
res.pipe(concat(function (buf) {
t.equal(res.headers['content-type'], 'application/javascript')
server.close()
}))
})
})
})