Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.

Commit 7c98ce5

Browse files
authored
Merge pull request #79 from lookback/feature/tests
- [x] Adds package tests for `Mailer`. Just to check for existence of `Mailer` object for now. - [x] Sets up `example` app for testing in app testing mode. Checks if an email renders with data. - [x] Use ES6 modules. - [x] Runs tests on CircleCI. - [x] Updates example (and now also test app) to Meteor 1.4.2.
2 parents 71b85ef + 905e1b0 commit 7c98ce5

23 files changed

+254
-124
lines changed

.eslintrc

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33

44
"globals": {
55
"Mailer": true,
6-
"Utils": true,
76
"juice": false,
87
"FlowRouter": false,
98
"Router": false,
10-
"TemplateHelpers": true,
119
"SSR": false,
12-
"Picker": false,
13-
"Routing": true,
14-
"Templates": true
10+
"Picker": false
1511
}
1612
}

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PORT=3100
2+
TEST_DRIVER=dispatch:mocha
3+
4+
lint:
5+
@./node_modules/.bin/eslint .
6+
7+
test-package:
8+
@meteor test-packages ./ --driver-package $(TEST_DRIVER) --once --port $(PORT)
9+
10+
test-app:
11+
@cd example && npm test -- --port $(PORT) && cd -
12+
13+
test-app-watch:
14+
@cd example && npm run test:watch -- --port $(PORT)
15+
16+
test-watch:
17+
@TEST_WATCH=1 meteor test-packages ./ --driver-package $(TEST_DRIVER) --port $(PORT)
18+
19+
.PHONY: test, test-watch

README.md

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Meteor Emails
22

