0.1.0 • Published 4 years ago

@springernature/util-sass-compiler v0.1.0

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

SASS Compiler

NPM version Node version MIT License

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