forked from luhn/gulp-rev-css-url
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
79 lines (70 loc) · 3.1 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
var rev = require('gulp-rev');
var fs = require('fs');
var gulp = require('gulp');
var fse = require('fs-extra');
var override = require('./index');
var expect = require('chai').expect;
var through = require('through2');
describe('gulp-rev-css-url', function () {
beforeEach(function (done) {
fse.remove('./results', done);
})
it('Should override urls in css and js', function (done) {
var expectedCSS = fs.readFileSync('./expected/styles.css', 'utf-8'),
expectedJs = fs.readFileSync('./expected/script.js', 'utf-8'),
expectedFont1 = fs.readFileSync('./expected/montserrat-light-webfont.woff', 'utf-8'),
expectedFont2 = fs.readFileSync('./expected/montserrat-light-webfont.woff2', 'utf-8'),
expectedManifest = require('./expected/rev-manifest.json', 'utf-8');
gulp.src('./fixtures/**/*')
.pipe(rev())
.pipe(override())
.pipe(gulp.dest('./results/'))
.pipe(rev.manifest())
.pipe(gulp.dest('./results/'))
.on('end', function () {
// load results
var css = fs.readFileSync('./results/styles/styles-d329971534.css', 'utf-8'),
js = fs.readFileSync('./results/scripts/script-382f58fea6.js', 'utf-8'),
font1 = fs.readFileSync('./results/fonts/montserrat-light-webfont-b2f7c06e09.woff', 'utf-8'),
font2 = fs.readFileSync('./results/fonts/montserrat-light-webfont-86efde6016.woff2', 'utf-8'),
manifest = require('./results/rev-manifest.json', 'utf-8');
// check files' content
expect(css).to.equal(expectedCSS);
expect(js).to.equal(expectedJs);
expect(expectedFont1).to.equal(font1);
expect(expectedFont2).to.equal(font2);
// check manifest
expect(manifest).to.deep.equal(expectedManifest);
done();
});
});
it('Should not replace application/json with application.js', function(done) {
gulp.src('./fixtures/scripts/application.js')
.pipe(rev())
.pipe(override())
.pipe(gulp.dest('./results/'))
.on('end', function () {
var js = fs.readFileSync(
'./results/application-5c2dec9780.js',
'utf-8');
expect(js).to.contain('application/json');
done();
});
});
it('Should not reorder the pipeline', function (done) {
var outputOrder = [];
gulp.src(['./fixtures/scripts/script.js', './fixtures/scripts/application.js'])
.pipe(rev())
.pipe(override())
.pipe(through.obj(
function (file, enc, cb) {
outputOrder.push(file.revOrigPath.replace(file.revOrigBase, ''));
cb(null, file);
},
function (cb) {
expect(outputOrder).to.deep.equal(['script.js', 'application.js']);
done();
}
));
});
});