forked from callumacrae/rev-del
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
133 lines (108 loc) · 2.78 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
var path = require('path');
var _ = require('lodash');
var File = require('vinyl');
var revDel = require('./');
var should = require('should');
var oldManifest = {
'foo.js': 'foo-abc.js',
'bar.js': 'bar-abc.js',
'hello': 'world'
};
var newManifest = {
'foo.js': 'foo-def.js',
'bar.js': 'bar-abc.js',
'hello': 'world2'
};
var manifests = {
oldManifest: oldManifest,
newManifest: newManifest,
delFn: function (files, options, cb) {
cb(null, files);
}
};
it('should work out which files to delete', function (cb) {
revDel(manifests, function (err, files) {
files.length.should.equal(2);
files.should.eql(['foo-abc.js', 'world']);
cb();
});
});
it('should read from JSON files', function (cb) {
var manifestsString = _.clone(manifests);
manifestsString.oldManifest = 'test.json';
revDel(manifestsString, function (err, files) {
files.length.should.equal(2);
files.should.eql(['foo-abc.js', 'world']);
cb();
});
});
it('should handle streams', function (cb) {
var stream = revDel({
oldManifest: 'test.json',
delFn: function (files, options, cb) {
cb(null, files);
}
});
stream.on('data', function (file) {
file.revDeleted.length.should.equal(2);
file.revDeleted.should.eql(['foo-abc.js', 'world']);
cb();
});
stream.write(new File({
contents: new Buffer(JSON.stringify(newManifest))
}));
stream.end();
});
it('should get the file path from gulp-rev', function (cb) {
var stream = revDel({
delFn: function (files, options, cb) {
cb(null, files);
}
});
stream.on('data', function (file) {
file.revDeleted.length.should.equal(2);
file.revDeleted.should.eql(['foo-abc.js', 'world']);
cb();
});
stream.write(new File({
path: 'test.json',
contents: new Buffer(JSON.stringify(newManifest))
}));
stream.end();
});
it('should not explode when rev-manifest.json is not found', function (cb) {
var manifestsString = _.clone(manifests);
manifestsString.oldManifest = 'doesntexist.json';
// We're literally just testing that it doesn't throw an error
revDel(manifestsString, function () {
cb();
});
});
it('should explode when suppress is set to false says to', function () {
var manifestsString = _.clone(manifests);
manifestsString.oldManifest = 'doesntexist.json';
manifestsString.suppress = false;
should.throws(function () {
revDel(manifestsString, function () {});
});
});
it('should accept dest', function (cb) {
var stream = revDel({
delFn: function (files, options, cb) {
cb(null, files);
},
dest: 'test',
oldManifest: 'test.json'
});
stream.on('data', function (file) {
file.revDeleted.length.should.equal(2);
file.revDeleted.should.eql(['test/foo-abc.js', 'test/world']);
cb();
});
stream.write(new File({
path: 'test.json',
contents: new Buffer(JSON.stringify(newManifest))
}));
stream.end();
});