Skip to content

Commit

Permalink
Allow external stylesheets passed as css option [#290]
Browse files Browse the repository at this point in the history
  • Loading branch information
bezoerb committed Mar 19, 2018
1 parent 045096d commit f0aba49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/core.js
Expand Up @@ -55,8 +55,11 @@ function appendStylesheets(opts) {
return function (htmlfile) {
// Consider opts.css and map to array if it isn't one
if (opts.css) {
htmlfile.stylesheets = Array.isArray(opts.css) ? opts.css : [opts.css];
return htmlfile;
const css = Array.isArray(opts.css) ? opts.css : [opts.css];
return Bluebird.map(css, file.assertLocal).then(stylesheets => {
htmlfile.stylesheets = stylesheets;
return htmlfile;
});
}

// Oust extracts a list of your stylesheets
Expand Down
21 changes: 21 additions & 0 deletions test/03-cli.js
Expand Up @@ -173,6 +173,27 @@ describe('CLI', () => {
done();
});
});

it('should generate critical path css with external stylesheets passed as option', function (done) {
const cp = execFile('node', [
path.join(__dirname, '../', this.pkg.bin.critical),
`http://localhost:${serverport}`,
'--css', `http://localhost:${serverport}/styles/main.css`,
'--css', `http://localhost:${serverport}/styles/bootstrap.css`,
'--base', 'fixtures',
'--width', '1300',
'--height', '900'
]);

const expected = fs.readFileSync(path.join(__dirname, 'expected/generate-default.css'), 'utf8');
cp.stdout.on('data', data => {
if (data instanceof Buffer) {
data = data.toString('utf8');
}
assert.strictEqual(nn(data), nn(expected));
done();
});
});
});

describe('mocked', () => {
Expand Down

0 comments on commit f0aba49

Please sign in to comment.