<commit_before><commit_msg>PostCSS unit tests<commit_after>const should = require('should');
const build = require(`../dist/commonjs/index.js`);
const getTestEnv = require('./fixtures/lib').getTestEnv;
const PostCssPlugin = build.PostCSS;
const RawPlugin = build.RawPlugin;
const postcss = require('postcss');

const pluginA = postcss.plugin('AllBlocks', function(options) {
    return function (css) {
        css.walkRules(function (rule) {
            rule.walkDecls(function (decl, i) {
                if (decl.prop === 'display') {
                    decl.value = 'block';
                }
            });
        });
    };
});

const pluginB = postcss.plugin('IdToClass', function(options) {
    return function (css) {
        css.walkRules(function (rule) {
            if (rule.selector && rule.selector[0] === '#') {
                rule.selector = '.' + rule.selector.slice(1);
            }
        });
    };
});

const style = `
    .grid {
        display: grid;
    }
    #moon {
        color: #555;
    }
`;

describe('PostCssPlugin', () => {
    
    it('Smoke test', () => {
        return getTestEnv({'style.css': style }, '>style.css', {
            plugins: [
                [PostCssPlugin(), RawPlugin()]
            ]
        }).then(root => {
            let result = root.FuseBox.import('./style.css'); 
            should.ok(result);
        });
    });
    
    it('No plugins should output unmodified input', () => {
        return getTestEnv({'style.css': style }, '>style.css', {
            plugins: [
                [PostCssPlugin(), RawPlugin()]
            ]
        }).then(root => {
            let result = root.FuseBox.import('./style.css');
            result.should.equal(style);
        });
    });
    
    it('Single test plugin', () => {
        return getTestEnv({'style.css': style }, '>style.css', {
            plugins: [
                [PostCssPlugin([pluginA]), RawPlugin()]
            ]
        }).then(root => {
            let result = root.FuseBox.import('./style.css');
            result.should.containEql('display: block');
        });
    });
    
    it('Several plugins', () => {
        return getTestEnv({'style.css': style }, '>style.css', {
            plugins: [
                [PostCssPlugin([pluginA, pluginB]), RawPlugin()]
            ]
        }).then(root => {
            let result = root.FuseBox.import('./style.css');
            result.should.containEql('display: block');
            result.should.not.containEql('#moon');
            result.should.containEql('.moon');
        });
    });
    
});
{'fraction_non_alphanumeric': 0.17362722351121423, 'fraction_numerical': 0.0019334880123743233, 'mean_word_length': 1.7997835497835497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7283543', 'n_tokens_mistral': 761, 'n_tokens_neox': 751, 'n_words': 126}