From f0aba49dd4c5f844625f0517cdf3cb2adf4313d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ben=20Z=C3=B6rb?= Date: Mon, 19 Mar 2018 23:50:05 +0100 Subject: [PATCH] Allow external stylesheets passed as css option [#290] --- lib/core.js | 7 +++++-- test/03-cli.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/core.js b/lib/core.js index 1591195e..b98348fb 100644 --- a/lib/core.js +++ b/lib/core.js @@ -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 diff --git a/test/03-cli.js b/test/03-cli.js index 62e07492..86254ba4 100644 --- a/test/03-cli.js +++ b/test/03-cli.js @@ -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', () => {