Skip to content

Commit 5562fcb

Browse files
authored
fix error when referencing a css file directly (#27)
* 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 <bartveneman@users.noreply.github.com>
1 parent 776e315 commit 5562fcb

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ module.exports = async (url, {waitUntil = 'networkidle0'} = {}) => {
3636
)
3737
}
3838

39+
// If the response is a CSS file, return that file
40+
// instead of running our complicated setup
41+
const headers = response.headers()
42+
43+
if (headers['content-type'].includes('text/css')) {
44+
return Promise.resolve(response.text())
45+
}
46+
3947
const coverage = await page.coverage.stopCSSCoverage()
4048

4149
// Get all CSS generated with the CSSStyleSheet API

test/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ test('it finds inline styles - JS', async t => {
8484
t.snapshot(actual)
8585
})
8686

87+
test('it returns a direct link to a CSS file', async t => {
88+
const actual = await extractCss(server.url + '/import-in-css.css')
89+
90+
t.true(actual.includes('.css-imported-with-css {}'))
91+
t.snapshot(actual)
92+
})
93+
8794
test('it rejects if the url has an HTTP error status', async t => {
8895
server.get('/404-page', (req, res) => {
8996
res.status(404).send()

test/snapshots/index.js.md

+6
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ Generated by [AVA](https://ava.li).
7878
7979
`[x-extract-css-inline-style] { color: red; font-size: 12px; border-style: solid; }␊
8080
[x-extract-css-inline-style] { border-color: blue; border-width: 1px; }`
81+
82+
## it returns a direct link to a CSS file
83+
84+
> Snapshot 1
85+
86+
'.css-imported-with-css {}'

test/snapshots/index.js.snap

31 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)