-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
118 lines (91 loc) · 2.59 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* istanbul ignore next */
describe('Finn', function () {
'use strict';
var Finn = require('./')
, assume = require('assume');
it('is exported as a function', function () {
assume(Finn).is.a('function');
});
it('can be constructed without new', function () {
var finn = Finn();
assume(finn).is.instanceOf(Finn);
assume(finn.render).is.a('function');
});
describe('#render', function () {
var css = '.foo { display: none }'
, finn;
beforeEach(function () {
finn = new Finn();
});
afterEach(function () {
finn.destroy();
});
it('renders the css output', function (next) {
finn.render(css, function (err, data) {
if (err) return next(err);
assume(data).is.a('object');
assume(data.css).is.a('string');
next();
});
});
it('includes a sourcemap', function (next) {
finn.render(css, {
source: 'finn.css',
sourcemap: true
}, function rendered(err, data) {
if (err) return next(err);
assume(data).is.a('object');
assume(data.css).is.a('string');
assume(data.css).includes('sourceMappingURL');
assume(data.map).is.a('object');
next();
});
});
it('receives errors from the middleware', function (next) {
finn.use(function (ast) {
assume(ast).is.a('object');
throw new Error('I should fail');
});
finn.render(css, function (err, data) {
assume(data).is.undefined();
assume(err.message).equals('I should fail');
next();
});
});
it('can add pre-processing', function (next) {
next = assume.plan(5, next);
finn
.pre.use(function (data) {
assume(data.css).equals('bar');
data.css = 'foo';
})
.pre.use(function (data) {
assume(data.css).equals('foo');
data.css = css;
});
finn.render('bar', function (err, data) {
if (err) return next(err);
assume(data).is.a('object');
assume(data.css).is.a('string');
assume(data.css).contains('.foo');
next();
});
});
it('can add pos-processing', function (next) {
next = assume.plan(4, next);
finn
.post.use(function (data) {
assume(data.css).contains('.foo');
data.css = 'foo';
data.bar = 'bar';
});
finn.render(css, function (err, data) {
if (err) return next(err);
assume(data).is.a('object');
assume(data.css).equals('foo');
assume(data.bar).equals('bar');
next();
});
});
});
});