Skip to content

Commit

Permalink
Merge pull request #69 from jaredwray/migrating-legacy-helper-tests-t…
Browse files Browse the repository at this point in the history
…o-helpers-directory

migrating legacy helper tests to helpers directory
  • Loading branch information
jaredwray authored Nov 1, 2024
2 parents 10021e3 + 34b84fa commit 9eea766
Show file tree
Hide file tree
Showing 47 changed files with 66 additions and 163 deletions.
4 changes: 4 additions & 0 deletions .c8rc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"exclude": [
"helpers/test/**",
"test/**",
"dist/**",
"**/*.test.js",
"**/*.spec.ts",
"node_modules/**"
],
"include": [
"helpers/**/*.js"
]
}
8 changes: 8 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extension": ["js"],
"spec": "helpers/test/**/*.js",
"reporter": "list",
"timeout": 5000,
"recursive": true
}

2 changes: 1 addition & 1 deletion helpers/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ module.exports = {
regex: require('./regex'),
string: require('./string'),
url: require('./url')
};
};
2 changes: 1 addition & 1 deletion test/array.js → helpers/test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.array({handlebars: hbs});
helpers.string({handlebars: hbs});

Expand Down
8 changes: 4 additions & 4 deletions test/code.js → helpers/test/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.code({handlebars: hbs});

