Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function(t, name, opts, postcssOpts, warnings)
{
opts = assign({ path: "test/fixtures/imports" }, opts)
return postcss(atImport(opts))
.process(read(name), postcssOpts || {})
.then((result) => {
var actual = result.css
var expected = read(name + ".expected")
// handy thing: checkout actual in the *.actual.css file
fs.writeFile("test/fixtures/" + name + ".actual.css", actual, () => {
t.is(actual, expected)
if (!warnings)
warnings = []
result.warnings().forEach((warning, index) => {
t.is(
warning.text,
warnings[index],
function cssnext (tagName, css) {
// A small hack: it passes :scope as :root to PostCSS.
// This make it easy to use css variables inside tags.
css = css.replace(/:scope/g, ':root')
css = postcss([postcssCssnext]).process(css).css
css = css.replace(/:root/g, ':scope')
return css
}
let parse = (styles, options = {}) => {
styles = escapeAtRuleQueryVars(styles);
if(typeof styles !== "string"){
throw new Error('Please styles as string!');
}
let container = [];
// normalize nested css before converting to ast
let content = postcss([nestedCss({ bubble: POSTCSS_BUBBLES })/*, prefixer*/]).process(styles).content;
let ast = compiler.parse(content);
// walk trough classic css selectors
ast.walkRules(node => push(container, getRuleConfig(node)));
// walk trough @ action /my/{{foo}}/route.html, @on ...
ast.walkAtRules(node => push(container, getAtRuleConfig(node)));
// combine/concat same attachOn´s
options.optimize ? container = optimize(container) : null;
// check in which constellation @ allowed
options.grammarCheck ? grammarCheck(container) : null;
return container;
};
test('should be consumed as a postcss stringifier', t => {
return postcss().process('h1{}', {stringifier: midas}).then(result => {
t.deepEqual('<pre class="midas"><code><span class="midas__selector"><span class="midas__tag">h1</span></span><span class="midas__brace">{</span><span class="midas__brace">}</span></code></pre>', result.content);
});
});
test("should have a callback that returns an object containing imported files", (t) =>
postcss()
.use(atImport({
path: "test/fixtures/imports",
onImport: (files) =>
{
t.deepEqual(
files,
[
resolve("test/fixtures/media-import.css"),
resolve("test/fixtures/imports/media-import-level-2.css"),
resolve("test/fixtures/imports/media-import-level-3.css")
]
)
}
}))
.process(readFileSync("test/fixtures/media-import.css"), {
from: "test/fixtures/media-import.css"
it('mods', function() {
process.env.REBEM_MOD_DELIM = '~~';
const CustomPlugin = requireUncached('../../lib/');
assert.strictEqual(
postcss([ CustomPlugin ]).process(':block(block):mod(mod val){}').css,
'.block~~mod~~val{}'
);
});
export async function compileSameFolder(input) {
const allOptions = {
...options,
from: "__tests__/fixtures/main.css",
to: "__tests__/fixtures/main.out.css"
}
const result = await postcss(plugins)
.process(input, allOptions)
expect(format(result.css)).toMatchSnapshot()
}
export default async function css() {
const source = fs.readFileSync('./app/css/downloads.css', 'utf8');
const output = postcss(postcssPlugins).process(source, {
from: './app/scripts/styles'
})
.catch(err => console.error(err.stack));
await output.then(data => {
const minifyOpts = {
discardComments: { removeAll: true }
};
cssnano.process(data.css, minifyOpts).then(minified =>
fs.outputFile('./build/css/downloads.css', minified.css));
});
}
processor: css => postcss([
prefixer('📖-'),
cssnano(),
]).process(css).then(result => result.css),
});