-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
98 lines (80 loc) · 2 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict'
var test = require('tape')
var fs = require('fs')
var path = require('path')
var proxyquire = require('proxyquire')
var split = require('split2')
var concat = require('concat-stream')
var child = require('child_process')
var MP3 = path.resolve(__dirname, 'warning.mp3')
test('one warning', function (t) {
t.plan(2)
var WarningStream = proxyquire('./', {
'play-sound': () => ({
play: function (file, callback) {
t.equal(file, MP3)
callback()
}
})
})
fs
.createReadStream(path.resolve(__dirname, 'fixtures', 'one-warning.txt'))
.pipe(WarningStream())
.pipe(concat(function (data) {
t.equal(data.toString(), 'warning\n')
}))
})
test('one warn', function (t) {
t.plan(1)
var WarningStream = proxyquire('./', {
'play-sound': () => ({
play: function (file, callback) {
t.equal(file, MP3)
callback()
}
})
})
fs
.createReadStream(path.resolve(__dirname, 'fixtures', 'one-warn.txt'))
.pipe(WarningStream())
})
test('two warnings', function (t) {
t.plan(2)
var WarningStream = proxyquire('./', {
'play-sound': () => ({
play: function (file, callback) {
t.equal(file, MP3)
callback()
}
})
})
fs
.createReadStream(path.resolve(__dirname, 'fixtures', 'two-warnings.txt'))
.pipe(split())
.pipe(WarningStream())
})
test('no match', function (t) {
t.plan(0)
var WarningStream = proxyquire('./', {
'play-sound': () => ({
play: t.fail
})
})
fs
.createReadStream(path.resolve(__dirname, 'fixtures', 'no-match.txt'))
.pipe(WarningStream())
.on('finish', t.end)
})
if (!process.env.CI) {
test('cli', function (t) {
t.plan(1)
var cli = child.spawn('node', [path.resolve(__dirname, 'cli.js')])
fs
.createReadStream(path.resolve(__dirname, 'fixtures', 'one-warning.txt'))
.pipe(cli.stdin)
cli.stdout
.pipe(concat(function (data) {
t.equal(data.toString(), 'warning\n')
}))
})
}