Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sassy-test

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sassy-test - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0

.github/workflows/static.yml

80

CHANGELOG.md
### Changelog
All notable changes to this project will be documented in this file.
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### [5.0.0](https://github.com/JohnAlbin/sassy-test/compare/4.0.2...5.0.0)
- feat!: Upgrade to sass npm package from node-sass; drop callback API [`66548d9`](https://github.com/JohnAlbin/sassy-test/commit/66548d95284b0325e9429da9f0c7b9f821f0feaa)
- feat: Switch from node-sass to sass
- feat: Drop callback-based APIs
- chore: Upgrade JS from CommonJS to ESModules
- chore(test): Migrate from nyc to c8
- chore(test): Upgrade eslint to v8
- chore(docs): Upgrade jsdoc to v4
- chore(test): Upgrade mocha to v10
- chore: Update development to Node.js v20
BREAKING CHANGE:
Drop callbacks from API. Developers should convert to the Promises API.
BREAKING CHANGE:
The old CommonJS entry point has been removed. Developers should switch their
codebase from CommonJS code to ESModules.
- Add workflow for GitHub Pages [`9187ad0`](https://github.com/JohnAlbin/sassy-test/commit/9187ad08c1c3633ab88aea9daee17b7747937a72)
- Update travis testing to Node v18/v20 [`837b40b`](https://github.com/JohnAlbin/sassy-test/commit/837b40b2c2fb0d690154c8a8449dbb10b0671b9b)
- docs: Update Pages URL [`41d853e`](https://github.com/JohnAlbin/sassy-test/commit/41d853e57e77373707837a5b036ddaa3c11d4a10)
#### [4.0.2](https://github.com/JohnAlbin/sassy-test/compare/4.0.1...4.0.2)
> 29 January 2018
- Release 4.0.2 [`5726fcf`](https://github.com/JohnAlbin/sassy-test/commit/5726fcf731cbc417187a200248a925a8ee19a755)
- Fix CHANGELOG [`9bbc988`](https://github.com/JohnAlbin/sassy-test/commit/9bbc988a34beee25fd165adc083931460e91d00e)

@@ -13,3 +39,5 @@ - Automate docs generation [`3e4a14c`](https://github.com/JohnAlbin/sassy-test/commit/3e4a14cf23908d28ffbf5808196fafab0bac2aa8)

#### [4.0.1](https://github.com/JohnAlbin/sassy-test/compare/4.0.0...4.0.1)
> 28 January 2018
- Update mocha to version 5.0.0 [`#20`](https://github.com/JohnAlbin/sassy-test/pull/20)

@@ -24,3 +52,5 @@ - Add package-lock.json [`a703e10`](https://github.com/JohnAlbin/sassy-test/commit/a703e102be3f43162e484f86ad0a5160dcc1daea)

### [4.0.0](https://github.com/JohnAlbin/sassy-test/compare/3.0.4...4.0.0)
> 4 December 2017
- chore(package): update mocha to version 4.0.0 [`#15`](https://github.com/JohnAlbin/sassy-test/pull/15)

@@ -30,2 +60,3 @@ - chore(package): update eslint to version 4.12.1 [`#18`](https://github.com/JohnAlbin/sassy-test/pull/18)

- Update all dependencies 🌴 [`#7`](https://github.com/JohnAlbin/sassy-test/pull/7)
- chore(package): update eslint to version 4.12.1 (#18) [`#11`](https://github.com/JohnAlbin/sassy-test/issues/11)
- Remove Babel [`5b8324f`](https://github.com/JohnAlbin/sassy-test/commit/5b8324fde82cb382e6bd7a20f9f2f2b49722b865)

@@ -44,19 +75,21 @@ - Build docs. [`5c621e0`](https://github.com/JohnAlbin/sassy-test/commit/5c621e0befc82b4270842ad6cab4f48025ac6c69)

- Update travis tests. [`7bbdb68`](https://github.com/JohnAlbin/sassy-test/commit/7bbdb685fd1bdaaec1d2f09bd7587944ec3d5049)
- Tag 4.0.0 [`eadf9ba`](https://github.com/JohnAlbin/sassy-test/commit/eadf9ba1ec551383e9336bdcb5c7a8a8a2452394)
- Build lib JS. [`a282789`](https://github.com/JohnAlbin/sassy-test/commit/a282789322ae1ace7dec7002aea9cfda1bcc7ca1)
- Tag 4.0.0 [`eadf9ba`](https://github.com/JohnAlbin/sassy-test/commit/eadf9ba1ec551383e9336bdcb5c7a8a8a2452394)
- Update docs to show what is returned when the Promise rejects. [`a9e6397`](https://github.com/JohnAlbin/sassy-test/commit/a9e6397a128d72bd9c678446c8f78e37d98caeaa)
- Update docs link to use HTTPS. [`c8cf00a`](https://github.com/JohnAlbin/sassy-test/commit/c8cf00a8267ecad056eeec235f6a04b7fcc7de49)
- chore(package): update dependencies [`bcc9517`](https://github.com/JohnAlbin/sassy-test/commit/bcc9517506e314a90a31a248cc4b1e0e70b6eba9)
- Update docs link to use HTTPS. [`c8cf00a`](https://github.com/JohnAlbin/sassy-test/commit/c8cf00a8267ecad056eeec235f6a04b7fcc7de49)
- Build JS. [`bcfcdf1`](https://github.com/JohnAlbin/sassy-test/commit/bcfcdf1a10981e9f81fcf4c3ffb2ccbb65c657bd)
- Update coveralls to 3.0.0 [`4bcaa0a`](https://github.com/JohnAlbin/sassy-test/commit/4bcaa0acc7877c1093d07c9afafd920c0d98e348)
- Add support for node-sass 4.0.0. [`395cdf0`](https://github.com/JohnAlbin/sassy-test/commit/395cdf04ad08bf8c57eff54516138b5ec98faacf)
- Prevent lock files in npm package [`a1eca5b`](https://github.com/JohnAlbin/sassy-test/commit/a1eca5be374476e5ea68cca4c46cfaa80eb3fbf4)
- Build JS. [`a9dfc71`](https://github.com/JohnAlbin/sassy-test/commit/a9dfc717b204a4abf3441cebe985e70a328be3f2)
- Drop support for Node.js 0.12 [`fc12d2d`](https://github.com/JohnAlbin/sassy-test/commit/fc12d2de1b8fdc6a92bcb80e13b220201ccbe122)
- Revert "chore(package): update node-sass to version 4.0.0 (#8)" [`d8d5e4b`](https://github.com/JohnAlbin/sassy-test/commit/d8d5e4b1410aa0656fe1f606d0290ed5fdac00b3)
- Update coveralls to 3.0.0 [`4bcaa0a`](https://github.com/JohnAlbin/sassy-test/commit/4bcaa0acc7877c1093d07c9afafd920c0d98e348)
- Fix test under Node.js v8. [`75f4d38`](https://github.com/JohnAlbin/sassy-test/commit/75f4d38e3fe69777edce4d9dc24649e7c37ce3de)
- Add CI tests for Node.js v8. [`8c2865f`](https://github.com/JohnAlbin/sassy-test/commit/8c2865f8bbc1819271ae12dc6959cb45e74b389a)
- Revert "chore(package): update node-sass to version 4.0.0 (#8)" [`d8d5e4b`](https://github.com/JohnAlbin/sassy-test/commit/d8d5e4b1410aa0656fe1f606d0290ed5fdac00b3)
- Build JS. [`a9dfc71`](https://github.com/JohnAlbin/sassy-test/commit/a9dfc717b204a4abf3441cebe985e70a328be3f2)
#### [3.0.4](https://github.com/JohnAlbin/sassy-test/compare/3.0.3...3.0.4)
> 30 March 2016
> 30 April 2016
- Update docs in README. [`65cd09f`](https://github.com/JohnAlbin/sassy-test/commit/65cd09f3e024a3723fafaee935ac46eafcaec025)

@@ -69,3 +102,5 @@ - Tag 3.0.4. [`38e9b88`](https://github.com/JohnAlbin/sassy-test/commit/38e9b8876bf70f2b96eac39d6bfaf323d422cf1e)

#### [3.0.3](https://github.com/JohnAlbin/sassy-test/compare/3.0.2...3.0.3)
> 29 March 2016
> 31 March 2016
- Update docs in README. [`c7d7b35`](https://github.com/JohnAlbin/sassy-test/commit/c7d7b358dbc3b9a86b38911436a0ef31a4152a7f)

@@ -75,3 +110,5 @@ - Tag 3.0.3. [`82e2f99`](https://github.com/JohnAlbin/sassy-test/commit/82e2f998241e85b5b1770f9dad6cd587b97b2c98)

#### [3.0.2](https://github.com/JohnAlbin/sassy-test/compare/3.0.1...3.0.2)
> 30 March 2016
- Promise is unexpectedly resolved successfully after Sass error. Fixes #5 [`#5`](https://github.com/JohnAlbin/sassy-test/issues/5)

@@ -84,3 +121,5 @@ - Build docs. [`8ffa6bf`](https://github.com/JohnAlbin/sassy-test/commit/8ffa6bf7d08930e5d844182125d7c09cb5a7e273)

#### [3.0.1](https://github.com/JohnAlbin/sassy-test/compare/3.0.0...3.0.1)
> 29 March 2016
- Tag 3.0.1. [`21a0952`](https://github.com/JohnAlbin/sassy-test/commit/21a0952146d49d57652dd544bab939fa926e6e46)

@@ -90,3 +129,5 @@ - Bugfix: bluebird is not a dev dependency. [`cd74138`](https://github.com/JohnAlbin/sassy-test/commit/cd741380c18706bc522a892e5ac9682021e109e0)

### [3.0.0](https://github.com/JohnAlbin/sassy-test/compare/2.0.0...3.0.0)
> 29 March 2016
- Return Promise if not given a callback. Fixes #4 [`#4`](https://github.com/JohnAlbin/sassy-test/issues/4)

@@ -102,4 +143,4 @@ - Module should export a constructor, not an object. Fixes #3 [`#3`](https://github.com/JohnAlbin/sassy-test/issues/3)

- Add assertResult() method. #4 [`b1df58d`](https://github.com/JohnAlbin/sassy-test/commit/b1df58dd055b20d4ed48f9ead8ee5fe3f6815e5f)
- Update README. [`4d40d9b`](https://github.com/JohnAlbin/sassy-test/commit/4d40d9b8e1331bb4463dab07af3551b36b2c96b8)
- Build docs. [`8069c4b`](https://github.com/JohnAlbin/sassy-test/commit/8069c4bd3e5032597ddfb0c3084cc4c7123cc536)
- Update README. [`4d40d9b`](https://github.com/JohnAlbin/sassy-test/commit/4d40d9b8e1331bb4463dab07af3551b36b2c96b8)
- Add babel-generated lib. [`2996bea`](https://github.com/JohnAlbin/sassy-test/commit/2996beac14ee99ad128c61ba80144e93e370dfbc)

@@ -111,4 +152,4 @@ - Update docs. [`8489fe8`](https://github.com/JohnAlbin/sassy-test/commit/8489fe89d18580f8124413d6e5de3948a9845db3)

- Update dependencies. [`37ad3e6`](https://github.com/JohnAlbin/sassy-test/commit/37ad3e6f04a4b87693efef7121372957eeab2773)
- Add .npmignore file. [`ea080b9`](https://github.com/JohnAlbin/sassy-test/commit/ea080b972114e6da998e99412d88c872cb9060e3)
- Fix tests on Node.js v0.12. [`9010c00`](https://github.com/JohnAlbin/sassy-test/commit/9010c006ef9e329d0dfe0ec85da5541d53e56e2e)
- Add .npmignore file. [`ea080b9`](https://github.com/JohnAlbin/sassy-test/commit/ea080b972114e6da998e99412d88c872cb9060e3)
- Update travis test configuration. [`07cc4a1`](https://github.com/JohnAlbin/sassy-test/commit/07cc4a14223fc53f175568def4ef46fdae784ecd)

@@ -122,3 +163,5 @@ - Tag 3.0.0. [`de2d2c7`](https://github.com/JohnAlbin/sassy-test/commit/de2d2c7355eb03ea2022008d66c9a97fec193e90)

### [2.0.0](https://github.com/JohnAlbin/sassy-test/compare/1.1.1...2.0.0)
> 17 November 2015
- Change library path string to includePaths array. [`db3e401`](https://github.com/JohnAlbin/sassy-test/commit/db3e4019c6de59be347a43f43786a501fd1c476e)

@@ -130,3 +173,5 @@ - Tag 2.0.0. [`212ecbf`](https://github.com/JohnAlbin/sassy-test/commit/212ecbf98ecafebfee0b22283c70afb4d4c3657b)

#### [1.1.1](https://github.com/JohnAlbin/sassy-test/compare/1.1.0...1.1.1)
> 16 September 2015
> 29 October 2015
- Do not delete Sass functions passed through to node-sass. [`051656f`](https://github.com/JohnAlbin/sassy-test/commit/051656f3bc157f2d37b0c69b6a5891b25f9126cc)

@@ -136,3 +181,5 @@ - Tag 1.1.1. [`5081ec2`](https://github.com/JohnAlbin/sassy-test/commit/5081ec2f24f7b079203b9b981dd066dfc836efa9)

#### [1.1.0](https://github.com/JohnAlbin/sassy-test/compare/1.0.1...1.1.0)
> 16 September 2015
- Add ability to catch Sass @warn/@debug messages. [`d4d5cbd`](https://github.com/JohnAlbin/sassy-test/commit/d4d5cbdc17f890cf8d5ef3b7bdcb98b76151e294)

@@ -143,3 +190,5 @@ - Tag 1.1.0. [`fcf34a8`](https://github.com/JohnAlbin/sassy-test/commit/fcf34a8841852fa0b36661cbefb86e19f01f29d4)

#### [1.0.1](https://github.com/JohnAlbin/sassy-test/compare/1.0.0...1.0.1)
> 16 September 2015
- Add missing LICENSE.txt file. [`11bf0e3`](https://github.com/JohnAlbin/sassy-test/commit/11bf0e368e47e8bdf4d8de704ee4742a618fd46d)

@@ -156,4 +205,6 @@ - Update docs. [`107ff2e`](https://github.com/JohnAlbin/sassy-test/commit/107ff2ec27f13bbf6cf4a4d8254ad04417d9e057)

#### [1.0.0](https://github.com/JohnAlbin/sassy-test/compare/1.0.0-beta.1...1.0.0)
### [1.0.0](https://github.com/JohnAlbin/sassy-test/compare/1.0.0-beta.1...1.0.0)
> 7 September 2015
- Add generated docs. [`1edff4b`](https://github.com/JohnAlbin/sassy-test/commit/1edff4b72f7fd8acbc987543f1cf291cce991987)

@@ -172,8 +223,9 @@ - Move module to lib/ folder. [`eee3c81`](https://github.com/JohnAlbin/sassy-test/commit/eee3c8187283c5b470d202422612b2044a4e63d6)

- Add link to GitHub from JS docs. [`37c9ba3`](https://github.com/JohnAlbin/sassy-test/commit/37c9ba33720475e89abb20ba1f9234166afa6764)
- Tag 1.0.0. [`a50eefe`](https://github.com/JohnAlbin/sassy-test/commit/a50eefe1059f85add28490a4875e903c7bb9dd39)
- Add simple install instructions. [`bc63719`](https://github.com/JohnAlbin/sassy-test/commit/bc637192e066def16034afb54d9097fc554f8e16)
- Tag 1.0.0. [`a50eefe`](https://github.com/JohnAlbin/sassy-test/commit/a50eefe1059f85add28490a4875e903c7bb9dd39)
#### 1.0.0-beta.1
> 7 September 2015
- Initial commit. [`9f7c2d7`](https://github.com/JohnAlbin/sassy-test/commit/9f7c2d773554ff2be69c615d098f2d16bc995555)

373

lib/sassy-test.js

@@ -1,10 +0,7 @@

'use strict';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { compileAsync, compileStringAsync } from 'sass';
const assert = require('assert'),
path = require('path'),
Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs')),
sass = Promise.promisifyAll(require('node-sass'));
/**

@@ -14,5 +11,5 @@ * A sassy-test helper object can be created with:

* // Import the SassyTest class.
* var SassyTest = require('sassy-test');
* import SassyTest from 'sassy-test';
* // Create a SassyTest object.
* var sassyTest = new SassyTest();
* const sassyTest = new SassyTest();
* ```

@@ -23,3 +20,3 @@ * @module sassy-test

/**
* A SassyTest object represents test helper for testing node-sass modules.
* A SassyTest object represents test helper for testing sass modules.
*

@@ -29,7 +26,7 @@ * This class is normally accessed via the

* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest();
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
* ```
*/
class SassyTest {
export default class SassyTest {
/**

@@ -43,10 +40,10 @@ * Creates a SassyTest object.

* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest({includePaths: ['/my/path/to/library']});
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest({loadPaths: ['/my/path/to/library']});
* ```
* is equivalent to:
* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest();
* sassyTest.configurePaths({includePaths: ['/my/path/to/library']});
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
* sassyTest.configurePaths({loadPaths: ['/my/path/to/library']});
* ```

@@ -63,6 +60,6 @@ *

// will also assume that the fixtures directory is in ./test/fixtures
this.paths.fixtures = path.join(__dirname, '../../../', 'test/fixtures');
this.paths.fixtures = path.join(path.dirname(fileURLToPath(import.meta.url)), '../../../', 'test/fixtures');
// No idea where the library's Sass files are, so no default.
this.paths.includePaths = [];
this.paths.loadPaths = [];

@@ -76,7 +73,7 @@ this.configurePaths(config);

* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest();
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
* sassyTest.configurePaths({
* fixtures: '/my/path/to/fixtures',
* includePaths: ['/my/path/to/library']
* loadPaths: ['/my/path/to/library']
* });

@@ -91,3 +88,3 @@ * ```

* @param {object} config - A configuration object containing the properties:
* `fixtures` and `includePaths`.
* `fixtures` and `loadPaths`.
*/

@@ -100,4 +97,4 @@ configurePaths(config) {

}
if (config.includePaths) {
this.paths.includePaths = config.includePaths;
if (config.loadPaths) {
this.paths.loadPaths = config.loadPaths;
}

@@ -114,11 +111,11 @@ }

* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest();
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
*
* // Returns full path to the test fixtures.
* var fixturePath = sassyTest.fixture();
* const fixturePath = sassyTest.fixture();
* // Returns full path to [fixtures]/sub-folder.
* var fixturePath = sassyTest.fixture('sub-folder');
* const fixturePath = sassyTest.fixture('sub-folder');
* // Returns full path to [fixtures]/sub-folder/_file.scss.
* var fixturePath = sassyTest.fixture('sub-folder', '_file.scss');
* const fixturePath = sassyTest.fixture('sub-folder', '_file.scss');
* ```

@@ -131,3 +128,3 @@ *

// Add the fixtures path to the start our list of paths.
var args = Array.prototype.slice.call(arguments);
const args = Array.prototype.slice.call(arguments);
args.unshift(this.paths.fixtures);

@@ -138,17 +135,9 @@ return path.join.apply(this, args);

/**
* Runs node-sass' render() with a light-weight wrapper.
* Runs sass' compile() with a light-weight wrapper.
*
* In addition to running node-sass' render(), this method:
* - adds the test fixtures path directory to the includePaths
* - ensures the includePaths are passed to node-sass
* In addition to running sass' compile(), this method:
* - adds the test fixtures path directory to the loadPaths
* - ensures the loadPaths are passed to sass
*
* And sassy-test modifies the [node-sass result
* object](https://github.com/sass/node-sass#result-object) by
* - converting the `css` property from a buffer to a string
* - converting the `map` property from a buffer to an object (Note: you will
* need to configure the proper sourcemap options before node-sass will add
* a `map` property.)
*
* Sassy-test also adds the following properties to the node-sass result
* object:
* Sassy-test also adds the following properties to the sass result object:
* - `warn`: An array containing the output of any @warn statements.

@@ -158,11 +147,9 @@ * - `debug`: An array containing the output of any @debug statements.

* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest();
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
*
* describe('a test suite', function() {
* it('should test something', function(done) {
* var options = {
* data: '@import "init"; // Imports fixtures/_init.scss.'
* };
* sassyTest.render(options, function(error, result) {
* const path = 'fixtures/_init.scss';
* sassyTest.compile(path, options, function(error, result) {
* assert.ifError(error);

@@ -176,55 +163,84 @@ * assert.ok(result.css);

*
* @param {object} options - The options to pass to node-sass' render(). For
* the full list of options, see the [node-sass documentation for
* "options"](https://github.com/sass/node-sass#options).
* @param {function} [callback] - An asynchronous callback with the signature
* of `function(error, result)`. In error conditions, the error argument is
* populated with the [node-sass error
* object](https://github.com/sass/node-sass#error-object). In success
* conditions, the result object is populated with an object describing the
* result of the render call.
* @returns {Promise|*} If no `callback` function is given, this method
* returns a Promise that resolves to node-sass' result object or rejects to
* node-sass' error object.
* @param {string} path The path to the file to be compiled.
* @param {object?} options The options to pass to sass' compile(). For
* the full list of options, see the [sass documentation for
* "options"](https://sass-lang.com/documentation/js-api/interfaces/options/).
* @returns {Promise} A Promise that resolves to sass' result object or
* rejects to sass' exception object.
*/
render(options, callback) {
compile(path, options = {}) {
return this._compileStringOrPath(path, null, options);
}
/**
* Runs sass' compileString() with a light-weight wrapper.
*
* In addition to running sass' compileString(), this method:
* - adds the test fixtures path directory to the loadPaths
* - ensures the loadPaths are passed to sass
*
* Sassy-test also adds the following properties to the sass result object:
* - `warn`: An array containing the output of any @warn statements.
* - `debug`: An array containing the output of any @debug statements.
*
* ```
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
*
* describe('a test suite', function() {
* it('should test something', async function() {
* let result;
* try {
* result = sassyTest.compileString(
* '@import "init"; // Imports fixtures/_init.scss.'
* options
* );
* } catch (error) {
* assert.ifError(error);
* }
* assert.ok(result.css);
* });
* });
* ```
*
* @param {string} string The path to the file to be compiled.
* @param {object?} options The options to pass to sass' compile(). For
* the full list of options, see the [sass documentation for
* "options"](https://sass-lang.com/documentation/js-api/interfaces/options/).
* @returns {Promise} A Promise that resolves to sass' result object or
* rejects to sass' exception object.
*/
compileString(string, options = {}) {
return this._compileStringOrPath(null, string, options);
}
_compileStringOrPath(filePath = null, string = null, options) {
if (typeof options !== 'object') {
let error = new Error('Options parameter of render method must be an object.');
if (callback) {
return callback(error, null);
} else {
return Promise.reject(error);
}
const error = new Error('Options parameter of compile method must be an object.');
return Promise.reject(error);
}
options.includePaths = options.includePaths || [];
options.loadPaths = options.loadPaths || [];
// Add the test fixtures directory.
options.includePaths.push(this.fixture());
options.loadPaths.push(this.fixture());
// Add the includePaths to node-sass' include paths.
if (this.paths.includePaths.length) {
Array.prototype.push.apply(options.includePaths, this.paths.includePaths);
// Add the loadPaths to sass' load paths.
if (this.paths.loadPaths.length) {
Array.prototype.push.apply(options.loadPaths, this.paths.loadPaths);
}
// Collect Sass warn() and debug() messages.
let warn = [],
const warn = [],
debug = [];
options.functions = options.functions || {};
options.functions['@warn'] = function(message) {
warn.push(message.getValue());
return sass.NULL;
options.logger = {
warn: function(message) {
warn.push(message);
},
debug: function(message) {
debug.push(message);
}
};
options.functions['@debug'] = function(message) {
debug.push(message.getValue());
return sass.NULL;
};
let handleResult = (result) => {
// Convert sass' result.css buffer to a string.
result.css = result.css.toString();
// Convert sass' sourcemap string to a JSON object.
if (result.map) {
result.map = JSON.parse(result.map.toString());
}
const handleResult = (result) => {
result.warn = warn;

@@ -236,13 +252,7 @@ result.debug = debug;

// Run node-sass' render().
if (callback) {
sass.render(options, function(error, result) {
if (error) {
callback(error, null);
} else {
callback(null, handleResult(result));
}
});
// Run sass' compile method.
if (string) {
return compileStringAsync(string, options).then(handleResult);
} else {
return sass.renderAsync(options).then(handleResult);
return compileAsync(filePath, options).then(handleResult);
}

@@ -252,5 +262,5 @@ }

/**
* Runs assertions against `renderFixture()`'s result object.
* Runs assertions against `compileFixture()`'s result object.
*
* The `renderFixture()` automatically calls this method to run a standard set
* The `compileFixture()` automatically calls this method to run a standard set
* of assertions against the result object before it is returned. If no Sass

@@ -264,3 +274,3 @@ * error occurs, `assertResult()` checks for an error when reading the

*
* @param {object} result The result object returned by `renderFixture()`.
* @param {object} result The result object returned by `compileFixture()`.
*/

@@ -276,9 +286,9 @@ assertResult(result) {

/**
* Renders the test fixture and returns the result.
* Compiles the test fixture and returns the result.
*
* Looks inside the specified folder in test/fixtures, renders the input.scss
* file and reads the output.css file. Before it returns the node-sass result
* Looks inside the specified folder in test/fixtures, compiles the input.scss
* file and reads the output.css file. Before it returns the sass result
* object, it calls `assertResult()` to run a standard set of assertions.
*
* renderFixture() does not test for errors itself; it requires the callback
* compileFixture() does not test for errors itself; it requires the caller
* to decide if a Sass error is a test failure or not. Good Sass libraries

@@ -288,30 +298,18 @@ * should `@error` if used incorrectly and sassy-test lets you see these

*
* Sassy-test modifies the [node-sass result
* object](https://github.com/sass/node-sass#result-object) by
* - converting the `css` property from a buffer to a string
* - converting the `map` property from a buffer to an object (Note: you will
* need to configure the proper sourcemap options before node-sass will add
* a `map` property.)
*
* Sassy-test also adds the following properties to the node-sass result
* object:
* Sassy-test also adds the following properties to the sass result object:
* - `warn`: An array containing the output of any @warn statements.
* - `debug`: An array containing the output of any @debug statements.
* - sassError: A node-sass error object which contains @error statements, if
* any.
* - sassError: A sass error object which contains @error statements, if any.
* - expectedOutput: The text of the output.css file; should match the `css`
* property provided by node-sass.
* property provided by sass.
*
* ```
* var SassyTest = require('sassy-test');
* var sassyTest = new SassyTest();
* import SassyTest from 'sassy-test';
* const sassyTest = new SassyTest();
*
* describe('a test suite', function() {
* it('should test something', function(done) {
* var options = {
* data: '@import "init"; // Imports fixtures/_init.scss.'
* };
* sassyTest.renderFixture('sometest', options, function(error, result) {
* // If there was no error, renderFixture() has already compared
* // the rendered output of fixtures/sometest/input.scss to
* it('should test something', async function() {
* sassyTest.compileFixture('sometest', options, function(error, result) {
* // If there was no error, compileFixture() has already compared
* // the compiled output of fixtures/sometest/input.scss to
* // fixtures/sometest/output.css.

@@ -327,27 +325,19 @@ * assert.ifError(error);

* directory) to the fixture to test.
* @param {object} options - The options to pass to node-sass' render(). For
* the full list of options, see the [node-sass documentation for
* "options"](https://github.com/sass/node-sass#options).
* @param {function} [callback] - An asynchronous callback with the signature
* of `function(error, result)`. In error conditions, the error argument is
* populated with the [node-sass error
* object](https://github.com/sass/node-sass#error-object). In success
* conditions, the result object is populated with an object describing the
* result of the render call.
* @returns {Promise|*} If no `callback` function is given, this method
* returns a Promise that resolves to node-sass' result object or rejects to
* node-sass' error object.
* @param {object} options - The options to pass to sass' compile(). For the
* full list of options, see the [sass documentation for
* "options"](https://sass-lang.com/documentation/js-api/interfaces/options/).
* @returns {Promise} A Promise that resolves to sass' result object or
* rejects to sass' exception object.
*/
renderFixture(fixtureDirectory, options, callback) {
options = options || /* istanbul ignore next */ {};
compileFixture(fixtureDirectory, options = {}) {
options = options || /* c8 ignore next */ {};
// Read the test from input.scss file in the specified fixture directory.
options.file = this.fixture(fixtureDirectory, 'input.scss');
// Include the sourcemap in the results object, but don't put the sourcemap
// URL in the output file.
const file = this.fixture(fixtureDirectory, 'input.scss');
const outFile = this.fixture(fixtureDirectory, 'output.css');
// Include the sourcemap in the results object.
options.sourceMap = true;
options.omitSourceMapUrl = true;
options.outFile = this.fixture(fixtureDirectory, 'output.css');
let test = {
const test = {
result: null,

@@ -358,5 +348,5 @@ expectedOutput: null,

let handleResult = (test) => {
// Move our properties into the node-sass result object.
let result = test.result || /* istanbul ignore next */ {};
const handleResult = (test) => {
// Move our properties into the sass result object.
const result = test.result || /* c8 ignore next */ {};
result.expectedOutput = test.expectedOutput;

@@ -370,69 +360,22 @@ result.expectedOutputFileError = test.expectedOutputFileError;

if (callback) {
test.completedSassRender = false;
test.completedReadFile = false;
test.sassError = null;
var compareResults = () => {
// We are waiting for all tasks to complete before completing this task.
if (!test.completedSassRender || !test.completedReadFile) {
return;
}
// Give the callback access to the results.
if (test.sassError) {
callback(test.sassError, null);
} else {
callback(null, handleResult(test));
}
};
// Do a sass.render() on the input.scss file.
this.render(options, function(error, result) {
return Promise.all([
// Do a sass.compile() on the input.scss file.
this.compile(file, options).then(result => {
test.result = result;
test.sassError = error;
return Promise.resolve();
}),
// Declare this task completed.
test.completedSassRender = true;
compareResults();
});
// Read the output.css file.
fs.readFile(options.outFile, function(error, expectedOutput) {
readFile(outFile).then(expectedOutput => {
// Convert fs' data buffer to a string.
test.expectedOutput = expectedOutput.toString();
return Promise.resolve();
}).catch(error => {
test.expectedOutputFileError = error;
test.expectedOutput = expectedOutput;
// Convert fs' data buffer to a string.
if (!error) {
test.expectedOutput = expectedOutput.toString();
}
// Declare this task completed.
test.completedReadFile = true;
compareResults();
});
} else {
return Promise.all([
// Do a sass.render() on the input.scss file.
this.render(options).then(result => {
test.result = result;
return Promise.resolve();
}),
// Read the output.css file.
fs.readFileAsync(options.outFile).then(expectedOutput => {
// Convert fs' data buffer to a string.
test.expectedOutput = expectedOutput.toString();
return Promise.resolve();
}).catch(error => {
test.expectedOutputFileError = error;
return Promise.resolve();
})
]).then(() => {
return Promise.resolve(handleResult(test));
});
}
return Promise.resolve();
})
]).then(() => {
return Promise.resolve(handleResult(test));
});
}
}
module.exports = SassyTest;
{
"name": "sassy-test",
"version": "4.0.2",
"version": "5.0.0",
"description": "A simple helper utility for creating unit tests of Sass modules. Works great with mocha or jasmine.",

@@ -11,8 +11,7 @@ "homepage": "https://github.com/JohnAlbin/sassy-test",

"type": "git",
"url": "git://github.com/JohnAlbin/sassy-test.git"
"url": "git+https://github.com/JohnAlbin/sassy-test.git"
},
"author": "John Albin Wilkins <virtually.johnalbin@gmail.com> (http://john.albin.net/)",
"author": "John Albin Wilkins <virtually.johnalbin@gmail.com> (https://john.albin.net/)",
"license": "(MIT OR GPL-2.0)",
"keywords": [
"node-sass",
"sass",

@@ -25,3 +24,4 @@ "mocha",

],
"main": "index.js",
"type": "module",
"module": "./lib/sassy-test.js",
"directories": {

@@ -31,6 +31,6 @@ "test": "test"

"scripts": {
"test": "nyc mocha",
"test": "c8 mocha",
"posttest": "eslint .",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"report": "nyc --reporter=html mocha",
"coverage": "c8 report --reporter=text-lcov | coveralls",
"report": "c8 --reporter=html mocha",
"changelog": "auto-changelog --commit-limit false --unreleased",

@@ -41,14 +41,29 @@ "preversion": "npm test",

"dependencies": {
"bluebird": "^3.3.4",
"node-sass": "^3.3.2 || ^4.0.0"
"sass": "^1.69.5"
},
"devDependencies": {
"auto-changelog": "^1.4.0",
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"eslint": "^4.12.1",
"jsdoc": "^3.4.0",
"mocha": "^5.0.0",
"nyc": "^11.3.0"
"auto-changelog": "^2.4.0",
"c8": "^8.0.1",
"chai": "^4.3.10",
"coveralls": "^3.1.1",
"eslint": "^8.53.0",
"jsdoc": "^4.0.2",
"mocha": "^10.2.0"
},
"c8": {
"all": true,
"include": [
"lib"
],
"exclude": [],
"check-coverage": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100,
"reporter": [
"text-summary",
"lcov"
]
}
}

@@ -1,4 +0,3 @@

[![Build Status](https://secure.travis-ci.org/JohnAlbin/sassy-test.png?branch=master)](http://travis-ci.org/JohnAlbin/sassy-test/builds) [![Coverage Status](https://coveralls.io/repos/JohnAlbin/sassy-test/badge.svg?branch=master&service=github)](https://coveralls.io/github/JohnAlbin/sassy-test?branch=master)
[![Coverage Status](https://coveralls.io/repos/JohnAlbin/sassy-test/badge.svg?branch=master&service=github)](https://coveralls.io/github/JohnAlbin/sassy-test?branch=master)
# Sassy Test

@@ -8,3 +7,3 @@

Sassy Test models its testing after the unit tests in LibSass. LibSass has a series of sub-folders in its "test/fixtures" directory that contain an "input" Sass file and an "output" CSS file. Its unit tests then reference a particular folder, render the input.scss and compare the results to the output.css file.
Sassy Test models its testing after the unit tests in LibSass. The tests are a series of sub-folders in the "test/fixtures" directory that contain an "input" Sass file and an "output" CSS file. Its unit tests then reference a particular folder, compile the input.scss and compare the results to the output.css file.

@@ -45,11 +44,9 @@ To get started, just install Sassy Test as a development dependency of your Sass module with: `npm install --save-dev sassy-test`

```JavaScript
'use strict';
import path from 'node:path';
import { expect } from 'chai';
import SassyTest from 'sassy-test';
var path = require('path');
var expect = require('chai').expect;
var SassyTest = require('sassy-test');
var sassyTest = new SassyTest({
const sassyTest = new SassyTest({
// Path to the Sass module we are testing and its dependencies.
includePaths: [
loadPaths: [
path.join(__dirname, '../sass'),

@@ -65,42 +62,47 @@ path.join(__dirname, '../node_modules/breakpoint-sass/stylesheets')

describe('@function my-modules-function()', function() {
it('should test an aspect of this function', function(done) {
// Sassy Test's renderFixture() will run a comparison test between the
// rendered input.scss and the output.css found in the fixtures
it('should test an aspect of this function', async function() {
// Sassy Test's compileFixture() will run a comparison test between the
// compiled input.scss and the output.css found in the fixtures
// sub-directory specified in its first parameter, in this case:
// test/fixtures/my-modules-function
sassyTest.renderFixture('my-modules-function', {}, function(error, result) {
// If we expect the comparison test to succeed, we just need to test
// that no error occurred and then done(), but we can run other tests
// here if we desire.
expect(error).to.not.exist;
done();
});
return sassyTest.compileFixture('my-modules-function')
.catch(error => {
// If we expect the comparison test to succeed, we just need to test
// that no error occurred.
expect(error).to.not.exist;
})
.then(result => {
// No additional assertions are needed, but we can run other tests
// here if we desire.
});
});
it('should throw an error in this situation', function(done) {
// Sassy Test's renderFixture() can also test if your module produces an
it('should throw an error in this situation', async function() {
// Sassy Test's compileFixture() can also test if your module produces an
// intentional error with Sass' @error directive.
sassyTest.renderFixture('my-modules-error', {}, function(error, result) {
// If the Sass in test/fixtures/my-modules-error/input.scss triggers an
// @error in your module, you should expect the error object to exist
// and to contain the error message from your module.
expect(error).to.exist;
expect(error.message).to.equal('Some helpful error message from your module.');
done();
});
return sassyTest.compileFixture('my-modules-error')
.catch(error => {
// If the Sass in test/fixtures/my-modules-error/input.scss triggers an
// @error in your module, you should expect the error object to exist
// and to contain the error message from your module.
expect(error).to.exist;
expect(error.message).to.equal('Some helpful error message from your module.');
});
});
it('should warn in another situation', function(done) {
// Sassy Test's renderFixture() can also test if your module produces an
it('should warn in another situation', async function() {
// Sassy Test's compileFixture() can also test if your module produces an
// intentional warning message with Sass' @warn directive.
sassyTest.renderFixture('my-modules-warn', {}, function(error, result) {
// If the Sass in test/fixtures/my-modules-warn/input.scss triggers a
// @warn in your module, you should expect the result object to exist
// and to contain the warn message from your module.
expect(error).to.not.exist;
// Sassy Test adds two new arrays to node-sass' result object:
// result.warn and result.debug are arrays of strings.
expect(result.warn[0]).to.equal('Some helpful warning from your module.');
done();
});
return sassyTest.compileFixture('my-modules-warn')
.catch(error => {
// If the Sass in test/fixtures/my-modules-warn/input.scss triggers a
// @warn in your module, you should expect the result object to exist
// and to contain the warn message from your module.
expect(error).to.not.exist;
})
.then(result => {
// Sassy Test adds two new arrays to sass' result object:
// result.warn and result.debug are arrays of strings.
expect(result.warn[0]).to.equal('Some helpful warning from your module.');
});
});

@@ -115,3 +117,3 @@ });

SassyTest's `render()` and `renderFixture()` methods will return a `Promise` if you don't provide a callback. Promises are available with Node.js 4.0.0 and later, or a Promise-compliant module on earlier versions of Node.js.
SassyTest's `compile()`, `compileString()` and `compileFixture()` methods return a `Promise`.

@@ -123,9 +125,9 @@ ```JavaScript

// Mocha accepts sassyTest's returned Promise.
return sassyTest.renderFixture('my-modules-function');
return sassyTest.compileFixture('my-modules-function');
});
it('should throw an error in this situation', function() {
return sassyTest.renderFixture('my-modules-error').then(function(result) {
return sassyTest.compileFixture('my-modules-error').then(function(result) {
// If the expected Sass error does not occur, we need to fail the test.
throw new Error('An error should have occurred');
expect(result).to.not.exist('An error should have occurred');
}).catch(function(error) {

@@ -138,3 +140,3 @@ expect(error).to.exist;

it('should warn in another situation', function() {
return sassyTest.renderFixture('my-modules-warn').then(function(result) {
return sassyTest.compileFixture('my-modules-warn').then(function(result) {
expect(result.warn[0]).to.equal('Some helpful warning from your module.');

@@ -147,3 +149,3 @@ });

[Full documentation of Sassy Test’s JavaScript API](https://johnalbin.github.io/sassy-test) is available online.
[Full documentation of Sassy Test’s JavaScript API](https://johnalbin.github.io/sassy-test/) is available online.

@@ -150,0 +152,0 @@ ## Development

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc