From 2db70e9e443f53be39b148401dbd9a58d6cecae3 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Tue, 17 Nov 2020 23:35:37 +0900 Subject: [PATCH] Fix `isStandardSyntaxTypeSelector.test.js` that use callbacks (#4990) --- .../isStandardSyntaxTypeSelector.test.js | 92 +++++++------------ 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/lib/utils/__tests__/isStandardSyntaxTypeSelector.test.js b/lib/utils/__tests__/isStandardSyntaxTypeSelector.test.js index 21b7fb25da..d53cca3553 100644 --- a/lib/utils/__tests__/isStandardSyntaxTypeSelector.test.js +++ b/lib/utils/__tests__/isStandardSyntaxTypeSelector.test.js @@ -6,101 +6,73 @@ const selectorParser = require('postcss-selector-parser'); describe('isStandardSyntaxTypeSelector', () => { it('tag', () => { - rules('a {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeTruthy(); - }); + expect(isStandardSyntaxTypeSelector(tag('a {}'))).toBe(true); }); it('lowercase nth-child pseudo selector', () => { - rules('.foo:nth-child(n) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo:nth-child(n) {}'))).toBe(false); }); it('mixedcase nth-child pseudo selector', () => { - rules('.foo:nTh-ChIlD(n) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo:nTh-ChIlD(n) {}'))).toBe(false); }); it('uppercase nth-child pseudo selector', () => { - rules('.foo:NTH-CHILD(n) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo:NTH-CHILD(n) {}'))).toBe(false); }); it('nth-last-child pseudo selector', () => { - rules('.foo:nth-last-child(n) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo:nth-last-child(n) {}'))).toBe(false); }); it('nth-of-type pseudo selector', () => { - rules('.foo:nth-of-type(n) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo:nth-of-type(n) {}'))).toBe(false); }); it('lowercase lang pseudo selector', () => { - rules(':lang(en) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag(':lang(en) {}'))).toBe(false); }); it('mixedcase lang pseudo selector', () => { - rules(':lAnG(en) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag(':lAnG(en) {}'))).toBe(false); }); it('uppercase lang pseudo selector', () => { - rules(':LANG(en) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag(':LANG(en) {}'))).toBe(false); }); it('dir pseudo selector', () => { - rules(':dir(ltr) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag(':dir(ltr) {}'))).toBe(false); }); it('nesting selector', () => { - rules('.foo { &-bar {} }', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo { &-bar {} }'))).toBe(false); }); it('nesting selector underscores', () => { - rules('.foo { &__bar {} }', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('.foo { &__bar {} }'))).toBe(false); }); it('placeholder selector', () => { - rules('%foo {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('%foo {}'))).toBe(false); }); - it('shadow-piercing descendant combinator', () => { - rules('.foo /deep/ .bar {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + // eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508) + it.skip('shadow-piercing descendant combinator', () => { + expect(isStandardSyntaxTypeSelector(tag('.foo /deep/ .bar {}'))).toBe(false); }); it('shadow-parts ident', () => { - rules('::part(foo) {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + expect(isStandardSyntaxTypeSelector(tag('::part(foo) {}'))).toBe(false); }); - it('lowercase reference combinators', () => { - rules('.foo /for/ .bar {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + // eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508) + it.skip('lowercase reference combinators', () => { + expect(isStandardSyntaxTypeSelector(tag('.foo /for/ .bar {}'))).toBe(false); }); - it('mixedcase reference combinators', () => { - rules('.foo /fOr/ .bar {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + // eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508) + it.skip('mixedcase reference combinators', () => { + expect(isStandardSyntaxTypeSelector(tag('.foo /fOr/ .bar {}'))).toBe(false); }); - it('uppercase reference combinators', () => { - rules('.foo /FOR/ .bar {}', (func) => { - expect(isStandardSyntaxTypeSelector(func)).toBeFalsy(); - }); + // eslint-disable-next-line jest/no-disabled-tests -- "Reference combinator" is unsupported? (see #2508) + it.skip('uppercase reference combinators', () => { + expect(isStandardSyntaxTypeSelector(tag('.foo /FOR/ .bar {}'))).toBe(false); }); }); -function rules(css, cb) { +function tag(css) { + const tags = []; + postcss.parse(css).walkRules((rule) => { selectorParser((selectorAST) => { - selectorAST.walkTags(cb); + selectorAST.walkTags((t) => tags.push(t)); }).processSync(rule.selector); }); + + return tags[0]; }