/
test.js
109 lines (80 loc) · 2.67 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
(function() {
'use strict';
var Vinyl = require('vinyl'),
cssjanus = require('cssjanus'),
gulpCssjanus = require('./index'),
expect = require('chai').expect,
sinon = require('sinon');
describe('gulp-cssjanus', function () {
var cssjanusSpy;
beforeEach(function () {
cssjanusSpy = sinon.spy(cssjanus, 'transform');
});
afterEach(function () {
cssjanus.transform.restore();
});
it('should convert LTR CSS to RTL', function (done) {
var stream = gulpCssjanus();
stream.on('data', function (file) {
expect(file.contents.toString()).to.equal('.selector { float: right; /* comment */ }');
done();
});
stream.write(new Vinyl({
path: 'styles.css',
contents: new Buffer('.selector { float: left; /* comment */ }')
}));
});
it('should use cssjanus by default', function (done) {
var stream = gulpCssjanus();
stream.on('data', function (file) {
expect(cssjanusSpy.callCount).to.equal(1);
expect(cssjanusSpy.getCall(0).args).to.deep.equal([
'.selector { float: left; /* comment */ }', false, false
]);
done();
});
stream.write(new Vinyl({
path: 'styles.css',
contents: new Buffer('.selector { float: left; /* comment */ }')
}));
});
it('should accept cssjanus options', function (done) {
var stream = gulpCssjanus({
swapLtrRtlInUrl: true,
swapLeftRightInUrl: true
});
stream.on('data', function (file) {
expect(cssjanusSpy.callCount).to.equal(1);
expect(cssjanusSpy.getCall(0).args).to.deep.equal([
'.selector { float: left; /* comment */ }', true, true
]);
done();
});
stream.write(new Vinyl({
path: 'styles.css',
contents: new Buffer('.selector { float: left; /* comment */ }')
}));
});
it('should accept cssjanus options', function (done) {
var customCssjanus = { transform: sinon.spy(function() {
return 'xxx';
}) };
var stream = gulpCssjanus({
cssjanus: customCssjanus
});
stream.on('data', function (file) {
expect(cssjanusSpy.callCount).to.equal(0);
expect(customCssjanus.transform.callCount).to.equal(1);
expect(customCssjanus.transform.getCall(0).args).to.deep.equal([
'.selector { float: left; /* comment */ }', false, false
]);
expect(file.contents.toString()).to.equal('xxx');
done();
});
stream.write(new Vinyl({
path: 'styles.css',
contents: new Buffer('.selector { float: left; /* comment */ }')
}));
});
});
})();