Commit 7e669a90 authored by Björn Bartels's avatar Björn Bartels

PATLAB-7 add config-check test cases

parent 71d4c63f
......@@ -111,7 +111,7 @@ function checkPatternsAdapterPatterns ( $pl ) {
* @returns
*/
function checkGUI ( $pl ) {
if ($pl.options.nogui !== false) {
if ($pl.options.nogui === false) {
if (!$pl.options.gui) {
throw new Error('GUI options must be defined.');
}
......
......@@ -12,7 +12,7 @@ function moduleOrProcessPath ( file_or_dir ) {
relFile = path.join(relPath, file_or_dir);
if ( (moduleFile != cwdFile) ) {
if ( !fs.existsSync(cwdFile) && !fs.existsSync(moduleFile)) {
if ( !fs.existsSync(cwdFile) && fs.existsSync(moduleFile)) {
// dindn't find in 'project' dir but found in 'module' dir
// so we actually have a relative path
......
This diff is collapsed.
{
"name": "node-patternlibrary",
"version": "0.0.3",
"description": "a tiny flat file pattern-library generator",
"description": "a tiny pattern-library documention generator",
"keywords": [
"pattern-library",
"partials",
"components",
"documentation",
"generator",
"handlebars",
"markdown-it",
"sassdoc",
"jsdoc",
"GUI"
],
"main": "index.js",
"scripts": {
"test": "nyc mocha --require babel-register",
"dev": "gulp",
"build": "gulp",
"demo": "gulp --demo"
"demo": "gulp --demo",
"reinstall": "rm -rf node_modules bower_components package-lock.json ; npm install; bower link siteapp; npm test; npm run demo"
},
"author": "Björn Bartels <coding@bjoernbartels.earth>",
"license": "Apache-2.0",
......@@ -46,7 +59,7 @@
"markdown-it-sup": "^1",
"markdown-it-table-of-contents": "^0.3",
"markdown-it-task-lists": "^2",
"minimatch": "^3.0.2",
"minimatch": "^3",
"mkdirp": "^0.5",
"mocha": "^5",
"mocha-lcov-reporter": "^1",
......@@ -63,7 +76,7 @@
"strip-indent": "^2",
"supercollider": "^1",
"through2": "^2",
"uglify-js": "^2.6.0",
"uglify-js": "^2",
"vinyl-fs": "^3"
},
"devDependencies": {
......@@ -75,7 +88,7 @@
"chai": "^4",
"chai-jquery": "^2",
"clipboard": "^1",
"corejs-typeahead": "^1.1.1",
"corejs-typeahead": "^1",
"eslint-html-reporter": "^0",
"foundation-sites": "^6",
"gulp": "github:gulpjs/gulp#4.0",
......@@ -96,7 +109,7 @@
"gulp-sass": "^2",
"gulp-sass-lint": "^1",
"gulp-scss-lint": "^0.4",
"gulp-sourcemaps": "^1.12.1",
"gulp-sourcemaps": "^1",
"gulp-strip-debug": "^1",
"gulp-uglify": "^1",
"gulp-uncss": "^1",
......@@ -123,10 +136,10 @@
"striptags": "^2.1.1",
"style-sherpa": "^1",
"vinyl-named": "^1",
"webpack": "^2.7.0",
"webpack": "^2",
"webpack-stream": "^3",
"what-input": "^4",
"yargs": "^3.32.0"
"yargs": "^3"
},
"repository": {
"type": "git",
......
<html>
<body>
<h1>My Layout</h1>
{{> body}}
</body>
</html>
......@@ -208,12 +208,249 @@ describe('Patternlibrary instanciation and configuration:', function() {
});
describe('Patternlibrary.config() - adapter patterns\' options checks', function() {
it('throws error if the pattern\'s adapter "source" search pattern option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.source = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the pattern\'s adapter "readme" search pattern option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.readme = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the pattern\'s adapter "scss" search pattern option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.scss = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the pattern\'s adapter "javascript" search pattern option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.javascript = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the pattern\'s adapter "changelog" search pattern option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.changelog = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the pattern\'s adapter "tests" search pattern option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.tests = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
});
describe('Patternlibrary.config() - GUI paths\' options checks', function() {
it('throws error if the GUI\'s options are missing in the first place', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('...but is ok when no GUI is requested at all', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui = null;
cfg.nogui = true;
expect(function() {
p.config(cfg);
}).not.to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s pages option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.pages = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s partials option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.partials = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s layouts dir option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.layouts = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s layout template-file option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.layout = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s doc-page template-file option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.docpage = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s dashboard template-file option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.dashboard = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s pattern-list template-file option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.patternlist = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the GUI\'s category-list template-file option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.gui.categorylist = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
});
describe('Patternlibrary.config() - static pages paths\' options checks', function() {
it('throws error if the static pages\' "root" source dir option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.root = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
it('throws error if the static pages\' "layouts" source-dir option is missing or empty', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.layouts = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
cfg.pattern.target = '';
expect(function() { p.config(cfg); }).to.throw(Error);
});
});
......
......@@ -68,6 +68,26 @@ describe('Patternlibrary basic templating:', function() {
expect(rendered).to.equal("<html>\n <body>\n <h1>My Layout</h1>\n I am here </body>\n</html>\n");
});
it('assings a handlebars layout by template name from project dir overriding file in module dir', function() {
const FIXTURES = 'test/fixtures.templating/layout-override/';
var patternlibraryOptions = {
verbose : false,
dest : FIXTURES + 'build',
root : FIXTURES + 'pages/',
layouts : FIXTURES + 'layouts',
partials: FIXTURES + 'partials'
}
var p = new Patternlibrary.Patternlibrary(patternlibraryOptions);
p.layout = 'ajax';
expect(p.layout).to.be.a('function');
p.handlebars.registerPartial('body', 'I am here');
var rendered = p.layout({});
expect(rendered).to.equal("User: I am here\n");
});
it('throws an error if layout could not be found by template name', function() {
var p = new Patternlibrary.Patternlibrary();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment