/
00-html.js
87 lines (77 loc) · 1.9 KB
/
00-html.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
80
81
82
83
84
85
86
87
var tiny = require('tiny-json-http')
var cp = require('fs').copyFileSync
var join = require('path').join
var mkdir = require('mkdirp')
var test = require('tape')
var sandbox = require('../../src/sandbox').http
var db = require('../../src/sandbox').db
var client
var server
var port = process.env.PORT
test('setup', t=> {
t.plan(1)
mkdir('test/sandbox/_mock')
cp('test/sandbox/00-mock.arc', 'test/sandbox/_mock/.arc')
mkdir('test/sandbox/_mock/src')
mkdir('test/sandbox/_mock/src/json')
mkdir('test/sandbox/_mock/src/html')
mkdir('test/sandbox/_mock/src/json/get-api')
mkdir('test/sandbox/_mock/src/html/get-index')
cp('test/sandbox/00-get-index-mock.js', 'test/sandbox/_mock/src/html/get-index/index.js')
cp('test/sandbox/00-get-api-mock.js', 'test/sandbox/_mock/src/json/get-api/index.js')
process.chdir('test/sandbox/_mock')
t.ok(true, 'created test/_mock/.arc')
console.log(process.cwd())
})
test('setup db server', t=> {
t.plan(1)
client = db.start(function() {
t.ok(true, 'started db @ localhost:5000')
})
})
test('setup web server', t=> {
t.plan(1)
server = sandbox.start(function() {
t.ok(true, `started server @ localhost:${port}`)
})
})
test('can read /', t=> {
t.plan(2)
tiny.get({
url: `http://localhost:${port}/`
},
function _got(err, data) {
if (err) {
t.fail(err)
console.log(err)
}
else {
t.ok(true, 'got /')
t.equals('hello world', data.body, 'is hello world')
console.log({data})
}
})
})
test('can read /hello.css', t=> {
t.plan(1)
console.log(process.cwd())
tiny.get({
url: `http://localhost:${port}/hello.css`
},
function _got(err, data) {
if (err) {
t.fail(err)
console.log(err)
}
else {
t.ok(true, 'got /hello.css')
console.log({data})
}
})
})
test('teardown', t=> {
t.plan(1)
server.close()
client.close()
t.ok(true, 'server closed')
})