File tree Expand file tree Collapse file tree 2 files changed +81
-0
lines changed
Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Verify that `:root`, `*`, etc are ignored correctly.
3+ */
4+
5+ import { test , expect } from '@playwright/test' ;
6+ import { cssToHtml } from '../src/index' ;
7+
8+ const css = `
9+ @import url('https://example.com/example.css');
10+ :root {
11+ background: #000;
12+ }
13+ * {
14+ content: 'a';
15+ box-sizing: border-box;
16+ }
17+ @media screen and (max-width: 200px) {}
18+ div {
19+ content: 'a';
20+ }
21+ div:hover {
22+ content: 'b';
23+ }
24+ ` ;
25+
26+ test ( 'Ignored' , async ( { page } ) => {
27+ await page . addScriptTag ( { path : './tests/GeneratorScript.js' } ) ;
28+
29+ const result = await page . evaluate ( async ( css ) => {
30+ document . body = cssToHtml ( css ) ;
31+
32+ const element = document . body . querySelector ( 'div' ) ;
33+ return element
34+ && element . innerHTML === 'a'
35+ && element . previousSibling === null
36+ && element . nextSibling === null ;
37+ } , css ) ;
38+
39+ expect ( result ) . toBeDefined ( ) ;
40+ expect ( result ) . toBe ( true ) ;
41+ } ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Verify that complex selectors will be parsed correctly.
3+ */
4+
5+ import { test , expect } from '@playwright/test' ;
6+ import { cssToHtml } from '../src/index' ;
7+
8+ const css = `
9+ #cat + .mouse >span.flea+i {
10+ padding: 10px;
11+ background-color: red;
12+ }
13+ nav a#logo.icon> img {
14+ content: 'https://example.com/image';
15+ display: block;
16+ }
17+ nav>a#logo.icon > img {
18+ content: 'https://example.com/image2';
19+ }
20+ ` ;
21+
22+ const html = `<body xmlns="http://www.w3.org/1999/xhtml"><div id="cat"></div><div class="mouse"><span class="flea"></span><i></i></div><nav><a class="icon" id="logo"><img src="https://example.com/image2" /></a></nav></body>` ;
23+
24+ test ( 'Selector' , async ( { page } ) => {
25+ await page . addScriptTag ( { path : './tests/GeneratorScript.js' } ) ;
26+
27+ const result = await page . evaluate ( async ( [ css , html ] ) => {
28+ document . body = cssToHtml ( css ) ;
29+ const styleElement = document . createElement ( 'style' ) ;
30+ styleElement . innerText = css ;
31+ document . head . append ( styleElement ) ;
32+
33+ const xml = new XMLSerializer ( ) . serializeToString ( document . body ) ;
34+
35+ return xml . trim ( ) === html . trim ( ) ;
36+ } , [ css , html ] ) ;
37+
38+ expect ( result ) . toBeDefined ( ) ;
39+ expect ( result ) . toBe ( true ) ;
40+ } ) ;
You can’t perform that action at this time.
0 commit comments