Open dmwin72015 opened 7 years ago
I wrote next test:
it('should generate correct collected manifest file, even if f the name of the JS file contains “-”', function (cb) {
var stream = revCollector({
// collectedManifest: 'collectedManifest.json'
});
var fileCount = 0;
var revisionMap = {
"assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js"
};
var htmlFileBody = '<html><head><script src="/assets/js/com-mon.js"></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><script src="/assets/js/com-mon.js": "assets/js/common-2c0d21e40c.js"></head><body><img src="cdn/image.gif" /></body></html>';
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var fpath = file.path;
var contents = file.contents.toString('utf8');
var ext = path.extname(file.path);
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/assets\/js\/com-mon\.js/.test(contents),
'The JS file name should be replaced'
);
assert(
/assets\/js\/com-mon-2c0d21e40c.js/.test(contents),
'The JS file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
The replacement "assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js" works correctly. Give my, please, more information about problem...
gulp-rev-collector 1.2.2 Similar problems filename as a-c-12345678.css replace fail,modify filename as a.c.12345678.css replace success @shonny-ua
// https://github.com/shonny-ua/gulp-rev-collector/issues/32
it('should generate correct collected manifest file, even if f the name of the JS or CSS file contains “-”', function (cb) {
var stream = revCollector({
// collectedManifest: 'collectedManifest.json'
});
var fileCount = 0;
var revisionMap = {
"assets/js/com-mon.js": "assets/js/com-mon-2c0d21e40c.js",
"assets/css/a-c.css": "assets/css/a-c-12345678.css"
};
var htmlFileBody = '<html><head><script src="/assets/js/com-mon.js"><link rel="stylesheet" href="/assets/css/a-c.css" /></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><script src="/assets/js/com-mon-2c0d21e40c.js"><link rel="stylesheet" href="/assets/css/a-c-12345678.css" /></head><body><img src="cdn/image.gif" /></body></html>';
stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));
stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));
stream.on('data', function (file) {
var fpath = file.path;
var contents = file.contents.toString('utf8');
var ext = path.extname(file.path);
assert.equal(ext, '.html', 'Only html files should pass through the stream');
assert(
!/assets\/js\/com-mon\.js/.test(contents),
'The JS file name should be replaced'
);
assert(
!/assets\/css\/a-c\.css/.test(contents),
'The CSS file name should be replaced'
);
assert(
/assets\/js\/com-mon-2c0d21e40c\.js/.test(contents),
'The JS file name should be correct replaced'
);
assert(
/assets\/css\/a-c-12345678\.css/.test(contents),
'The CSS file name should be correct replaced'
);
fileCount++;
});
stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});
stream.end();
});
works correctly.
Give my, please, more information about problem!!!
Write, Please, content of rev-manifest.json
and html source files.
If the name of the JS file contains “-”, it will be not work