@springernature/util-sass-compiler
v0.1.0
Published
Promisify SASS.render and add JSON output
Downloads
3
Maintainers
Keywords
Readme
SASS Compiler
Helper module for compiling SASS using node-sass
, and returning the result as either CSS
or JSON
within a <Promise>
. Used for testing SASS logic using Jest.
Install
$ npm install @springernature/util-sass-compiler
Usage
The render
function returns an Object of the form
{
"css": <Buffer>,
"stats": {},
"json": {}
}
Example
Below is a simple example, see the test folder for more.
import {render} from '@springernature/util-sass-compiler';
describe('Compile Some SASS', () => {
test('CSS String', async () => {
const result = await render({
data: `
$size: 100px;
.foo {
width: $size;
}`;
});
expect(result.css.toString().trim()).toEqual('.foo{width:100px}');
});
test('JSON match', async () => {
const result = await render({
data: `
$size: 100px;
.foo {
width: $size;
}`;
});
expect(result.json).toEqual(
expect.objectContaining({
'.foo': {
'width': '100px'
}
})
);
});
});
License
MIT License © 2020, Springer Nature