-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
241 additions
and
6 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var rimraf = require('rimraf'); | ||
var mock = require('../mock'); | ||
var Environment = require('../../dist/environment'); | ||
|
||
describe('#environment', function () { | ||
var warnings = []; | ||
var logger; | ||
var env; | ||
|
||
beforeEach(function () { | ||
logger = new mock.Logger(true); | ||
env = new Environment(logger, false); | ||
warnings = logger.output; | ||
}); | ||
|
||
/** | ||
* Passed in config file. | ||
*/ | ||
describe('#config', function () { | ||
var configPath = path.join(__dirname, '../fixture/config.json'); | ||
var configFile = require(configPath); | ||
|
||
beforeEach(function () { | ||
env.load(configPath); | ||
env.postProcess(); | ||
}); | ||
|
||
it('should properly process a passed in config file', function () { | ||
assert.ok(path.basename(env.file) === 'config.json'); | ||
assert.deepEqual(env.display, configFile.display); | ||
}); | ||
}); | ||
|
||
/** | ||
* Passed in wrong type config file. | ||
*/ | ||
describe('#config-fail', function () { | ||
var spy = sinon.spy(); | ||
|
||
beforeEach(function () { | ||
env.on('error', spy); | ||
env.load(123); // @TOO [] pass | ||
env.postProcess(); | ||
}); | ||
|
||
it('should error if config is of a wrong format', function () { | ||
assert.ok(spy.called); | ||
}); | ||
}); | ||
|
||
/** | ||
* Passed in undefined config file. | ||
*/ | ||
describe('#config-fail', function () { | ||
beforeEach(function () { | ||
env.load('fail.json'); | ||
env.postProcess(); | ||
}); | ||
|
||
it('should warn if config file is not found', function () { | ||
assert.ok(path.basename(env.file) === '.sassdocrc'); | ||
assert.ok(warnings[0].includes('Config file `fail.json` not found')); | ||
assert.ok(warnings[1].includes('Falling back to `.sassdocrc')); | ||
}); | ||
}); | ||
|
||
/** | ||
* Default .sassdocrc process. | ||
*/ | ||
describe('#sassdocrc', function () { | ||
var sdrc; | ||
|
||
var config = { | ||
display: { | ||
access: ['public', 'private'], | ||
alias: true, | ||
watermark: true | ||
} | ||
}; | ||
|
||
beforeEach(function () { | ||
sdrc = new mock.SassDocRc(config); | ||
|
||
return sdrc.dump().then(function () { | ||
env.load(); | ||
env.postProcess(); | ||
}); | ||
}); | ||
|
||
it('should default to .sassdocrc', function () { | ||
assert.ok(warnings.length === 0); | ||
assert.ok(path.basename(env.file) === '.sassdocrc'); | ||
assert.deepEqual(env.display, config.display); | ||
}); | ||
|
||
after(function () { | ||
return sdrc.clean(); | ||
}); | ||
}); | ||
|
||
/** | ||
* A config.package is passed but fails. | ||
*/ | ||
describe('#package-fail', function () { | ||
var spy = sinon.spy(); | ||
|
||
beforeEach(function () { | ||
env.on('warning', spy); | ||
env.load({ package: 'should/fail.json' }); | ||
env.postProcess(); | ||
}); | ||
|
||
it('should warn if package file is not found and load CWD package.json', function () { | ||
assert.ok(spy.called); | ||
assert.ok(env.package.name === 'sassdoc'); | ||
assert.ok(warnings[0].includes('should/fail.json` not found')); | ||
assert.ok(warnings[1].includes('Falling back to `package.json`')); | ||
}); | ||
}); | ||
|
||
/** | ||
* Render default theme. | ||
*/ | ||
describe('#theme-default', function () { | ||
beforeEach(function () { | ||
env.load(); | ||
env.postProcess(); | ||
env.data = []; | ||
return env.theme('.sassdoc', env); | ||
}); | ||
|
||
it('should render the default theme', function () { | ||
assert.ok(env.themeName === 'default'); | ||
assert.ok(fs.existsSync('.sassdoc/index.html')); | ||
assert.ok(fs.existsSync('.sassdoc/assets')); | ||
}); | ||
|
||
after(function (done) { | ||
rimraf('.sassdoc', done); | ||
}); | ||
}); | ||
|
||
/** | ||
* A config.theme is passed but fails. | ||
*/ | ||
describe('#theme-fail', function () { | ||
beforeEach(function () { | ||
env.load({ theme: 'fail' }); | ||
env.postProcess(); | ||
env.data = []; | ||
return env.theme('.sassdoc', env); | ||
}); | ||
|
||
it('should warn and render the default theme', function () { | ||
assert.ok(warnings[0].includes('Theme `fail` not found')); | ||
assert.ok(warnings[1].includes('Falling back to default theme')); | ||
// assert.ok(env.themeName === 'default'); // @TODO ?? | ||
assert.ok(fs.existsSync('.sassdoc/index.html')); | ||
assert.ok(fs.existsSync('.sassdoc/assets')); | ||
}); | ||
|
||
after(function (done) { | ||
rimraf('.sassdoc', done); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"display": { | ||
"access": ["public", "private"], | ||
"alias": false, | ||
"watermark": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
require('./init'); | ||
|
||
var path = require('path'); | ||
var fs = require('fs'); | ||
var inherits = require('util').inherits; | ||
var Writable = require('stream').Writable; | ||
var Logger = require('../dist/logger'); | ||
var utils = require('../dist/utils'); | ||
var writeFile = utils.denodeify(fs.writeFile); | ||
var unlink = utils.denodeify(fs.unlink); | ||
var is = utils.is; | ||
|
||
function SassDocRc(config) { | ||
this._filePath = path.join(process.cwd(), '.sassdocrc'); | ||
this._contents = config || {}; | ||
} | ||
|
||
SassDocRc.prototype.dump = function () { | ||
return writeFile(this._filePath, JSON.stringify(this._contents)); | ||
}; | ||
|
||
SassDocRc.prototype.clean = function () { | ||
return unlink(this._filePath); | ||
}; | ||
|
||
Object.defineProperty(SassDocRc.prototype, 'contents', { | ||
get: function () { | ||
return this._contents; | ||
}, | ||
set: function (config) { | ||
if (!is.plainObject(config)) { | ||
throw new Error('SassDocRc.contents can only be an Object.'); | ||
} | ||
this._contents = config; | ||
} | ||
}); | ||
|
||
module.exports.SassDocRc = SassDocRc; | ||
|
||
function MockLogger() { | ||
Logger.call(this, arguments); | ||
this._output = []; | ||
this._stderr = new Writable(); | ||
this._stderr._write = function (chunk, enc, cb) { | ||
this._output.push(chunk.toString()); | ||
cb(); | ||
}.bind(this); | ||
} | ||
inherits(MockLogger, Logger); | ||
|
||
Object.defineProperty(MockLogger.prototype, 'output', { | ||
get: function () { | ||
return this._output; | ||
} | ||
}); | ||
|
||
module.exports.Logger = MockLogger; |