-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
137 lines (117 loc) · 3.75 KB
/
test.js
File metadata and controls
137 lines (117 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
require('mocha');
var assert = require('assert');
var assemble = require('assemble-core');
var questions = require('base-questions');
var conflicts = require('base-fs-conflicts');
var rename = require('base-fs-rename');
var exists = require('fs-exists-sync');
var selectViews = require('./');
var del = require('delete');
var app;
describe('assemble-select-views', function() {
describe('module', function() {
it('should export a function', function() {
assert.equal(typeof selectViews, 'function');
});
});
describe('plugin', function() {
it('should only register the plugin once', function(cb) {
var count = 0;
app = assemble();
app.on('plugin', function(name) {
if (name === 'assemble-select-views') {
count++;
}
});
app.use(selectViews());
app.use(selectViews());
app.use(selectViews());
assert.equal(count, 1);
cb();
});
});
describe('errors', function() {
beforeEach(function() {
app = assemble();
app.use(selectViews());
app.create('pages');
});
it('should throw an error when base-questions is not registered', function(cb) {
app.use(conflicts());
app.use(rename());
app.selectViews('pages', function(err, views) {
assert(err);
assert.equal(err.message, 'expected the base-questions plugin to be registered');
cb();
});
});
it('should throw an error when base-fs-conflicts is not registered', function(cb) {
app.use(questions());
app.use(rename());
app.selectViews('pages', function(err, views) {
assert(err);
assert.equal(err.message, 'expected the base-fs-conflicts plugin to be registered');
cb();
});
});
it('should throw an error when base-fs-rename is not registered', function(cb) {
app.use(questions());
app.use(conflicts());
app.selectViews('pages', function(err, views) {
assert(err);
assert.equal(err.message, 'expected the base-fs-rename plugin to be registered');
cb();
});
});
it('should throw an error when base-fs-rename is not registered', function(cb) {
app.use(questions());
app.use(conflicts());
app.selectViews('pages', function(err, views) {
assert(err);
assert.equal(err.message, 'expected the base-fs-rename plugin to be registered');
cb();
});
});
it('should throw an error when the options.collection is not defined', function(cb) {
app.create('posts');
app.use(questions());
app.use(conflicts());
app.use(rename());
app.selectViews(function(err, views) {
assert(err);
assert.equal(err.message, 'expected options.collection to be a string');
cb();
});
});
});
describe('plugin', function() {
this.timeout(10000);
beforeEach(function() {
app = assemble();
app.use(questions());
app.use(conflicts());
app.use(rename());
app.use(selectViews());
app.create('pages');
});
afterEach(function(cb) {
del('actual', cb);
});
it('should render views specified on the `selectViews` option', function(cb) {
app.page('foo.hbs', {content: 'this is {{name}}', data: {name: 'Foo'}});
app.page('bar.hbs', {content: 'this is {{name}}'});
app.page('baz.hbs', {content: 'this is {{name}}'});
app.data({name: 'blah'});
app.engine('hbs', require('engine-handlebars'));
app.option('selectViews', ['baz', 'foo']);
app.option('dest', 'actual');
app.selectViews('pages', function(err, views) {
if (err) return cb(err);
assert(exists('actual/foo.hbs'));
assert(exists('actual/baz.hbs'));
cb();
});
});
});
});