mirror of
https://github.com/danog/inline-critical.git
synced 2024-11-30 04:29:07 +01:00
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
var expect = require('chai').expect,
|
|
fs = require('fs'),
|
|
inlineCritical = require('..');
|
|
|
|
/**
|
|
* Strip whitespaces, tabs and newlines and replace with one space.
|
|
* Usefull when comparing string contents.
|
|
* @param string
|
|
*/
|
|
function stripWhitespace(string) {
|
|
return string.replace(/[\r\n]+/mg,' ').replace(/\s+/gm,'');
|
|
}
|
|
|
|
describe('inline-critical', function() {
|
|
it('should inline css', function(done) {
|
|
var html = fs.readFileSync('test/fixtures/index.html', 'utf8');
|
|
var css = fs.readFileSync('test/fixtures/critical.css', 'utf8');
|
|
|
|
var expected = fs.readFileSync('test/fixtures/index-inlined-async-final.html', 'utf8');
|
|
var out = inlineCritical(html, css);
|
|
|
|
expect(stripWhitespace(out.toString('utf-8'))).to.be.equal(stripWhitespace(expected));
|
|
|
|
done();
|
|
});
|
|
|
|
|
|
it('should inline and minify css', function(done) {
|
|
var html = fs.readFileSync('test/fixtures/index.html', 'utf8');
|
|
var css = fs.readFileSync('test/fixtures/critical.css', 'utf8');
|
|
|
|
var expected = fs.readFileSync('test/fixtures/index-inlined-async-minified-final.html', 'utf8');
|
|
var out = inlineCritical(html, css, true);
|
|
|
|
expect(stripWhitespace(out.toString('utf-8'))).to.be.equal(stripWhitespace(expected));
|
|
|
|
done();
|
|
});
|
|
});
|