diff --git a/src/snapshot.ts b/src/snapshot.ts index 49642ed7..1be1b6a4 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -21,13 +21,21 @@ function getCssRulesString(s: CSSStyleSheet): string | null { try { const rules = s.rules || s.cssRules; return rules - ? Array.from(rules).reduce((prev, cur) => (prev += cur.cssText), '') + ? Array.from(rules).reduce((prev, cur) => prev + getCssRuleString(cur), '') : null; } catch (error) { return null; } } +function getCssRuleString(rule: CSSRule): string { + return isCSSImportRule(rule) ? getCssRulesString(rule.styleSheet) || '' : rule.cssText; +} + +function isCSSImportRule(rule: CSSRule): rule is CSSImportRule { + return 'styleSheet' in rule; +} + function extractOrigin(url: string): string { let origin; if (url.indexOf('//') > -1) { diff --git a/test/__snapshots__/integration.ts.snap b/test/__snapshots__/integration.ts.snap index 2c3d42b8..2ee77d42 100644 --- a/test/__snapshots__/integration.ts.snap +++ b/test/__snapshots__/integration.ts.snap @@ -205,3 +205,14 @@ exports[`[html file]: with-style-sheet.html 1`] = ` " `; + +exports[`[html file]: with-style-sheet-with-import.html 1`] = ` +" + + + + with style sheet with import + + +" +`; diff --git a/test/css/style-with-import.css b/test/css/style-with-import.css new file mode 100644 index 00000000..61058d7b --- /dev/null +++ b/test/css/style-with-import.css @@ -0,0 +1 @@ +@import "./style.css"; diff --git a/test/html/with-style-sheet-with-import.html b/test/html/with-style-sheet-with-import.html new file mode 100644 index 00000000..6b45f65b --- /dev/null +++ b/test/html/with-style-sheet-with-import.html @@ -0,0 +1,16 @@ + + + + + + + + with style sheet with import + + + + + + + +