2014-10-19 03:16:34 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-19 03:12:33 +02:00
|
|
|
var expect = require('chai').expect;
|
2014-10-20 16:44:53 +02:00
|
|
|
var reaver = require('reaver');
|
2014-10-19 03:12:33 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var inlineCritical = require('..');
|
|
|
|
|
|
|
|
function strip(string) {
|
|
|
|
return string.replace(/[\r\n]+/mg,' ').replace(/\s+/gm,'');
|
|
|
|
}
|
|
|
|
|
|
|
|
function read (file) {
|
|
|
|
return fs.readFileSync(file, 'utf8');
|
|
|
|
}
|
|
|
|
|
|
|
|
function write (file, data) {
|
|
|
|
fs.writeFileSync(file, data);
|
2014-08-04 00:01:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('inline-critical', function() {
|
2014-10-19 03:16:34 +02:00
|
|
|
it('should inline css', function(done) {
|
|
|
|
var html = read('test/fixtures/index.html');
|
|
|
|
var css = read('test/fixtures/critical.css');
|
2014-08-04 00:01:39 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
var expected = read('test/fixtures/index-inlined-async-final.html');
|
|
|
|
var out = inlineCritical(html, css);
|
2014-08-04 00:01:39 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
expect(strip(out.toString('utf-8'))).to.be.equal(strip(expected));
|
2014-08-04 00:01:39 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
done();
|
|
|
|
});
|
2014-08-04 00:01:39 +02:00
|
|
|
|
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
it('should inline and minify css', function(done) {
|
|
|
|
var html = read('test/fixtures/index.html');
|
|
|
|
var css = read('test/fixtures/critical.css');
|
2014-10-19 03:12:33 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
var expected = read('test/fixtures/index-inlined-async-minified-final.html');
|
|
|
|
var out = inlineCritical(html, css, { minify: true });
|
2014-10-19 03:12:33 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
expect(strip(out.toString('utf-8'))).to.be.equal(strip(expected));
|
2014-10-19 03:12:33 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
done();
|
|
|
|
});
|
2014-10-19 03:12:33 +02:00
|
|
|
|
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
it('should inline and extract css', function(done) {
|
|
|
|
var html = read('test/fixtures/cartoon.html');
|
|
|
|
var css = read('test/fixtures/critical.css');
|
2014-10-20 16:44:53 +02:00
|
|
|
var expected = read('test/fixtures/cartoon-expected.css');
|
2014-11-25 17:11:26 +01:00
|
|
|
var expectedHtml = read('test/fixtures/cartoon-expected.html');
|
2014-08-04 00:01:39 +02:00
|
|
|
|
2014-11-25 17:11:26 +01:00
|
|
|
var out = inlineCritical(html, css, { extract: true, basePath: 'test/fixtures' });
|
2014-08-04 00:01:39 +02:00
|
|
|
|
2014-11-25 17:11:26 +01:00
|
|
|
expect(read(reaver.rev('test/fixtures/css/cartoon.css', expected))).to.be.equal(expected);
|
|
|
|
expect(strip(out.toString('utf-8'))).to.be.equal(strip(expectedHtml));
|
2014-08-04 00:01:39 +02:00
|
|
|
|
2014-10-19 03:16:34 +02:00
|
|
|
done();
|
|
|
|
});
|
2014-08-04 00:01:39 +02:00
|
|
|
});
|