-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 do not ignore @import rules pointing to inaccessible stylesheets
We follow @import rules and inline their content so the player can uses its strategy to emulate :hover states. But if the external stylesheet is inaccessible, we should still take the @import rule into account, so the external stylesheet can be loaded in the player.
- Loading branch information
1 parent
ef8f6ca
commit 98431dd
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/rum/src/domain/record/serialization/serializeAttributes.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { getCssRulesString } from './serializeAttributes' | ||
|
||
describe('getCssRulesString', () => { | ||
let styleNode: HTMLStyleElement | ||
|
||
beforeEach(() => { | ||
styleNode = document.createElement('style') | ||
document.body.appendChild(styleNode) | ||
}) | ||
afterEach(() => { | ||
document.body.removeChild(styleNode) | ||
}) | ||
|
||
it('returns the CSS rules as a string', () => { | ||
styleNode.sheet!.insertRule('body { color: red; }') | ||
|
||
expect(getCssRulesString(styleNode.sheet)).toBe('body { color: red; }') | ||
}) | ||
|
||
it('inlines imported external stylesheets', () => { | ||
styleNode.sheet!.insertRule('@import url("toto.css");') | ||
|
||
// Simulates an accessible external stylesheet | ||
spyOnProperty(styleNode.sheet!.cssRules[0] as CSSImportRule, 'styleSheet').and.returnValue({ | ||
cssRules: [{ cssText: 'p { margin: 0; }' } as CSSRule] as unknown as CSSRuleList, | ||
} as CSSStyleSheet) | ||
|
||
expect(getCssRulesString(styleNode.sheet)).toBe('p { margin: 0; }') | ||
}) | ||
|
||
it('does not skip the @import rules if the external stylesheet is inaccessible', () => { | ||
styleNode.sheet!.insertRule('@import url("toto.css");') | ||
|
||
// Simulates an inaccessible external stylesheet | ||
spyOnProperty(styleNode.sheet!.cssRules[0] as CSSImportRule, 'styleSheet').and.returnValue({ | ||
get cssRules(): CSSRuleList { | ||
throw new Error('Cannot access rules') | ||
}, | ||
} as CSSStyleSheet) | ||
|
||
expect(getCssRulesString(styleNode.sheet)).toBe('@import url("toto.css");') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters