Home Run postcss process multiple times with different settings
Reply: 0

Run postcss process multiple times with different settings

Arpad from KD Web
1#
Arpad from KD Web Published in 2017-12-07 10:57:23Z

I am trying to write a utility function for my tests for postcss plugins. I want to compare processed results with expected ones via jest.

My issue is that the postcss process returns the same result for different files.

let fs = require('fs');
let postcss = require('postcss');
let plugin = require('./');
let run = (testFile, options = {}, plugins = []) => {
    return new Promise((resolve, reject) => {
        let inputFile = `./tests/${testFile}`;
        let expectFile = inputFile.replace('.css', '.expected.css');
        let input = fs.readFileSync(inputFile).toString();
        let expect = fs.readFileSync(expectFile).toString();
        plugins.unshift(plugin);
        postcss(plugins)
            .process(input, Object.assign({
                from: inputFile,
                to: expectFile
            }, options))
            .then(result => {
                resolve(expect(result.css.trim()).toEqual(expect.trim()));
            })
            .catch(error => reject(error));
    });
};

it('stacks css rules', () => run('stacking.css'));
it('import files', () => run('import.css'));

I essentially want to be able to check a processed stacking.css to a stacking.expected.css. And then the same thing with import.css and import.expected.css. But although the input files are different, postcss return the same result (always the first to be processed) both times.

Is there a way to do this?

I've tried without a promise, I've tried expect().resolves.toEqual() inside the function passed into it also tried postcss.process().css

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298847 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO