chore: remove selectorsV2Enabled switch (#4880)
Selectors V2 seem to stick.
This commit is contained in:
Родитель
c4df522555
Коммит
5215add60d
|
@ -26,28 +26,21 @@ export type ParsedSelector = {
|
|||
capture?: number,
|
||||
};
|
||||
|
||||
export function selectorsV2Enabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const customCSSNames = new Set(['not', 'is', 'where', 'has', 'scope', 'light', 'visible', 'text', 'text-matches', 'text-is']);
|
||||
|
||||
export function parseSelector(selector: string): ParsedSelector {
|
||||
const result = parseSelectorV1(selector);
|
||||
|
||||
if (selectorsV2Enabled()) {
|
||||
result.parts = result.parts.map(part => {
|
||||
if (Array.isArray(part))
|
||||
return part;
|
||||
if (part.name === 'css' || part.name === 'css:light') {
|
||||
if (part.name === 'css:light')
|
||||
part.body = ':light(' + part.body + ')';
|
||||
const parsedCSS = parseCSS(part.body, customCSSNames);
|
||||
return parsedCSS.selector;
|
||||
}
|
||||
result.parts = result.parts.map(part => {
|
||||
if (Array.isArray(part))
|
||||
return part;
|
||||
});
|
||||
}
|
||||
if (part.name === 'css' || part.name === 'css:light') {
|
||||
if (part.name === 'css:light')
|
||||
part.body = ':light(' + part.body + ')';
|
||||
const parsedCSS = parseCSS(part.body, customCSSNames);
|
||||
return parsedCSS.selector;
|
||||
}
|
||||
return part;
|
||||
});
|
||||
return {
|
||||
parts: result.parts,
|
||||
capture: result.capture,
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
import { it, expect } from './fixtures';
|
||||
import { selectorsV2Enabled } from '../src/server/common/selectorParser';
|
||||
|
||||
it('should throw for non-string selector', async ({page}) => {
|
||||
const error = await page.$(null).catch(e => e);
|
||||
|
@ -59,8 +58,6 @@ it('should auto-detect xpath selector with starting parenthesis', async ({page,
|
|||
});
|
||||
|
||||
it('should auto-detect xpath selector starting with ..', async ({page, server}) => {
|
||||
if (selectorsV2Enabled())
|
||||
return; // Selectors v2 do not support this.
|
||||
await page.setContent('<div><section>test</section><span></span></div>');
|
||||
const span = await page.$('"test" >> ../span');
|
||||
expect(await span.evaluate(e => e.nodeName)).toBe('SPAN');
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
import { it, expect } from './fixtures';
|
||||
import { selectorsV2Enabled } from '../src/server/common/selectorParser';
|
||||
|
||||
it('should work with large DOM', async ({page, server}) => {
|
||||
await page.evaluate(() => {
|
||||
|
@ -240,7 +239,7 @@ it('should work with *', async ({page}) => {
|
|||
expect(await body.$$eval('div *', els => els.length)).toBe(2);
|
||||
// Selectors v2 matches jquery in the sense that matching starts with the element scope,
|
||||
// not the document scope.
|
||||
expect(await body.$$eval('* > *', els => els.length)).toBe(selectorsV2Enabled() ? 2 : 4);
|
||||
expect(await body.$$eval('* > *', els => els.length)).toBe(2);
|
||||
// Adding scope makes querySelectorAll work like jquery.
|
||||
expect(await body.$$eval(':scope * > *', els => els.length)).toBe(2);
|
||||
// Note that the following two selectors are following jquery logic even
|
||||
|
@ -310,18 +309,13 @@ it('should work with +', async ({page}) => {
|
|||
expect(await page.$$eval(`css=div + #div1`, els => els.length)).toBe(0);
|
||||
expect(await page.$$eval(`css=section > div + div ~ div`, els => els.length)).toBe(4);
|
||||
expect(await page.$$eval(`css=section > div + #div4 ~ div`, els => els.length)).toBe(2);
|
||||
if (selectorsV2Enabled()) {
|
||||
// Selectors v1 do not support this.
|
||||
expect(await page.$$eval(`css=section:has(:scope > div + #div2)`, els => els.length)).toBe(1);
|
||||
expect(await page.$$eval(`css=section:has(:scope > div + #div1)`, els => els.length)).toBe(0);
|
||||
}
|
||||
expect(await page.$$eval(`css=section:has(:scope > div + #div2)`, els => els.length)).toBe(1);
|
||||
expect(await page.$$eval(`css=section:has(:scope > div + #div1)`, els => els.length)).toBe(0);
|
||||
// TODO: the following does not work. Should it?
|
||||
// expect(await page.$eval(`css=div:has(:scope + #div5)`, e => e.id)).toBe('div4');
|
||||
});
|
||||
|
||||
it('should work with spaces in :nth-child and :not', async ({page, server}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
await page.goto(server.PREFIX + '/deep-shadow.html');
|
||||
expect(await page.$$eval(`css=span:nth-child(23n +2)`, els => els.length)).toBe(1);
|
||||
expect(await page.$$eval(`css=span:nth-child(23n+ 2)`, els => els.length)).toBe(1);
|
||||
|
@ -336,8 +330,6 @@ it('should work with spaces in :nth-child and :not', async ({page, server}) => {
|
|||
});
|
||||
|
||||
it('should work with :is', async ({page, server}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
await page.goto(server.PREFIX + '/deep-shadow.html');
|
||||
expect(await page.$$eval(`css=div:is(#root1)`, els => els.length)).toBe(1);
|
||||
expect(await page.$$eval(`css=div:is(#root1, #target)`, els => els.length)).toBe(1);
|
||||
|
@ -352,8 +344,6 @@ it('should work with :is', async ({page, server}) => {
|
|||
});
|
||||
|
||||
it('should work with :has', async ({page, server}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
await page.goto(server.PREFIX + '/deep-shadow.html');
|
||||
expect(await page.$$eval(`css=div:has(#target)`, els => els.length)).toBe(2);
|
||||
expect(await page.$$eval(`css=div:has([data-testid=foo])`, els => els.length)).toBe(3);
|
||||
|
@ -361,8 +351,6 @@ it('should work with :has', async ({page, server}) => {
|
|||
});
|
||||
|
||||
it('should work with :scope', async ({page, server}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
await page.goto(server.PREFIX + '/deep-shadow.html');
|
||||
// 'is' does not change the scope, so it remains 'html'.
|
||||
expect(await page.$$eval(`css=div:is(:scope#root1)`, els => els.length)).toBe(0);
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
import { it, expect } from './fixtures';
|
||||
import { selectorsV2Enabled } from '../src/server/common/selectorParser';
|
||||
|
||||
it('should work for open shadow roots', async ({page, server}) => {
|
||||
await page.goto(server.PREFIX + '/deep-shadow.html');
|
||||
|
@ -29,8 +28,6 @@ it('should work for open shadow roots', async ({page, server}) => {
|
|||
});
|
||||
|
||||
it('should work with :visible', async ({page}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
await page.setContent(`
|
||||
<section>
|
||||
<div id=target1></div>
|
||||
|
@ -53,9 +50,6 @@ it('should work with :visible', async ({page}) => {
|
|||
it('should work with proximity selectors', test => {
|
||||
test.skip('Not ready yet');
|
||||
}, async ({page}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
|
||||
/*
|
||||
|
||||
+--+ +--+
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
import { it, expect } from './fixtures';
|
||||
import { selectorsV2Enabled } from '../src/server/common/selectorParser';
|
||||
|
||||
it('should work', async ({page}) => {
|
||||
await page.setContent(`<div>yo</div><div>ya</div><div>\nye </div>`);
|
||||
|
@ -108,8 +107,6 @@ it('should work', async ({page}) => {
|
|||
});
|
||||
|
||||
it('should work in v2', async ({page}) => {
|
||||
if (!selectorsV2Enabled())
|
||||
return; // Selectors v1 do not support this.
|
||||
await page.setContent(`<div>yo</div><div>ya</div><div>\nHELLO \n world </div>`);
|
||||
expect(await page.$eval(`:text("ya")`, e => e.outerHTML)).toBe('<div>ya</div>');
|
||||
expect(await page.$eval(`:text-is("ya")`, e => e.outerHTML)).toBe('<div>ya</div>');
|
||||
|
|
Загрузка…
Ссылка в новой задаче