describe('code', function() {
describe('embed', function() {
it('should embed markdown:', function() {
assert.equal(hbs.compile('{{{embed "test/fixtures/simple.md"}}}')(), [
assert.equal(hbs.compile('{{{embed "helpers/test/fixtures/simple.md"}}}')(), [
'```markdown',
'## Some Markdown\n',
' - one',
Expand All @@ -21,7 +21,7 @@ describe('code', function() {
});

it('should determine the language from the file extension', function() {
assert.equal(hbs.compile('{{{embed "test/fixtures/embedded.md"}}}')(), [
assert.equal(hbs.compile('{{{embed "helpers/test/fixtures/embedded.md"}}}')(), [
'```markdown',
'## Markdown',
'',
Expand All @@ -40,7 +40,7 @@ describe('code', function() {
});

it('should use the language defined in the last argument', function() {
var template = hbs.compile('{{{embed "test/fixtures/index.html" "hbs"}}}');
var template = hbs.compile('{{{embed "helpers/test/fixtures/index.html" "hbs"}}}');
assert.equal(template(), [
'```hbs',
'<!DOCTYPE html>',
Expand Down
2 changes: 1 addition & 1 deletion test/collection.js → helpers/test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.array({handlebars: hbs});
helpers.collection({handlebars: hbs});
helpers.string({handlebars: hbs});
Expand Down
2 changes: 1 addition & 1 deletion test/comparison.js → helpers/test/comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.comparison({handlebars: hbs});

describe('comparison', function() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions test/fs.js → helpers/test/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ var fs = require('fs');
var path = require('path');
var assert = require('assert');
var hbs = require('handlebars').create();
require('../helpers/helpers.js')({handlebars: hbs});
require('../helpers.js')({handlebars: hbs});

var libFiles = fs.readdirSync(path.join(__dirname, '../helpers/lib'))
var libFiles = fs.readdirSync(path.join(__dirname, '../lib'))
.map(function(fp) {
return path.join('helpers/lib', fp);
});
Expand All @@ -16,7 +16,7 @@ describe('fs', function() {
describe('read', function() {
it('should read a file from the file system', function() {
var fn = hbs.compile('{{read filepath}}');
assert.equal(fn({filepath: 'test/fixtures/read/a.txt'}), 'abc');
assert.equal(fn({filepath: 'helpers/test/fixtures/read/a.txt'}), 'abc');
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js → helpers/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars');
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');

describe('helpers', function() {
it('should should return all helpers:', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/html.js → helpers/test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.html({handlebars: hbs});

var locals = {data: [{aaa: 'AAA', bbb: 'BBB'}, {aaa: 'CCC', bbb: 'DDD'}]};
Expand Down
2 changes: 1 addition & 1 deletion test/i18n.js → helpers/test/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.i18n({handlebars: hbs});

var context = {language: 'en', en: {key: 'value', a: {b: 'c'}}, fr: {key: 'valeur'}};
Expand Down
6 changes: 3 additions & 3 deletions test/index.js → helpers/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var assert = require('assert');
const chai = require('chai');
const expect = chai.expect;
const {createHandlebars, fumanchu} = require('../dist/index.js');
const {createHandlebars, fumanchu} = require('../../dist/index.js');

describe('Fumanchu Template Test', function() {
it('should render name correctly', async function() {
Expand All @@ -24,7 +24,7 @@ describe('Fumanchu Template Test', function() {
});

it('should have the helper class exported', function() {
var helpers = require('../dist/index.js').helpers;
var helpers = require('../../dist/index.js').helpers;
const HandlebarsLib = require('handlebars');
const handlebars = HandlebarsLib.create();
helpers({ handlebars: handlebars });
Expand All @@ -33,7 +33,7 @@ describe('Fumanchu Template Test', function() {
});

it('should have the handlebars object exported', function() {
var {handlebars, helpers} = require('../dist/index.js');
var {handlebars, helpers} = require('../../dist/index.js');
helpers({ handlebars: handlebars });
var fn = handlebars.compile('{{add value 5}}');
assert.equal(fn({value: 5}), '10');
Expand Down
2 changes: 1 addition & 1 deletion test/inflection.js → helpers/test/inflection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.inflection({handlebars: hbs});

describe('inflection', function() {
Expand Down
8 changes: 4 additions & 4 deletions test/markdown.js → helpers/test/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ require('mocha');
var assert = require('assert');
var fs = require('fs');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var markdownHelper = require('../helpers/lib/markdown.js');
var helpers = require('../helpers.js');
var markdownHelper = require('../lib/markdown.js');
helpers.markdown({handlebars: hbs});

describe('markdown', function() {
Expand Down Expand Up @@ -50,9 +50,9 @@ describe('markdown', function() {

describe('md', function() {
it('should render markdown from a file using the {{md}} inline helper', function() {
var expected = fs.readFileSync('test/expected/simple.html', 'utf8');
var expected = fs.readFileSync('helpers/test/expected/simple.html', 'utf8');
var template = hbs.compile('{{{md fp}}}');
var actual = template({fp: 'test/fixtures/simple.md'});
var actual = template({fp: 'helpers/test/fixtures/simple.md'});
assert.equal(actual, expected);
});
});
Expand Down
14 changes: 7 additions & 7 deletions test/match.js → helpers/test/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ var fs = require('fs');
var path = require('path');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
helpers.match({handlebars: hbs});
var helpers = require('../helpers.js');
helpers({handlebars: hbs});

var testFiles = fs.readdirSync(__dirname);
var rootFiles = fs.readdirSync(path.join(__dirname, '..'));
var testFiles = fs.readdirSync(path.join(__dirname, '../lib'));
var rootFiles = fs.readdirSync(path.join(__dirname, '../../'));

describe('matching', function() {
describe('match', function() {
it('should use the main micromatch function to filter an array', function() {
var fn = hbs.compile('{{match files "(a|u)*.js"}}');
assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js');
assert.equal(fn({files: testFiles}), 'array.js,url.js');
});

it('should take an array of patterns', function() {
var ctx = {files: testFiles, patterns: ['(a|u)*.js', 'f*.js']};
var fn = hbs.compile('{{match files patterns}}');
assert.equal(fn(ctx), 'array.js,url.js,utils.js,fs.js');
assert.equal(fn(ctx), 'array.js,url.js,fs.js');
});

it('should take options from the "options[helper name]" object', function() {
Expand All @@ -37,7 +37,7 @@ describe('matching', function() {

it('should use return matching items', function() {
var fn = hbs.compile('{{match files "(a|u)*.js"}}');
assert.equal(fn({files: testFiles}), 'array.js,url.js,utils.js');
assert.equal(fn({files: testFiles}), 'array.js,url.js');
});

it('should take options from the "options[helper name]" object', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/math.js → helpers/test/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.math({handlebars: hbs});

describe('math', function() {
Expand Down
18 changes: 9 additions & 9 deletions test/md.js → helpers/test/md.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var assert = require('assert');
var handlebars = require('handlebars');
var Templates = require('templates');
var hljs = require('highlight.js');
var md = require('../helpers/lib/md.js');
var md = require('../lib/md.js');
var _ = require('lodash');
var app;

Expand Down Expand Up @@ -43,19 +43,19 @@ describe('sync', function() {
});

it('should support rendering markdown from a file:', function() {
assert.equal(md.sync('test/fixtures/a.md'), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
assert.equal(md.sync('helpers/test/fixtures/a.md'), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
});

describe('handlebars:', function() {
it('should support rendering markdown from a file:', function() {
handlebars.registerHelper('md', md.sync);
assert.equal(handlebars.compile('{{{md "test/fixtures/a.md"}}}')(), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
assert.equal(handlebars.compile('{{{md "helpers/test/fixtures/a.md"}}}')(), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
});

it('should use the `render` function passed on the locals to render templates in partials :', function() {
handlebars.registerHelper('md', md.sync);
var locals = {name: 'CCC', compile: handlebars.compile};
assert.equal(handlebars.compile('{{{md "test/fixtures/c.md"}}}')(locals), '<h1>CCC</h1>\n<p>This is CCC</p>\n');
assert.equal(handlebars.compile('{{{md "helpers/test/fixtures/c.md"}}}')(locals), '<h1>CCC</h1>\n<p>This is CCC</p>\n');
});
});
});
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('async', function() {
});

it('should support rendering from a file', function(cb) {
app.page('home.md', {content: '<%= md("test/fixtures/d.md") %>'});
app.page('home.md', {content: '<%= md("helpers/test/fixtures/d.md") %>'});

app.render('home.md', {name: 'DDD'}, function(err, view) {
if (err) return cb(err);
Expand All @@ -111,22 +111,22 @@ describe('async', function() {
describe('lodash:', function() {
it('should work as a lodash mixin:', function() {
_.mixin({md: md.sync});
assert.equal(_.template('<%= _.md("test/fixtures/a.md") %>', {})(), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
assert.equal(_.template('<%= _.md("helpers/test/fixtures/a.md") %>', {})(), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
});

it('should work when passed to lodash on the locals:', function() {
assert.equal(_.template('<%= _.md("test/fixtures/a.md") %>')({md: md.sync}), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
assert.equal(_.template('<%= _.md("helpers/test/fixtures/a.md") %>')({md: md.sync}), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
});

it('should work as a lodash import:', function() {
var settings = {imports: {md: md.sync}};
assert.equal(_.template('<%= _.md("test/fixtures/a.md") %>', {}, settings)(), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
assert.equal(_.template('<%= _.md("helpers/test/fixtures/a.md") %>', {}, settings)(), '<h1>AAA</h1>\n<blockquote>\n<p>this is aaa</p>\n</blockquote>\n');
});
});

describe('highlight:', function(argument) {
it('should support syntax highlighting', function() {
var actual = md.sync('test/fixtures/e.md', {
var actual = md.sync('helpers/test/fixtures/e.md', {
highlight: function(code, lang) {
try {
try {
Expand Down
2 changes: 1 addition & 1 deletion test/misc.js → helpers/test/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');

describe('misc', function() {
beforeEach(function() {
Expand Down
2 changes: 1 addition & 1 deletion test/number.js → helpers/test/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.number({handlebars: hbs});

describe('number', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/object.js → helpers/test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('mocha');
var assert = require('assert');
var support = require('./support');
var expected = support.expected('object');
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
var hbs = require('handlebars').create();
helpers.math({handlebars: hbs});
helpers.object({handlebars: hbs});
Expand Down
2 changes: 1 addition & 1 deletion test/path.js → helpers/test/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var assert = require('assert');
var path = require('path');
var hbs = require('handlebars').create();
var gm = require('global-modules');
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.path({handlebars: hbs});

describe('assemble', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/regex.js → helpers/test/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.regex({handlebars: hbs});

describe('regex', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/string.js → helpers/test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.string({handlebars: hbs});

describe('string', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/subexpressions.js → helpers/test/subexpressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('../helpers/helpers.js');
var helpers = require('../helpers.js');
helpers.array({handlebars: hbs});
helpers.string({handlebars: hbs});

Expand Down
4 changes: 2 additions & 2 deletions test/support/index.js → helpers/test/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ utils.read = function(fp) {

utils.fixture = function(type) {
return function(fp) {
return utils.read('test/fixtures/' + type + '/' + fp);
return utils.read('helpers/test/fixtures/' + type + '/' + fp);
};
};

Expand All @@ -45,6 +45,6 @@ utils.fixture = function(type) {

utils.expected = function(type) {
return function(fp) {
return utils.read('test/expected/' + type + '/' + fp);
return utils.read('helpers/test/expected/' + type + '/' + fp);
};
};
Loading

0 comments on commit 9eea766

Please sign in to comment.