sassy-test
Advanced tools
Comparing version 2.0.0 to 3.0.0
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var assert = require('assert'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
sass = require('node-sass'); | ||
path = require('path'), | ||
Promise = require('bluebird'); | ||
var fs = Promise.promisifyAll(require('fs')), | ||
sass = Promise.promisifyAll(require('node-sass')); | ||
/** | ||
* The core sassy-test API can be imported with: | ||
* A sassy-test helper object can be created with: | ||
* ``` | ||
* var sassyTest = require('sassy-test'); | ||
* // Import the SassyTest class. | ||
* var SassyTest = require('sassy-test'); | ||
* // Create a SassyTest object. | ||
* var sassyTest = new SassyTest(); | ||
* ``` | ||
@@ -16,13 +27,52 @@ * @module sassy-test | ||
module.exports = { | ||
/** | ||
* A SassyTest object represents test helper for testing node-sass modules. | ||
* | ||
* This class is normally accessed via the | ||
* [`sassy-test`]{@link module:sassy-test} module: | ||
* ``` | ||
* var SassyTest = require('sassy-test'); | ||
* var sassyTest = new SassyTest(); | ||
* ``` | ||
*/ | ||
paths: { | ||
var SassyTest = function () { | ||
/** | ||
* Creates a SassyTest object. | ||
* | ||
* If the optional initialization object is given to the constructor, it will | ||
* be passed to the `configurePaths()` method. | ||
* | ||
* For example, this: | ||
* ``` | ||
* var SassyTest = require('sassy-test'); | ||
* var sassyTest = new SassyTest({includePaths: ['/my/path/to/library']}); | ||
* ``` | ||
* is equivalent to: | ||
* ``` | ||
* var SassyTest = require('sassy-test'); | ||
* var sassyTest = new SassyTest(); | ||
* sassyTest.configurePaths({includePaths: ['/my/path/to/library']}); | ||
* ``` | ||
* | ||
* @param {object} [config] Optional initialization object. | ||
*/ | ||
function SassyTest(config) { | ||
_classCallCheck(this, SassyTest); | ||
config = config || {}; | ||
this.paths = {}; | ||
// Assuming this is normally installed in ./node_modules/sassy-test/lib, we | ||
// will also assume that the fixtures directory is in ./test/fixtures | ||
fixtures: path.join(__dirname, '../../../', 'test/fixtures'), | ||
this.paths.fixtures = path.join(__dirname, '../../../', 'test/fixtures'); | ||
// No idea where the library's Sass files are, so no default. | ||
includePaths: [] | ||
}, | ||
this.paths.includePaths = []; | ||
this.configurePaths(config); | ||
} | ||
/** | ||
@@ -32,3 +82,4 @@ * Configures the paths needed for the sassyTest object. | ||
* ``` | ||
* var sassyTest = require('sassy-test'); | ||
* var SassyTest = require('sassy-test'); | ||
* var sassyTest = new SassyTest(); | ||
* sassyTest.configurePaths({ | ||
@@ -48,89 +99,116 @@ * fixtures: '/my/path/to/fixtures', | ||
*/ | ||
configurePaths: function(config) { | ||
// Don't override the default values or previously-set values, if no new | ||
// values are provided. | ||
if (config.fixtures) { | ||
this.paths.fixtures = config.fixtures; | ||
_createClass(SassyTest, [{ | ||
key: 'configurePaths', | ||
value: function configurePaths(config) { | ||
// Don't override the default values or previously-set values, if no new | ||
// values are provided. | ||
if (config.fixtures) { | ||
this.paths.fixtures = config.fixtures; | ||
} | ||
if (config.includePaths) { | ||
this.paths.includePaths = config.includePaths; | ||
} | ||
} | ||
if (config.includePaths) { | ||
this.paths.includePaths = config.includePaths; | ||
/** | ||
* Returns the full path to the requested test fixture. | ||
* | ||
* When called without any parameters, this method returns the path to the | ||
* test fixtures directory. If one or more parameters are given, the method | ||
* will append them to the returned path. | ||
* | ||
* ``` | ||
* var SassyTest = require('sassy-test'); | ||
* var sassyTest = new SassyTest(); | ||
* | ||
* // Returns full path to the test fixtures. | ||
* var fixturePath = sassyTest.fixture(); | ||
* // Returns full path to [fixtures]/sub-folder. | ||
* var fixturePath = sassyTest.fixture('sub-folder'); | ||
* // Returns full path to [fixtures]/sub-folder/_file.scss. | ||
* var fixturePath = sassyTest.fixture('sub-folder', '_file.scss'); | ||
* ``` | ||
* | ||
* @param {...string} path - Optional paths inside the fixtures directory. | ||
* @returns {string} The path to the requested test fixture. | ||
*/ | ||
}, { | ||
key: 'fixture', | ||
value: function fixture() { | ||
// Add the fixtures path to the start our list of paths. | ||
var args = Array.prototype.slice.call(arguments); | ||
args.unshift(this.paths.fixtures); | ||
return path.join.apply(this, args); | ||
} | ||
}, | ||
/** | ||
* Returns the full path to the requested test fixture. | ||
* | ||
* When called without any parameters, this method returns the path to the | ||
* test fixtures directory. If one or more parameters are given, the method | ||
* will append them to the returned path. | ||
* | ||
* ``` | ||
* var sassyTest = require('sassy-test'); | ||
* | ||
* // Returns full path to the test fixtures. | ||
* var fixturePath = sassyTest.fixture(); | ||
* // Returns full path to [fixtures]/sub-folder. | ||
* var fixturePath = sassyTest.fixture('sub-folder'); | ||
* // Returns full path to [fixtures]/sub-folder/_file.scss. | ||
* var fixturePath = sassyTest.fixture('sub-folder', '_file.scss'); | ||
* ``` | ||
* | ||
* @param {...string} path - Optional paths inside the fixtures directory. | ||
* @returns {string} The path to the requested test fixture. | ||
*/ | ||
fixture: function() { | ||
// Add the fixtures path to the start our list of paths. | ||
var args = Array.prototype.slice.call(arguments); | ||
args.unshift(this.paths.fixtures); | ||
return path.join.apply(this, args); | ||
}, | ||
/** | ||
* Runs node-sass' render() 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 | ||
* | ||
* 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: | ||
* - `warn`: An array containing the output of any @warn statements. | ||
* - `debug`: An array containing the output of any @debug statements. | ||
* | ||
* ``` | ||
* var SassyTest = require('sassy-test'); | ||
* var 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) { | ||
* assert.ifError(error); | ||
* assert.ok(result.css); | ||
* done(); | ||
* }); | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @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. | ||
*/ | ||
/** | ||
* Runs node-sass' render() 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 | ||
* - converts render.css from a buffer to a string | ||
* - converts render.map to an object (Note: you will need to configure the | ||
* proper sourcemap options) | ||
* - Captures messages generated with `@warn` and puts them in an array stored | ||
* in render.warn. | ||
* - Captures messages generated with `@debug` and puts them in an array | ||
* stored in render.debug. | ||
* | ||
* ``` | ||
* var sassyTest = require('sassy-test'); | ||
* | ||
* 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) { | ||
* assert.ifError(error); | ||
* assert.ok(result.css); | ||
* }); | ||
* done(); | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @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 error object. In success conditions, the result object | ||
* is populated with an object describing the result of the render call. For | ||
* full details, see the [node-sass documentation for the error and result | ||
* objects](https://github.com/sass/node-sass#error-object). | ||
*/ | ||
render: function(options, callback) { | ||
try { | ||
var warn = [], | ||
debug = []; | ||
}, { | ||
key: 'render', | ||
value: function render(options, callback) { | ||
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { | ||
var error = new Error('Options parameter of render method must be an object.'); | ||
if (callback) { | ||
return callback(error, null); | ||
} else { | ||
return Promise.reject(error); | ||
} | ||
} | ||
options.includePaths = options.includePaths || []; | ||
// Add the test fixtures directory. | ||
options.includePaths.push(this.fixture()); | ||
// Add the includePaths to node-sass' include paths. | ||
@@ -140,8 +218,12 @@ if (this.paths.includePaths.length) { | ||
} | ||
// Collect Sass warn() and debug() messages. | ||
var warn = [], | ||
debug = []; | ||
options.functions = options.functions || {}; | ||
options.functions['@warn'] = function(message) { | ||
options.functions['@warn'] = function (message) { | ||
warn.push(message.getValue()); | ||
return sass.NULL; | ||
}; | ||
options.functions['@debug'] = function(message) { | ||
options.functions['@debug'] = function (message) { | ||
debug.push(message.getValue()); | ||
@@ -151,127 +233,224 @@ return sass.NULL; | ||
var handleResult = function 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()); | ||
} | ||
result.warn = warn; | ||
result.debug = debug; | ||
return result; | ||
}; | ||
// Run node-sass' render(). | ||
sass.render(options, function(error, result) { | ||
if (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()); | ||
if (callback) { | ||
sass.render(options, function (error, result) { | ||
if (error) { | ||
callback(error, null); | ||
} else { | ||
callback(null, handleResult(result)); | ||
} | ||
result.warn = warn; | ||
result.debug = debug; | ||
} | ||
callback(error, result); | ||
}); | ||
} catch (err) { | ||
callback(err, null); | ||
}); | ||
} else { | ||
return sass.renderAsync(options).then(handleResult); | ||
} | ||
} | ||
}, | ||
/** | ||
* Renders 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. If no Sass error occurs, it compares | ||
* the results to the expected output using `assert.strictEqual()`. | ||
* | ||
* renderFixture() does not test for errors itself; it requires the callback | ||
* to decide if a Sass error is a test failure or not. Good Sass libraries | ||
* should `@error` if used incorrectly and sassy-test lets you see these | ||
* errors and assert they were the expected result. | ||
* | ||
* ``` | ||
* var sassyTest = require('sassy-test'); | ||
* | ||
* 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 | ||
* // fixtures/sometest/output.css. | ||
* assert.ifError(error); | ||
* }); | ||
* done(); | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @param {string} fixtureDirectory - The path (relative to the fixtures base | ||
* 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, expectedOutput)`. The expectedOutput is always | ||
* given the contents of the output.css file in the specified fixture. In | ||
* error conditions, the error argument is populated with the error object. | ||
* In success conditions, the result object is populated with an object | ||
* describing the result of the render call. For full details, see the | ||
* [node-sass documentation for the error and result | ||
* objects](https://github.com/sass/node-sass#error-object). | ||
*/ | ||
renderFixture: function(fixtureDirectory, options, callback) { | ||
options = options || /* istanbul ignore next */ {}; | ||
/** | ||
* Runs assertions against `renderFixture()`'s result object. | ||
* | ||
* The `renderFixture()` automatically calls this method to run a standard set | ||
* of assertions against the result object before it is returned. If no Sass | ||
* error occurs, `assertResult()` checks for an error when reading the | ||
* output.css file using `assert.ifError()` and compares the results to the | ||
* expected output using `assert.strictEqual()`. | ||
* | ||
* If the SassyTest user chooses, this method can be overridden to perform | ||
* different assertions. | ||
* | ||
* @param {object} result The result object returned by `renderFixture()`. | ||
*/ | ||
var results = { | ||
completedSassRender: false, | ||
completedReadFile: false | ||
}; | ||
var compareResults = function() { | ||
// We are waiting for all tasks to complete before completing this task. | ||
if (!results.completedSassRender || !results.completedReadFile) { | ||
return; | ||
} | ||
}, { | ||
key: 'assertResult', | ||
value: function assertResult(result) { | ||
// We always return a Sass error, so don't run our assertions if there is | ||
// a Sass error. | ||
if (!result.sassError) { | ||
// A missing output.css file is a hard fail. | ||
assert.ifError(result.expectedOutputFileError); | ||
// If no errors, compare the Sass compilation to the expected output file. | ||
if (!results.sassError && !results.outputError) { | ||
assert.strictEqual(results.result.css, results.expectedOutput); | ||
// Compare the Sass compilation to the expected output file. | ||
assert.strictEqual(result.css, result.expectedOutput); | ||
} | ||
} | ||
// Give the callback access to the results. | ||
if (results.outputError && !results.sassError) { | ||
// Ensure the callback notices the output error by removing the sass | ||
// result. | ||
callback(results.outputError, null, null); | ||
} else { | ||
callback(results.sassError, results.result, results.expectedOutput); | ||
} | ||
}; | ||
/** | ||
* Renders 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 | ||
* object, it calls `assertResult()` to run a standard set of assertions. | ||
* | ||
* renderFixture() does not test for errors itself; it requires the callback | ||
* to decide if a Sass error is a test failure or not. Good Sass libraries | ||
* should `@error` if used incorrectly and sassy-test lets you see these | ||
* errors and assert they were the expected result. | ||
* | ||
* 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: | ||
* - `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. | ||
* - expectedOutput: The text of the output.css file; should match the `css` | ||
* property provided by node-sass. | ||
* | ||
* ``` | ||
* var SassyTest = require('sassy-test'); | ||
* var 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 | ||
* // fixtures/sometest/output.css. | ||
* assert.ifError(error); | ||
* done(); | ||
* }); | ||
* }); | ||
* }); | ||
* ``` | ||
* | ||
* @param {string} fixtureDirectory - The path (relative to the fixtures base | ||
* 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. | ||
*/ | ||
// 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. | ||
options.sourceMap = true; | ||
options.omitSourceMapUrl = true; | ||
options.outFile = this.fixture(fixtureDirectory, 'output.css'); | ||
}, { | ||
key: 'renderFixture', | ||
value: function renderFixture(fixtureDirectory, options, callback) { | ||
var _this = this; | ||
// Do a sass.render() on the input.scss file. | ||
this.render(options, function(error, result) { | ||
results.result = result; | ||
results.sassError = error; | ||
options = options || /* istanbul ignore next */{}; | ||
// Declare this task completed. | ||
results.completedSassRender = true; | ||
compareResults(); | ||
}); | ||
// 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. | ||
options.sourceMap = true; | ||
options.omitSourceMapUrl = true; | ||
options.outFile = this.fixture(fixtureDirectory, 'output.css'); | ||
// Read the output.css file. | ||
fs.readFile(options.outFile, function(error, expectedOutput) { | ||
results.outputError = error; | ||
results.expectedOutput = expectedOutput; | ||
var test = { | ||
result: null, | ||
sassError: null, | ||
expectedOutput: null, | ||
expectedOutputFileError: null | ||
}; | ||
// Convert fs' data buffer to a string. | ||
if (!error) { | ||
results.expectedOutput = expectedOutput.toString(); | ||
var handleResult = function handleResult(test) { | ||
// Move our properties into the node-sass result object. | ||
var result = test.result || {}; | ||
result.sassError = test.sassError; | ||
result.expectedOutput = test.expectedOutput; | ||
result.expectedOutputFileError = test.expectedOutputFileError; | ||
_this.assertResult(result); | ||
return result; | ||
}; | ||
if (callback) { | ||
test.completedSassRender = false; | ||
test.completedReadFile = false; | ||
var compareResults = function 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. | ||
callback(test.sassError, handleResult(test)); | ||
}; | ||
// Do a sass.render() on the input.scss file. | ||
this.render(options, function (error, result) { | ||
test.result = result; | ||
test.sassError = error; | ||
// Declare this task completed. | ||
test.completedSassRender = true; | ||
compareResults(); | ||
}); | ||
// Read the output.css file. | ||
fs.readFile(options.outFile, function (error, expectedOutput) { | ||
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).catch(function (error) { | ||
test.sassError = error; | ||
return Promise.resolve(null); | ||
}).then(function (result) { | ||
test.result = result; | ||
return Promise.resolve(); | ||
}), | ||
// Read the output.css file. | ||
fs.readFileAsync(options.outFile).catch(function (error) { | ||
test.expectedOutputFileError = error; | ||
return Promise.resolve(null); | ||
}).then(function (expectedOutput) { | ||
if (expectedOutput) { | ||
// Convert fs' data buffer to a string. | ||
test.expectedOutput = expectedOutput.toString(); | ||
} | ||
return Promise.resolve(); | ||
})]).then(function () { | ||
return Promise.resolve(handleResult(test)); | ||
}); | ||
} | ||
} | ||
}]); | ||
// Declare this task completed. | ||
results.completedReadFile = true; | ||
compareResults(); | ||
}); | ||
} | ||
}; | ||
return SassyTest; | ||
}(); | ||
module.exports = SassyTest; |
{ | ||
"name": "sassy-test", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/JohnAlbin/sassy-test", | ||
@@ -25,13 +25,18 @@ "author": "John Albin Wilkins <virtually.johnalbin@gmail.com> (http://john.albin.net/)", | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"coveralls": "^2.11.4", | ||
"eslint": "^1.9.0", | ||
"istanbul": "^0.4.0", | ||
"jsdoc": "^3.3.3", | ||
"mocha": "^2.3.4" | ||
"babel-cli": "^6.6.5", | ||
"babel-preset-es2015": "^6.6.0", | ||
"bluebird": "^3.3.4", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.8", | ||
"eslint": "^2.4.0", | ||
"istanbul": "^0.4.2", | ||
"jsdoc": "^3.4.0", | ||
"mocha": "^2.4.5" | ||
}, | ||
"scripts": { | ||
"test": "istanbul cover _mocha", | ||
"test": "istanbul cover -i 'src/**' _mocha", | ||
"posttest": "eslint .", | ||
"report-coverage": "cat ./coverage/lcov.info | coveralls", | ||
"test-no-coverage": "mocha", | ||
"build": "babel src --out-dir lib", | ||
"docs": "make docs" | ||
@@ -38,0 +43,0 @@ }, |
@@ -49,4 +49,5 @@ [![Build Status](https://secure.travis-ci.org/JohnAlbin/sassy-test.png?branch=master)](http://travis-ci.org/JohnAlbin/sassy-test) [![Coverage Status](https://coveralls.io/repos/JohnAlbin/sassy-test/badge.svg?branch=master&service=github)](https://coveralls.io/github/JohnAlbin/sassy-test?branch=master) | ||
global.path = require('path'); | ||
global.should = require('chai').should(); | ||
global.sassyTest = require('sassy-test'); | ||
global.expect = require('chai').expect; | ||
global.SassyTest = require('sassy-test'); | ||
global.sassyTest = new SassyTest(); | ||
@@ -59,3 +60,3 @@ // This before() is run before any test_*.js file. | ||
path.join(__dirname, '../sass'), | ||
path.join(__dirname, '../node_modules/breakpoint-sass/stylesheets' | ||
path.join(__dirname, '../node_modules/breakpoint-sass/stylesheets') | ||
] | ||
@@ -74,4 +75,2 @@ // Since our fixtures are in test/fixtures, we don't need to override | ||
```JavaScript | ||
'use strict'; | ||
describe('@import "mymodule";', function() { | ||
@@ -84,8 +83,8 @@ describe('@function my-modules-function()', function() { | ||
// test/fixtures/my-modules-function | ||
sassyTest.renderFixture('my-modules-function', {}, function(error, result, expectedOutput) { | ||
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; both expectedOutput (the contents of output.css) | ||
// and node-sass's result object are available. | ||
should.not.exist(error); | ||
// here if we desire. | ||
expect(error).to.not.exist; | ||
expect(result.css).to.expect('.some-valid-css {border: 0}'); | ||
done(); | ||
@@ -98,8 +97,8 @@ }); | ||
// intentional error with Sass' @error directive. | ||
sassyTest.renderFixture('my-modules-error', {}, function(error, result, expectedOutput) { | ||
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. | ||
error.should.exist; | ||
error.message.should.equal('Some helpful error message from your module.'); | ||
expect(error).to.exist; | ||
expect(error.message).to.equal('Some helpful error message from your module.'); | ||
done(); | ||
@@ -112,10 +111,10 @@ }); | ||
// intentional warning message with Sass' @warn directive. | ||
sassyTest.renderFixture('my-modules-warn', {}, function(error, result, expectedOutput) { | ||
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. | ||
should.not.exist(error); | ||
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. | ||
result.warn[0].should.equal('Some helpful warning from your module.'); | ||
expect(result.warn[0]).to.equal('Some helpful warning from your module.'); | ||
done(); | ||
@@ -128,2 +127,35 @@ }); | ||
SassyTest's `render()` and `renderFixture()` methods will return a Promise if you don't provide a callback: | ||
```JavaScript | ||
describe('@import "mymodule";', function() { | ||
describe('@function my-modules-function()', function() { | ||
it('should test an aspect of this function', function() { | ||
return sassyTest.renderFixture('my-modules-function', {}).catch(function(error) { | ||
expect(error).to.not.exist; | ||
}).then(function(result) { | ||
expect(result.css).to.expect('.some-valid-css {border: 0}'); | ||
}); | ||
}); | ||
it('should throw an error in this situation', function() { | ||
return sassyTest.renderFixture('my-modules-error', {}).then(function(result) { | ||
expect(result).to.not.exist; | ||
}).catch(function(error) { | ||
expect(error).to.exist; | ||
expect(error.message).to.equal('Some helpful error message from your module.'); | ||
}); | ||
}); | ||
it('should warn in another situation', function() { | ||
return sassyTest.renderFixture('my-modules-warn', {}).catch(function(error) { | ||
expect(error).to.not.exist; | ||
}).then(function(result) { | ||
expect(result.warn[0]).to.equal('Some helpful warning from your module.'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
``` | ||
[Full documentation of Sassy Test’s JavaScript API](http://johnalbin.github.io/sassy-test) is available online. | ||
@@ -130,0 +162,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
165
89879
9
20
403
1