Commit a6613847 authored by Björn Bartels's avatar Björn Bartels

PATLAB-7 add more and more tests (adapters, utilities)

parent 8587dee6
Pipeline #79 failed with stage
in 3 minutes and 24 seconds
var childProcess = require('child_process');
module.exports = {
debug: function(callback) {
childProcess.exec('git remote -v', {}, function(err, remotes) {
if (err) {
throw new Error('git.remote: ' + err.message);
}
childProcess.exec('git branch -a', {}, function(err, branches) {
if (err) {
throw new Error('git.branch: ' + err.message);
}
callback(remotes, branches);
});
});
},
clean: function(callback) {
childProcess.exec('git diff-index --name-only HEAD --', {}, function(err, stdout) {
callback(undefined, !err && !stdout);
});
},
commitInfo: function(callback) {
module.exports.head(function(err, headSha) {
module.exports.master(function(err, masterSha) {
module.exports.tagName(function(err, tagName) {
callback(undefined, {
head: headSha,
master: masterSha,
tagName: tagName,
isMaster: headSha === masterSha
});
});
});
});
},
head: function(callback) {
childProcess.exec('git rev-parse --short HEAD', {}, function(err, stdout) {
if (err) {
throw new Error('git.head: ' + err.message);
}
callback(undefined, stdout.trim());
});
},
master: function(callback) {
childProcess.exec('git rev-parse --short origin/master', {}, function(err, stdout) {
// This will error if master was not checked out but in this case we know we are not master
// so we can ignore.
if (err && !(/Needed a single revision/.test(err.message))) {
throw new Error('git.master: ' + err.message);
}
callback(undefined, stdout.trim());
});
},
add: function(path, callback) {
childProcess.exec('git add -f ' + path, {}, function(err) {
if (err) {
throw new Error('git.add: ' + err.message);
}
callback();
});
},
commit: function(name, callback) {
childProcess.exec('git commit --message=' + name, {}, function(err) {
if (err) {
throw new Error('git.commit: ' + err.message);
}
callback();
});
},
tag: function(name, callback) {
childProcess.exec('git tag -a --message=' + name + ' ' + name, {}, function(err) {
if (err) {
throw new Error('git.tag: ' + err.message);
}
callback();
});
},
tagName: function(callback) {
childProcess.exec('git describe --tags', {}, function(err, stdout) {
if (err) {
throw new Error('git.tagName: ' + err.message);
}
var tags = stdout.trim().split(/\n/);
tags = tags.filter(function(info) {
info = info.split('-');
return info.length == 1;
});
var versionTags = tags.filter(function(info) {
return (/^v/.test(info[0]));
});
callback(undefined, versionTags[0] || tags[0]);
});
},
log: function(filepath, pretty, callback) {
var dateformat = 'format:"%d/%m/%Y"';
......@@ -115,4 +13,5 @@ module.exports = {
return childProcess.execSync(cmd);
}
};
var hljs = require('../vendor/highlightjs');
var multiline = require('multiline');
/**
* render a code snippet into highlighted code HTML
......
......@@ -105,7 +105,7 @@ function processlog(file, data, time) {
debug : debug,
warn : warn
};*/
module.exports = function () {};
//module.exports = function () {};
module.exports.log = info,
module.exports.info = info,
module.exports.process= processlog,
......
{
"atom/link": {
"pattern": {
"name": "atom/link",
"categories": [
"basic",
"typography"
],
"uses": null
},
"params": {
"class": [
"*"
],
"href": [
"*"
],
"label": [
"*"
]
},
"body": "<a class=\"{{class}}\" href=\"{{#if href}}{{href}}{{/if}}{{#unless href}}{{texthelper 'url'}}{{/unless}}\">{{#if label}}{{label}}{{/if}}{{#unless label}}{{texthelper 'word'}}{{/unless}}</a>"
},
"atom/modal-close-button": {
"pattern": {
"name": "atom/modal-close-button",
"categories": [
"button",
"modal"
]
},
"body": "<a class=\"btn btn-icon btn-cta-xhr cta-xhr-modal-close\" href=\"javascript:return true;\" aria-label=\"Close modal\" data-close>\n <span aria-hidden=\"true\">&times;</span>\n</a>"
},
"atom/text-headline": {
"pattern": {
"name": "atom/text-headline",
"categories": [
"basic",
"typography"
],
"uses": null
},
"params": {
"heading": [
"1",
"2",
"3",
"4",
"5",
"6"
],
"class": [
"*"
],
"text": [
"*"
]
},
"defaults": {
"heading": "1"
},
"body": "{{#unless heading}}\n<h{{defaults.heading}} class=\"{{class}}\">{{#unless text}}{{texthelper 'words'}}{{/unless}}{{#if text}}{{text}}{{/if}}</h{{defaults.heading}}>\n{{/unless}}\n{{#if heading}}\n<h{{heading}} class=\"{{class}}\">{{#unless text}}{{texthelper 'words'}}{{/unless}}{{#if text}}{{text}}{{/if}}</h{{heading}}>\n{{/if}}\n"
},
"atom/text-paragraph": {
"pattern": {
"name": "atom/text-paragraph",
"categories": [
"basic",
"typography"
],
"uses": null
},
"params": {
"class": [
"*"
]
},
"body": "<p class=\"{{class}}\">{{texthelper 'normal'}}</p>"
},
"molecule/article-teaser": {
"pattern": {
"name": "molecule/article-teaser",
"categories": [
"typography",
"article"
],
"uses": [
"atom/text-headline",
"atom/text-paragraph",
"atom/link"
]
},
"params": {
"class": [
"*"
],
"headline": [
"*"
],
"content": [
"*"
],
"url": [
"*"
]
},
"defaults": {
"headline": "This is some article headline..."
},
"body": "<article class=\"{{class}}\">\n {{patternlibrary atom=\"text-headline\" text=headline}}\n {{patternlibrary atom=\"text-paragraph\" text=content}}\n {{patternlibrary atom=\"link\" href=url label=\"more\" class=\"more\"}}\n</article>"
}
}
......@@ -74,7 +74,6 @@ describe('Patternlibrary instanciation and configuration:', function() {
'test/fixtures/adapters/example/partials/atoms/link/atom-link.html',
{},
( a, b ) => {
console.log(b);
expect(b.pattern.name).to.be.a('string').that.is.equal('atom/link');
expect(b.pattern.categories).to.be.an('array').that.is.deep.equal(['basics','texts']);
done();
......@@ -134,15 +133,6 @@ describe('Patternlibrary instanciation and configuration:', function() {
describe('Patternlibrary "example" adapter:', () => {
let adapter = require('../lib/adapters/example.js');
/*let patternlibraryOptions = {
verbose : false,
dest : FIXTURES + 'example/build',
root : FIXTURES + 'example/pages/',
layouts : FIXTURES + 'example/layouts/',
partials: FIXTURES + 'example/partials/',
testing : true
};
var p = new Patternlibrary.Patternlibrary(patternlibraryOptions);*/
var p = new Patternlibrary.Patternlibrary();
it('retrieves example\'s source-code from file', function (done) {
......
......@@ -6,7 +6,6 @@ import mkdirp from 'mkdirp';
var expect = require('chai').expect;
var $md = require('../lib/vendor/markdown-it.js');
var stripHtml = require('striptags');
describe('Markdown-It plugin helpers', function () {
......@@ -17,7 +16,6 @@ describe('Markdown-It plugin helpers', function () {
"```"].join("\n");
let result = $md.render(codeblock);
console.log(result);
expect(result).to.be.a('string');
});
......@@ -28,7 +26,6 @@ describe('Markdown-It plugin helpers', function () {
"```"].join("\n");
let result = $md.render(codeblock);
console.log(result);
expect(result).to.be.a('string');
});
......@@ -39,7 +36,6 @@ describe('Markdown-It plugin helpers', function () {
"```"].join("\n");
let result = $md.render(codeblock);
console.log(result);
expect(result).to.be.a('string');
});
......
import Patternlibrary from '..';
import fs from 'fs';
import equal from 'assert-dir-equal';
import rimraf from 'rimraf';
import mkdirp from 'mkdirp';
import sinon from 'sinon';
import jsonfile from 'jsonfile';
var expect = require('chai').expect;
var $md = require('../lib/vendor/markdown-it.js');
var stripHtml = require('striptags');
describe('Markdown-It plugin helpers', function () {
describe('Utility functions:', function () {
it('renders highlighted code block with given language', function () {
describe('"escape"', function () {
var escape = require('../lib/util/escape.js');
it('replaces whitespace with a dash character "-" ', function () {
let result = escape("a space");
expect(result).to.equal('a-space');
});
let codeblock = ["```html_example", "\n",
'<div class="galaxy"><div>',
"```"].join("\n");
let result = $md.render(codeblock);
it('returns empty string if parameter is undefined', function () {
let result = escape();
expect(result).to.equal('');
});
console.log(result);
expect(result).to.be.a('string');
});
});
it('renders highlighted code block with no language', function () {
describe('"git"', function () {
var git = require('../lib/util/git.js');
let codeblock = ["```", "\n",
'<div class="galaxy"><div>',
"```"].join("\n");
let result = $md.render(codeblock);
it('"git.log" retrieves git-log information for a given file', function () {
let result = git.log('./package.json');
expect(result).not.to.be.empty;
expect(String(result)).not.to.be.empty;
});
it('"git.log" retrieves formated git-log information for a given file', function () {
var logFormatCompact =
'### %cd'+'%n'+
'%n'+
'- %s (%h, by [%an](mailto:%ae), <%ae>)'+'%n'+
'%n'+
'%n';
let result = git.log('./package.json', 'format:"'+logFormatCompact+'"');
expect(result).not.to.be.empty;
expect(String(result)).not.to.be.empty;
});
it('"git.log" retrieves git-log information for CWD if no file is given', function () {
let result = git.log();
expect(result).not.to.be.empty;
expect(String(result)).not.to.be.empty;
});
console.log(result);
expect(result).to.be.a('string');
});
});
it('renders highlighted code block with faulty indicator', function () {
describe('"log"', function () {
it('"log" method outputs console log info', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.log('some log info...');
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('some log info...');
spyLog.restore();
});
it('"info" method outputs console info', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.info('some more log info...');
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('some more log info...');
spyLog.restore();
});
it('"warn" method outputs console warning', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.warn('this a warning...');
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('this a warning...');
spyLog.restore();
});
it('"warn" method outputs console warning with error information', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.warn('this a warning...', {message: 'some error'});
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('this a warning...');
expect( spyLog.getCall(1).args[0] ).to.contain('Patternlibrary Debug');
spyLog.restore();
});
it('"debug" method outputs console debug information', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.debug({key: 'value'});
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('Patternlibrary Debug');
expect( spyLog.getCall(1).args[0] ).to.have.a.property('key');
spyLog.restore();
});
it('"process" method outputs (file) process information', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.process('some/file.name');
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('Patternlibrary: processed');
expect( spyLog.getCall(0).args[0] ).to.contain('some/file.name');
spyLog.restore();
});
it('"process" method outputs (file) process information with additional data', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.process('some/file.name', 'more data');
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('Patternlibrary: processed');
expect( spyLog.getCall(0).args[0] ).to.contain('some/file.name');
expect( spyLog.getCall(0).args[0] ).to.contain('more data');
spyLog.restore();
});
let codeblock = ["```_example", "\n",
'<div class="galaxy"><div>',
"```"].join("\n");
let result = $md.render(codeblock);
it('"process" method outputs (file) process information with special adapter data', function () {
var p = new Patternlibrary.Patternlibrary({verbose: true});
var spyLog = sinon.spy(console, 'log');
p.log.process('some/file.name', {_adapterData: {one: 'an adapter object', two: 'another adapter object'}});
expect( spyLog.called ).to.be.true;
expect( spyLog.getCall(0).args[0] ).to.contain('Patternlibrary: processed');
expect( spyLog.getCall(0).args[0] ).to.contain('some/file.name');
expect( spyLog.getCall(0).args[0] ).to.contain('one, two');
spyLog.restore();
});
console.log(result);
expect(result).to.be.a('string');
});
});
describe('"module-or-process-path"', function () {
it('resolves to module base path', function () {
var moduleOrProcessPath = require('../lib/util/module-or-process-path.js');
process.chdir('lib/util');
var the_path = moduleOrProcessPath('package.json');
expect(the_path).to.contain('../..');
process.chdir('../..');
});
});
describe('"highlight-code"', function () {
it('throws exception on error', function () {
var highlightCode = require('../lib/util/highlight-code.js');
expect(function() { highlightCode('language_not_found_thorws_error', "<div bla... some code here!"); }).to.throw(Error);
});
});
describe('"filter-patterns"', function () {
var patterns = jsonfile.readFileSync('test/data/patterns.json');
var filterPatterns = require('../lib/util/filter-patterns.js');
it('filters list of patterns by category', function () {
var list = filterPatterns('atom', patterns);
expect(list).to.be.an('object')
.and.to.have.a.property('atom/link');
});
it('returns the data itself if first parameter has an undefined value', function () {
var list = filterPatterns(undefined, patterns);
expect(list).to.be.an('object')
.and.to.deep.equal(patterns);
});
});
describe('"process-parameters"', function () {
it('returns data ^^', function () {
var processParameters = require('../lib/util/process-parameters.js');
var data = {key: ' value'};
var xpct = {key: ' value'};
var result = processParameters({}, data);
expect(result).to.deep.equal(data);
});
});
});
\ No newline at end of file
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