forked from puppeteer/puppeteer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement nested selector parsing (puppeteer#12587)
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/puppeteer-core/src/common/PSelectorParser.test.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,50 @@ | ||
/** | ||
* @license | ||
* Copyright 2024 Google Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {describe, it} from 'node:test'; | ||
|
||
import expect from 'expect'; | ||
|
||
import {parsePSelectors} from './PSelectorParser.js'; | ||
|
||
describe('PSelectorParser', () => { | ||
describe('parsePSelectors', () => { | ||
it('parses nested selectors', () => { | ||
const [updatedSelector, isPureCSS, hasPseudoClasses] = | ||
parsePSelectors('& > div'); | ||
expect(updatedSelector).toEqual([[['&>div']]]); | ||
expect(isPureCSS).toBeTruthy(); | ||
expect(hasPseudoClasses).toBeFalsy(); | ||
}); | ||
|
||
it('parses nested selectors with p-selector syntax', () => { | ||
const [updatedSelector, isPureCSS, hasPseudoClasses] = | ||
parsePSelectors('& > div >>> button'); | ||
expect(updatedSelector).toEqual([[['&>div'], '>>>', ['button']]]); | ||
expect(isPureCSS).toBeFalsy(); | ||
expect(hasPseudoClasses).toBeFalsy(); | ||
}); | ||
|
||
it('parses selectors with pseudo classes', () => { | ||
const [updatedSelector, isPureCSS, hasPseudoClasses] = | ||
parsePSelectors('div:focus'); | ||
expect(updatedSelector).toEqual([[['div:focus']]]); | ||
expect(isPureCSS).toBeTruthy(); | ||
expect(hasPseudoClasses).toBeTruthy(); | ||
}); | ||
|
||
it('parses nested selectors with pseudo classes and p-selector syntax', () => { | ||
const [updatedSelector, isPureCSS, hasPseudoClasses] = parsePSelectors( | ||
'& > div:focus >>>> button:focus' | ||
); | ||
expect(updatedSelector).toEqual([ | ||
[['&>div:focus'], '>>>>', ['button:focus']], | ||
]); | ||
expect(isPureCSS).toBeFalsy(); | ||
expect(hasPseudoClasses).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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