@stylable/core-test-kit
testStylableCore
Use import {testStylableCore} from '@stylable/core-test-kit'
to test core analysis, transformation, diagnostics and symbols. All stylable files are checked for inline expectations:
single entry
const { sheets } = testStylableCore(`
/* @rule .entry__root */
.root {}
`);
const { meta, exports } = sheets[`/entry.st.css`];
multiple files
const { sheets } = testStylableCore({
'/entry.st.css': `
@st-import Comp from './comp.st.css';
/* @rule .entry__root .comp__root */
.root Comp {}
`,
'/comp.st.css': `
/* @rule .comp__root */
.root {}
`
});
const entryResults = sheets[`/entry.st.css`];
const compResults = sheets[`/comp.st.css`];
stylable config
testStylableCore({
'/a.st.css': ``,
'/b.st.css': ``,
'/c.st.css': ``,
}, {
entries: [`/b.st.css`, `/c.st.css`]
stylableConfig: {
projectRoot: string,
resolveNamespace: (ns: string) => string,
requireModule: (path: string) => any
filesystem: IFileSystem,
}
});
expose infra
const { stylable, fs } = testStylableCore(``);
fs.writeFileSync(
`/new.st.css`,
`
@st-import [part] from './entry.st.css';
.part {}
`
);
const { meta, exports } = stylable.transform(stylable.analyze(`/new.st.css`));
Inline expectations syntax
The inline expectation syntax can be used with testInlineExpects
for testing stylesheets transformation and diagnostics.
An expectation is written as a comment just before the code it checks on. All expectations support label
that will be thrown as part of an expectation fail message.
@rule
- check rule transformation including selector and nested declarations:
Selector - @rule SELECTOR
.root::before {}
Declarations - @rule SELECTOR { decl: val; }
.root { color: red; }
.root {
color: red;
background: green;
}
Target generated rules (mixin) - @rule[OFFSET] SELECTOR
.mix {
color: red;
}
.mix:hover {
color: green;
}
.root {
-st-mixin: mix;
}
Label - @rule(LABEL) SELECTOR
.root {}
.part {}
@atrule
- check at-rule transformation of params:
AtRule params - @atrule PARAMS
:
@media value(smallScreen) {}
Label - @atrule(LABEL) PARAMS
@keyframes jump {}
@decl
- check declaration transformation
Prop & value - @decl PROP: VALUE
.root {
color: red
}
Label - @decl(LABEL) PROP: VALUE
.root {
color: red;
}
@analyze
& @transform
- check single file (analyze) and multiple files (transform) diagnostics:
Severity - @analyze-SEVERITY MESSAGE
/ @transform-SEVERITY MESSAGE
@st-global-custom-property --x;
@keyframes {}
#id() {}
.root {
color: value(unknown);
}
Word - @analyze-SEVERITY word(TEXT) MESSAGE
/ @transform-SEVERITY word(TEXT) MESSAGE
.root::unknown {}
Label - @analyze(LABEL) MESSAGE
/ @transform(LABEL) MESSAGE
@keyframes {}
@keyframes unknown {}
Removed in transformation - @transform-remove
@import X from './x.st.css';
License
Copyright (c) 2019 Wix.com Ltd. All Rights Reserved. Use of this source code is governed by a MIT license.