-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
64 lines (56 loc) · 1.4 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
const tap = require('tap')
const { spawn } = require('child_process')
process.argv.push('doge.png')
tap.test('Probably fine', t => {
require('./img2ascii')
t.pass('Test like a volkswagen.')
t.end()
})
tap.test('File load .png', t =>
require('./img2ascii')({
_: ['doge.png'],
c: 40,
cols: 40,
r: 0.8,
ratio: 0.8,
}).on('end', () => {
t.pass('Volkswagen')
t.end()
}).pipe(process.stdout))
tap.test('File load .jpg', t =>
require('./img2ascii')({
_: ['frost-doge.jpg'],
c: 40,
cols: 40
}).on('end', () => {
t.pass('Volkswagen')
t.end()
}).pipe(process.stdout))
tap.test('Load remote file', t => {
const http = require('http')
const port = process.env.PORT || 5397
const finalHandler = require('finalhandler')
const serveStatic = require('serve-static')
const serve = serveStatic('./')
const server = http
.createServer((req, res) =>
serve(req, res, finalHandler(req, res)))
.listen(port)
require('./img2ascii')({
_: [`http://127.0.0.1:${port}/frost-doge.jpg`],
c: 40,
cols: 40
}).on('end', () => {
server.close()
t.pass('Volkswagen')
t.end()
}).pipe(process.stdout)
})
tap.test('Not existing files .jpg', t =>
spawn('./bin.js', ['not-existing-file.jpg'])
.stderr
.on('data', (err) => {
t.pass('Finishes correctly with error', err.toString())
t.end()
})
.pipe(process.stdout))