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 1030675
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 148 deletions.
9 changes: 4 additions & 5 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
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
148 changes: 73 additions & 75 deletions packages/core/test/stylable-transformer/general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,99 +52,97 @@ describe('Stylable postcss transform (General)', () => {
expect(rule2.nodes[0].toString(), 'color1').to.equal('color: red');
expect(rule2.nodes[1].toString(), 'color1').to.equal('color: blue');
});
it('should continue inferred selector after combinator', () => {
// ToDo: remove once experimentalSelectorInference is the default
testStylableCore({
'comp.st.css': `.part {} `,
'entry.st.css': `
@st-import Comp from './comp.st.css';
it('should set default inferred selector context to universal selector', () => {
testStylableCore(
`
.root { -st-states: state; }
.class { -st-states: state; }
/* @rule(state) .entry__class .entry--state */
.class :state {}
/* @rule(pseudo-element) .comp__root .comp__part */
Comp ::part {}
/* @rule(unknown pseudo-element) .comp__root ::class */
Comp ::class {}
`,
});
});
it('should continue inferred selector after universal', () => {
// ToDo: remove once experimentalSelectorInference is the default
testStylableCore(`
.root { -st-states: state; }
.part {}
/* @rule(state) *.entry--state */
*:state {}
/* @rule(element) * .entry__part */
*::part {}
`);
/*
@transform-error(unknown state) ${cssPseudoClassDiagnostics.UNKNOWN_STATE_USAGE(
'state'
)}
@rule(unknown state) :state
*/
:state {}
/*
@transform-error(unknown pseudo-element) ${transformerStringDiagnostics.UNKNOWN_PSEUDO_ELEMENT(
`class`
)}
@rule(unknown pseudo-element) ::class
*/
::class {}
`
);
});

describe('experimentalSelectorInference', () => {
it('should set default inferred selector context to universal selector', () => {
testStylableCore(
`
.root { -st-states: state; }
it('should reset inferred selector after combinator', () => {
testStylableCore({
'comp.st.css': ` .part {} `,
'entry.st.css': `
@st-import Comp from './comp.st.css';
.class { -st-states: state; }
/*
@transform-error(unknown state) ${cssPseudoClassDiagnostics.UNKNOWN_STATE_USAGE(
'state'
)}
@rule(unknown state) :state
*/
:state {}
/* @rule(unknown state) .entry__class :state */
.class :state {}
/* @rule(unknown pseudo-element) .comp__root ::part */
Comp ::part {}
/*
@transform-error(unknown pseudo-element) ${transformerStringDiagnostics.UNKNOWN_PSEUDO_ELEMENT(
`class`
)}
@rule(unknown pseudo-element) ::class
*/
::class {}
/* @rule(standalone pseudo-element) .comp__root ::class */
Comp ::class {}
`,
{ stylableConfig: { experimentalSelectorInference: true } }
);
});
it('should reset inferred selector after combinator', () => {
});
it('should set inferred selector after universal (to universal)', () => {
testStylableCore(
`
.root { -st-states: state; }
.part {}
/* @rule(state) *:state */
*:state {}
/* @rule(element) *::part */
*::part {}
`
);
});
describe('experimentalSelectorInference', () => {
it('should continue inferred selector after combinator', () => {
testStylableCore(
{
'comp.st.css': ` .part {} `,
'comp.st.css': `.part {} `,
'entry.st.css': `
@st-import Comp from './comp.st.css';
.class { -st-states: state; }
@st-import Comp from './comp.st.css';
.class { -st-states: state; }
/* @rule(state) .entry__class .entry--state */
.class :state {}
/* @rule(unknown state) .entry__class :state */
.class :state {}
/* @rule(unknown pseudo-element) .comp__root ::part */
Comp ::part {}
/* @rule(pseudo-element) .comp__root .comp__part */
Comp ::part {}
/* @rule(standalone pseudo-element) .comp__root ::class */
Comp ::class {}
`,
/* @rule(unknown pseudo-element) .comp__root ::class */
Comp ::class {}
`,
},
{ stylableConfig: { experimentalSelectorInference: true } }
{ stylableConfig: { experimentalSelectorInference: false } }
);
});
it('should set inferred selector after universal (to universal)', () => {
it('should continue inferred selector after universal', () => {
testStylableCore(
`
.root { -st-states: state; }
.part {}
/* @rule(state) *:state */
*:state {}
/* @rule(element) *::part */
*::part {}
`,
{ stylableConfig: { experimentalSelectorInference: true } }
.root { -st-states: state; }
.part {}
/* @rule(state) *.entry--state */
*:state {}
/* @rule(element) * .entry__part */
*::part {}
`,
{ stylableConfig: { experimentalSelectorInference: false } }
);
});
});
Expand Down
64 changes: 36 additions & 28 deletions packages/core/test/stylable-transformer/nesting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,48 @@ describe('transformer/nesting', () => {
*/
&:onlyX {}
}
`,
{ stylableConfig: { experimentalSelectorInference: true } }
`
);
});
it('should infer to universal selector without nesting selector', () => {
testStylableCore(`
.root {
-st-states: x;
}
.part {
-st-states: x;
}
describe('experimentalSelectorInference=false', () => {
it('should infer to universal selector without nesting selector', () => {
testStylableCore(
`
.root {
-st-states: x;
}
.part {
-st-states: x;
}
.part {
/*
@transform-error(first) ${cssPseudoClassDiagnostics.UNKNOWN_STATE_USAGE('x')}
@rule(first) :x
*/
:x {}
.part {
/*
@transform-error(first) ${cssPseudoClassDiagnostics.UNKNOWN_STATE_USAGE(
'x'
)}
@rule(first) :x
*/
:x {}
/*
@transform-error(after combinator) ${cssPseudoClassDiagnostics.UNKNOWN_STATE_USAGE(
'x'
)}
@rule(after combinator) .entry__root :x
*/
.root :x {}
}
/*
@transform-error(after combinator) ${cssPseudoClassDiagnostics.UNKNOWN_STATE_USAGE(
'x'
)}
@rule(after combinator) .entry__root :x
legacy behavior without "experimentalSelectorInference"
@rule(after combinator) .entry__root .entry--x
*/
.root :x {}
}
/*
legacy behavior without "experimentalSelectorInference"
@rule(after combinator) .entry__root .entry--x
*/
.root :x {}
`);
`,
{
stylableConfig: { experimentalSelectorInference: false },
}
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ describe('LS: css-pseudo-class', () => {
}
}
/* currently nesting in non-& reset to root - this behavior might change */
.part {
:hover {
&^nestUnderNonAmp^
Expand All @@ -561,8 +560,8 @@ describe('LS: css-pseudo-class', () => {
assertCompletions('/entry.st.css', ({ filePath, carets }) => ({
message: 'nestUnderNonAmp',
actualList: service.onCompletion(filePath, carets.nestUnderNonAmp),
expectedList: [{ label: ':root-state' }],
unexpectedList: [{ label: ':part-state' }],
expectedList: [],
unexpectedList: [{ label: ':part-state' }, { label: ':root-state' }],
}));
});
});
Expand Down
Loading

0 comments on commit 1030675

Please sign in to comment.