diff --git a/src/index.js b/src/index.js index c17fc6a..546f9cd 100644 --- a/src/index.js +++ b/src/index.js @@ -36,6 +36,14 @@ module.exports = async (url, {waitUntil = 'networkidle0'} = {}) => { ) } + // If the response is a CSS file, return that file + // instead of running our complicated setup + const headers = response.headers() + + if (headers['content-type'].includes('text/css')) { + return Promise.resolve(response.text()) + } + const coverage = await page.coverage.stopCSSCoverage() // Get all CSS generated with the CSSStyleSheet API diff --git a/test/index.js b/test/index.js index fc8681c..0fe24b6 100644 --- a/test/index.js +++ b/test/index.js @@ -84,6 +84,13 @@ test('it finds inline styles - JS', async t => { t.snapshot(actual) }) +test('it returns a direct link to a CSS file', async t => { + const actual = await extractCss(server.url + '/import-in-css.css') + + t.true(actual.includes('.css-imported-with-css {}')) + t.snapshot(actual) +}) + test('it rejects if the url has an HTTP error status', async t => { server.get('/404-page', (req, res) => { res.status(404).send() diff --git a/test/snapshots/index.js.md b/test/snapshots/index.js.md index 69c6d1b..3d93769 100644 --- a/test/snapshots/index.js.md +++ b/test/snapshots/index.js.md @@ -78,3 +78,9 @@ Generated by [AVA](https://ava.li). `[x-extract-css-inline-style] { color: red; font-size: 12px; border-style: solid; }␊ [x-extract-css-inline-style] { border-color: blue; border-width: 1px; }` + +## it returns a direct link to a CSS file + +> Snapshot 1 + + '.css-imported-with-css {}' diff --git a/test/snapshots/index.js.snap b/test/snapshots/index.js.snap index 70c133c..fd6263a 100644 Binary files a/test/snapshots/index.js.snap and b/test/snapshots/index.js.snap differ