Skip to content

Commit

Permalink
Update tests and styleguide for path resolving feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
canvaskisa committed Jun 14, 2016
1 parent 03cf8de commit 51bf4f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ module.exports = function plugin(options) {
return prev instanceof Error ? curr : prev;
});

return result instanceof Error ? reject(result) : resolve(result);
return result instanceof Error ?
reject(new Error('ENOENT: posthtml-modules module lookups failed. Was looking for a module here:\n' + lookups.join('\n'))) :
resolve(result);
});
}).then(function (content) {
return posthtml([function (tree) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthtml-modules",
"version": "0.1.1",
"version": "0.2.0",
"description": "Posthtml modules processing",
"main": "index.js",
"scripts": {
Expand Down
15 changes: 12 additions & 3 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ test('Must include html', async t => {

test('Must fail when module\'s href cannot be found', async t => {
const actual = `<div><module href="./undefined.html"></module></div>`;
t.throws(posthtml().use(plugin()).process(actual));
const lookups = [
path.resolve(__dirname, './/undefined.html'),
path.resolve(__dirname, './undefined/index.html')
];

t.throws(
posthtml().use(plugin()).process(actual),
'ENOENT: posthtml-modules module lookups failed. Was looking for a module here:\n' + lookups.join('\n')
);
});

test('Must replace <content/> with module\'s content', async t => {
Expand All @@ -23,7 +31,8 @@ test('Must replace <content/> with module\'s content', async t => {
});

test('Must resolve href\'s correctly', async t => {
const actual = '<div class="container"><module href="./header"></module></div>'
const actual = '<div class="container"><module href="./header"></module></div>';
const expected = '<div class="container"><header class="header"><nav class="nav"><button class="button"></button></nav></header></div>';
const {html} = await posthtml().use(plugin({context: path.resolve(__dirname, 'tree.spec')})).process(actual);
console.log(html);
t.is(html.replace(/(\n|\t)/g, ''), expected);
});

0 comments on commit 51bf4f1

Please sign in to comment.