Skip to content

Commit

Permalink
test: modify tests to new default
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros committed Sep 20, 2023
1 parent 81109a4 commit e4a7311
Show file tree
Hide file tree
Showing 10 changed files with 493 additions and 556 deletions.
1 change: 0 additions & 1 deletion packages/core/test/features/css-general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { shouldReportNoDiagnostics, testStylableCore } from '@stylable/core-test
describe('features/css-general', () => {
describe('svg', () => {
it('should preserve path value function quotes', () => {
// ToDo: remove once experimentalSelectorInference is the default
const { sheets } = testStylableCore(`
.path {
Expand Down
424 changes: 189 additions & 235 deletions packages/core/test/features/css-pseudo-class.spec.ts

Large diffs are not rendered by default.

126 changes: 55 additions & 71 deletions packages/core/test/features/css-pseudo-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,79 +250,63 @@ describe('features/css-pseudo-element', () => {

shouldReportNoDiagnostics(meta);
});
describe('experimentalSelectorInference', () => {
it('should transform multiple selector intersection', () => {
const { sheets } = testStylableCore(
{
'base.st.css': `
.shared {}
@custom-selector :--sharedMulti .x, .y;
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--multi A, B;
/* @rule(shared) .entry__root .a__root .base__shared,.entry__root .b__root .base__shared */
.root::multi::shared {}
/* @rule(shared-multi) .entry__root .a__root .base__x,.entry__root .b__root .base__x,.entry__root .a__root .base__y,.entry__root .b__root .base__y */
.root::multi::sharedMulti {}
`,
},
{
stylableConfig: {
experimentalSelectorInference: true,
},
}
);
it('should transform multiple selector intersection', () => {
const { sheets } = testStylableCore({
'base.st.css': `
.shared {}
@custom-selector :--sharedMulti .x, .y;
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--multi A, B;
/* @rule(shared) .entry__root .a__root .base__shared,.entry__root .b__root .base__shared */
.root::multi::shared {}
/* @rule(shared-multi) .entry__root .a__root .base__x,.entry__root .b__root .base__x,.entry__root .a__root .base__y,.entry__root .b__root .base__y */
.root::multi::sharedMulti {}
`,
});

const { meta } = sheets['/entry.st.css'];
const { meta } = sheets['/entry.st.css'];

shouldReportNoDiagnostics(meta);
});
it('should filter out elements that do not exist or match', () => {
testStylableCore(
{
'base.st.css': `
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
.onlyInA {}
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--multi A, B;
/*
@transform-error(exist in 1) word(onlyInA) ${transformerStringDiagnostics.UNKNOWN_PSEUDO_ELEMENT(
`onlyInA`
)}
@rule(exist in 1) .entry__root .a__root::onlyInA,.entry__root .b__root::onlyInA
*/
.root::multi::onlyInA {}
`,
},
{
stylableConfig: {
experimentalSelectorInference: true,
},
}
);
shouldReportNoDiagnostics(meta);
});
it('should filter out elements that do not exist or match', () => {
testStylableCore({
'base.st.css': `
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
.onlyInA {}
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--multi A, B;
/*
@transform-error(exist in 1) word(onlyInA) ${transformerStringDiagnostics.UNKNOWN_PSEUDO_ELEMENT(
`onlyInA`
)}
@rule(exist in 1) .entry__root .a__root::onlyInA,.entry__root .b__root::onlyInA
*/
.root::multi::onlyInA {}
`,
});
});
});
Expand Down
121 changes: 52 additions & 69 deletions packages/core/test/features/st-custom-selector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chaiSubset from 'chai-subset';
import { STCustomSelector, CSSType } from '@stylable/core/dist/features';
import { STCustomSelector, CSSType, CSSPseudoClass } from '@stylable/core/dist/features';
import {
testStylableCore,
shouldReportNoDiagnostics,
Expand All @@ -11,6 +11,7 @@ chai.use(chaiSubset);

const customSelectorDiagnostics = diagnosticBankReportToStrings(STCustomSelector.diagnostics);
const cssTypeDiagnostics = diagnosticBankReportToStrings(CSSType.diagnostics);
const pseudoClassDiagnostics = diagnosticBankReportToStrings(CSSPseudoClass.diagnostics);

describe('features/st-custom-selector', () => {
// ToDo: migrate to @st-part
Expand Down Expand Up @@ -59,17 +60,15 @@ describe('features/st-custom-selector', () => {
shouldReportNoDiagnostics(meta);
});
it('should handle unknown custom selector', () => {
// ToDo: remove diagnostic once experimentalSelectorInference is the default
// it will fallback to pseudo-class transform and then to unknown pseudo-class
testStylableCore(`
/* @analyze-error(in custom) word(:--unknown) ${customSelectorDiagnostics.UNKNOWN_CUSTOM_SELECTOR(
':--unknown'
)} */
@custom-selector :--x .before:--unknown.after;
/*
@transform-error(in selector) word(:--unknown) ${customSelectorDiagnostics.UNKNOWN_CUSTOM_SELECTOR(
':--unknown'
@transform-error(in selector) word(--unknown) ${pseudoClassDiagnostics.UNKNOWN_STATE_USAGE(
'--unknown'
)}
@rule .entry__before:--unknown.entry__after {}
*/
Expand Down Expand Up @@ -100,71 +99,55 @@ describe('features/st-custom-selector', () => {
'only a single unscoped diagnostic for span'
).to.eql(1);
});
describe('experimentalSelectorInference', () => {
it('should transform multiple selector intersection', () => {
const { sheets } = testStylableCore(
{
'base.st.css': `
.shared {}
@custom-selector :--xy .x, .y;
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--ab A, B;
/* @rule(shared-multi) .a__root .base__x, .b__root .base__x,.a__root .base__y, .b__root .base__y */
:--ab::xy {}
`,
},
{
stylableConfig: {
experimentalSelectorInference: true,
},
}
);

const { meta } = sheets['/entry.st.css'];

shouldReportNoDiagnostics(meta);
it('should transform multiple selector intersection', () => {
const { sheets } = testStylableCore({
'base.st.css': `
.shared {}
@custom-selector :--xy .x, .y;
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--ab A, B;
/* @rule(shared-multi) .a__root .base__x, .b__root .base__x,.a__root .base__y, .b__root .base__y */
:--ab::xy {}
`,
});
it('should filter out elements that do not exist or match', () => {
testStylableCore(
{
'base.st.css': `
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
.onlyInA {}
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--ab A, B;
/* @rule(exist in 1) .a__root::onlyInA, .b__root::onlyInA */
:--ab::onlyInA {}
`,
},
{
stylableConfig: {
experimentalSelectorInference: true,
},
}
);

const { meta } = sheets['/entry.st.css'];

shouldReportNoDiagnostics(meta);
});
it('should filter out elements that do not exist or match', () => {
testStylableCore({
'base.st.css': `
`,
'a.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
.onlyInA {}
`,
'b.st.css': `
@st-import Base from './base.st.css';
.root { -st-extends: Base }
`,
'entry.st.css': `
@st-import A from './a.st.css';
@st-import B from './b.st.css';
@custom-selector :--ab A, B;
/* @rule(exist in 1) .a__root::onlyInA, .b__root::onlyInA */
:--ab::onlyInA {}
`,
});
});
});
59 changes: 30 additions & 29 deletions packages/core/test/features/st-global.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,47 +89,48 @@ describe(`features/st-global`, () => {
const expectedGlobalRules = collectAst(meta.sourceAst, ['global']);
expect(actualGlobalRules).to.eql(expectedGlobalRules['global']);
});
it('should continue inferred selector after :global()', () => {
// ToDo: remove once experimentalSelectorInference is the default
it('should set wildcard inferred selector to context after :global()', () => {
testStylableCore({
'comp.st.css': `.part {} `,
'comp.st.css': ` .part {} `,
'entry.st.css': `
@st-import Comp from './comp.st.css';
.class { -st-states: state; }
/* @rule(state) .entry__class.g.entry--state */
.class:global(.g):state {}
@st-import Comp from './comp.st.css';
.class { -st-states: state('.class-state'); }
/* @rule(pseudo-element) .comp__root.g .comp__part */
Comp:global(.g)::part {}
/* @rule(root state) .entry__class.g:state */
.class:global(.g):state {}
/* @rule(unknown pseudo-element) .comp__root.g::class */
Comp:global(.g)::class {}
`,
/* @rule(unknown comp pseudo-element) .comp__root.g::part */
Comp:global(.g)::part {}
/* @rule(unknown pseudo-element) .comp__root.g::class */
Comp:global(.g)::class {}
/* @rule(universal pseudo-element) .comp__root.g ::class */
Comp:global(.g) ::class {}
`,
});
});
describe('experimentalSelectorInference', () => {
it('should set wildcard inferred selector to context after :global()', () => {
describe('experimentalSelectorInference=false', () => {
it('should continue inferred selector after :global()', () => {
testStylableCore(
{
'comp.st.css': ` .part {} `,
'comp.st.css': `.part {} `,
'entry.st.css': `
@st-import Comp from './comp.st.css';
.class { -st-states: state('.class-state'); }
@st-import Comp from './comp.st.css';
.class { -st-states: state; }
/* @rule(state) .entry__class.g.entry--state */
.class:global(.g):state {}
/* @rule(root state) .entry__class.g:state */
.class:global(.g):state {}
/* @rule(unknown comp pseudo-element) .comp__root.g::part */
Comp:global(.g)::part {}
/* @rule(pseudo-element) .comp__root.g .comp__part */
Comp:global(.g)::part {}
/* @rule(unknown pseudo-element) .comp__root.g::class */
Comp:global(.g)::class {}
/* @rule(universal pseudo-element) .comp__root.g ::class */
Comp:global(.g) ::class {}
`,
/* @rule(unknown pseudo-element) .comp__root.g::class */
Comp:global(.g)::class {}
`,
},
{ stylableConfig: { experimentalSelectorInference: true } }
{
stylableConfig: { experimentalSelectorInference: false },
}
);
});
});
Expand Down
Loading

0 comments on commit e4a7311

Please sign in to comment.