Skip to content

Commit 6093cb3

Browse files
committed
tests
1 parent 4abe668 commit 6093cb3

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

lib/render.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1+
'use strict;'
2+
13
const Inky = require('inky').Inky;
24
const Juice = require('juice');
5+
const Hoek = require('hoek');
36

47
module.exports = (htmlFile, cssFile, options = { inky: { enabled: true }, juice: { linkCss: false } }) => {
5-
let convertedHtml;
6-
if (options.inky.enabled) {
7-
const inky = new Inky(options.inky);
8-
convertedHtml = inky.releaseTheKraken(htmlFile);
9-
}
8+
return new Promise((resolve, reject) => {
9+
Hoek.assert(htmlFile || htmlFile === '', new Error('HTML file is required!'));
1010

11-
if (options.juice.linkCss) {
12-
return new Promise((resolve, reject) => {
11+
let convertedHtml;
12+
if (options.inky.enabled) {
13+
const inky = new Inky(options.inky);
14+
convertedHtml = inky.releaseTheKraken(htmlFile);
15+
}
16+
17+
if (options.juice.linkCss) {
1318
Juice.juiceResources(options.inky.enabled ? convertedHtml : htmlFile, options.juice, (err, htmlResult) => {
1419
if (err) {
1520
return reject(err);
1621
}
1722

1823
return resolve(htmlResult);
1924
});
20-
});
21-
} else {
22-
return Promise.resolve(Juice.inlineContent(options.inky.enabled ? convertedHtml : htmlFile, cssFile, options.juice))
23-
}
25+
} else {
26+
return resolve(Juice.inlineContent(options.inky.enabled ? convertedHtml : htmlFile, cssFile || '', options.juice))
27+
}
28+
})
2429
}

package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
"description": "CLI for Merging HTML and CSS to inline for emails. Supports Inky Templates.",
55
"main": "bin/driver",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "node_modules/lab/bin/lab"
88
},
99
"bin": {
1010
"inline-email": "bin/driver"
1111
},
1212
"author": "Dan Sabin <dan@freethinking.it>",
1313
"license": "MIT",
1414
"dependencies": {
15-
"command-line-args": "^5.0.0",
16-
"command-line-usage": "^4.1.0",
17-
"inky": "^1.3.7",
18-
"juice": "^4.2.2"
15+
"command-line-args": "5.0.0",
16+
"command-line-usage": "4.1.0",
17+
"hoek": "^5.0.2",
18+
"inky": "1.3.7",
19+
"juice": "4.2.2"
20+
},
21+
"devDependencies": {
22+
"code": "3.0.2",
23+
"lab": "14.3.2"
1924
},
20-
"devDependencies": {},
2125
"repository": {
2226
"type": "git",
2327
"url": "git+https://github.com/freethinkingit/inline-email.git"
@@ -30,5 +34,8 @@
3034
"bugs": {
3135
"url": "https://github.com/freethinkingit/inline-email/issues"
3236
},
33-
"homepage": "https://github.com/freethinkingit/inline-email#readme"
37+
"homepage": "https://github.com/freethinkingit/inline-email#readme",
38+
"env": {
39+
"node": "6.12.3"
40+
}
3441
}

test/lib/render.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const Code = require('code');
4+
const Lab = require('lab');
5+
const Render = require('../../lib/render')
6+
7+
const expect = Code.expect;
8+
const lab = exports.lab = Lab.script();
9+
10+
lab.experiment('render', () => {
11+
lab.test('with no args throws error requiring HTML files', () => {
12+
return Render()
13+
.catch((error) => {
14+
expect(error.message).to.equal('HTML file is required!');
15+
});
16+
});
17+
18+
lab.test('with blank HTML files returns nothing', () => {
19+
return Render('')
20+
.then((htmlResult) => {
21+
expect(htmlResult).to.equal('');
22+
})
23+
});
24+
25+
lab.test('with no args throws error requiring HTML files', () => {
26+
return Render()
27+
.catch((error) => {
28+
expect(error.message).to.equal('HTML file is required!');
29+
});
30+
});
31+
32+
lab.test('convert inky tags to html', () => {
33+
return Render('<row>thing</row>', null, {inky: {enabled: true}, juice: {}})
34+
.then((htmlResult) => {
35+
expect(htmlResult).to.equal('<table class=\"row\"><tbody><tr>thing</tr></tbody></table>');
36+
})
37+
});
38+
});

0 commit comments

Comments
 (0)