Skip to content

Commit

Permalink
fix error when referencing a css file directly (#27)
Browse files Browse the repository at this point in the history
* fix error when referencing a css file directly

* hey computer plz run all tests

* hey computer plz run all tests

Co-authored-by: Bart Veneman <[email protected]>
  • Loading branch information
bartveneman and bartveneman committed Mar 9, 2020
1 parent 776e315 commit 5562fcb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions test/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}'
Binary file modified test/snapshots/index.js.snap
Binary file not shown.

0 comments on commit 5562fcb

Please sign in to comment.