3+
[![CircleCI](https://circleci.com/gh/lookback/meteor-emails.svg?style=shield)](https://circleci.com/gh/lookback/meteor-emails)
4+
35
`lookback:emails` is a Meteor package that makes it easier to build, test and debug rich HTML emails.
46

57
Usually, building HTML emails yourself is tedious. On top of that, add the need for data integration and thus a template language (for sending out daily digest emails, for instance). We wanted a way to preview the email in the browser *with real data* in order to quickly iterate on the design, instead of alternating between code editor and email client.
@@ -562,22 +564,40 @@ route: {
562564
563565
PRs and help is welcomed.
564566
565-
## Develop
567+
### Develop
566568
567569
Clone repo, and run:
568570
569571
```
570572
npm install
571573
```
572574
573-
to install dev dev dependencies. We're using ESLint for linting.
575+
to install dev dev dependencies. We're using ESLint for linting. Lint with:
576+
577+
```
578+
npm run lint
579+
```
580+
581+
Run tests with:
582+
583+
```
584+
npm test
585+
```
586+
587+
or have test watching with:
588+
589+
```
590+
npm run test:watch
591+
```
592+
593+
You'll find tests in the `lib` directory along with the source files.
574594
575-
## Things to do
595+
### Things to do
576596
577597
- [ ] Tests.
578598
579599
Also see [open issues](https://github.com/lookback/meteor-emails/issues).
580600
581601
***
582602
583-
Made by [Lookback](http://github.com/lookback)
603+
Made by [Johan](http://johanbrook.com) in [Lookback](http://github.com/lookback)

circle.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
machine:
2+
node:
3+
version: 5.8.0
4+
5+
dependencies:
6+
cache_directories:
7+
- "~/.meteor"
8+
- "~/.npm"
9+
override:
10+
# -- CACHE METEOR --
11+
# Restore the meteor symlink
12+
- if [ -d ~/.meteor ]; then sudo ln -s ~/.meteor/meteor /usr/local/bin/meteor; fi
13+
# Install Meteor (if not restored from cache)
14+
- if [ ! -e ~/.meteor/meteor ]; then curl https://install.meteor.com | /bin/sh; fi
15+
- npm install --no-progress
16+
- meteor npm install --no-progress:
17+
pwd: example

example/.meteor/.finished-upgraders

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ notices-for-facebook-graph-api-2
1111
1.2.0-cordova-changes
1212
1.2.0-breaking-changes
1313
1.3.0-split-minifiers-package
14+
1.4.0-remove-old-dev-bundle-link
15+
1.4.1-add-shell-server-package

example/.meteor/packages

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
# 'meteor add' and 'meteor remove' will edit this file for you,
55
# but you can also edit it by hand.
66

7-
ecmascript
7+
ecmascript@0.5.9
88
lookback:emails
99
#chrisbutler:[email protected]
10-
meteor-base
10+
meteor-base@1.0.4
1111
blaze-html-templates
12-
reload
12+
reload@1.1.11
1313
spacebars
1414
kadira:flow-router
1515
#iron:router
16-
standard-minifier-css
17-
standard-minifier-js
16+
17+
18+
19+
practicalmeteor:chai
20+
dispatch:mocha
21+
shell-server

example/.meteor/release

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

example/.meteor/versions

+60-53
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,76 @@
11
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
1516
16-
17-
18-
17+
18+
19+
1920
20-
21-
22-
23-
24-
25-
21+
22+
23+
24+
25+
26+
27+
2628
27-
28-
29-
30-
31-
29+
30+
31+
32+
33+
3234
3335
34-
36+
3537
36-
meteor@1.1.15_1
38+
meteor@1.6.0
3739
3840
meteorhacks:[email protected]
3941
meteorhacks:[email protected]
40-
minifier-css@1.1.12_1
41-
minifier-js@1.1.12_1
42-
43-
modules@0.6.4
44-
modules-runtime@0.6.4_1
42+
minifier-css@1.2.15
43+
minifier-js@1.2.15
44+
45+
modules@0.7.7
46+
modules-runtime@0.7.7
4547
46-
47-
48-
49-
50-
48+
49+
50+
51+
52+
practicalmeteor:[email protected]_1
53+
practicalmeteor:[email protected]
54+
5155
5256
53-
54-
55-
57+
58+
59+
5660
5761
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
6976

example/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "example",
33
"version": "1.0.0",
44
"scripts": {
5-
"test": "echo \"Error: no test specified\" && exit 1"
5+
"test": "meteor test --driver-package dispatch:mocha --once --full-app",
6+
"test:watch": "TEST_WATCH=1 meteor test --port 5012 --driver-package dispatch:mocha --full-app"
67
},
78
"author": "Johan Brook",
89
"license": "MIT",
File renamed without changes.

example/server/lib/template-helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TemplateHelpers = {
1+
export default {
22

33
enumerate(arr, limit, oxfordComma) {
44
if (arr) {
@@ -24,7 +24,7 @@ TemplateHelpers = {
2424
let suffix = ' and ';
2525

2626
if (oxfordComma === true
27-
|| (typeof oxfordComma === 'number' && length >= oxfordComma)) {
27+
|| typeof oxfordComma === 'number' && length >= oxfordComma) {
2828
suffix = `, ${suffix}`;
2929
}
3030

example/server/lib/templates.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
Templates = {};
1+
export default {
2+
sample: {
3+
path: 'sample-email/template.html', // Relative to the 'private' dir.
4+
scss: 'sample-email/style.scss', // Mail specific SCSS.
25

3-
Templates.sample = {
4-
path: 'sample-email/template.html', // Relative to the 'private' dir.
5-
scss: 'sample-email/style.scss', // Mail specific SCSS.
6+
helpers: {
7+
capitalizedName() {
8+
return this.name.charAt(0).toUpperCase() + this.name.slice(1);
9+
}
10+
},
611

7-
helpers: {
8-
capitalizedName() {
9-
return this.name.charAt(0).toUpperCase() + this.name.slice(1);
10-
}
11-
},
12-
13-
route: {
14-
path: '/sample/:name',
15-
data: function(params) {
16-
return {
12+
route: {
13+
path: '/sample/:name',
14+
data: (params) => ({
1715
name: params.name,
1816
names: ['Johan', 'John', 'Paul', 'Ringo']
19-
};
17+
})
2018
}
2119
}
2220
};

example/server/server.app-test.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* eslint-env mocha */
2+
import { Mailer } from 'meteor/lookback:emails';
3+
import { assert } from 'meteor/practicalmeteor:chai';
4+
5+
describe('Render email', () => {
6+
7+
it('should render an email', () => {
8+
const string = Mailer.render('sample', {
9+
name: 'johan',
10+
names: ['Johan', 'John', 'Paul', 'Ringo']
11+
});
12+
13+
assert.isString(string);
14+
assert.match(string, new RegExp('<h2>Hi Johan', 'gm'), 'includes heading with capitalized name');
15+
});
16+
17+
it('should render with a layout', () => {
18+
const searchFor = 'Paul is dead';
19+
20+
const string = Mailer.render('sample', {
21+
name: 'johan',
22+
names: ['Johan', 'John', 'Paul', 'Ringo'],
23+
preview: searchFor
24+
});
25+
26+
assert.isString(string);
27+
assert.match(string, new RegExp(`<title>${searchFor}</title>`, 'gm'), 'includes a <title> element from layout.html');
28+
});
29+
});

example/server/server.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import TemplateHelpers from './lib/template-helpers';
2+
import Templates from './lib/templates';
3+
14
if (!process.env.MAIL_URL) {
25
process.env.MAIL_URL = Meteor.settings.MAIL_URL;
36
}

export.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Mailer as theModule } from './lib/mailer';
2+
3+
Mailer = theModule;

lib/mailer.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// See the [GitHub repo](https://github.com/lookback/meteor-emails) for README.
66
// Made by Johan Brook for [Lookback](https://github.com/lookback).
77

8+
import RoutingMiddleware from './routing';
9+
import TemplateHelpers from './template-helpers';
10+
import Utils from './utils';
811

912
const TAG = 'mailer';
1013

@@ -19,7 +22,7 @@ const TAG = 'mailer';
1922
// - `disabled`, optionally disable the actual email sending. Useful for E2E testing.
2023
// Defaults to `false`.
2124
// - `addRoutes`, should we add preview and send routes? Defaults to `true` in development.
22-
Mailer = {
25+
export const Mailer = {
2326
settings: {
2427
silent: false,
2528
routePrefix: 'emails',
@@ -300,7 +303,7 @@ Mailer.init = function(opts) {
300303
const obj = _.extend(this, factory(opts));
301304

302305
if (obj.settings.addRoutes) {
303-
obj.use(Routing);
306+
obj.use(RoutingMiddleware);
304307
}
305308

306309
obj.init();

0 commit comments

Comments
 (0)