-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
241 lines (190 loc) · 6.28 KB
/
test.js
File metadata and controls
241 lines (190 loc) · 6.28 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
'use strict';
require('mocha');
var assert = require('assert');
var rimraf = require('rimraf');
var assemble = require('assemble-core');
var permalink = require('./');
var app;
describe('permalinks', function() {
beforeEach(function() {
app = assemble();
});
it('should support passing the plugin to the app instance:', function() {
app.use(permalink());
app.create('pages');
var page = app.page('a/b/c.txt', {content: '...'})
.permalink(':name.html');
assert(typeof page.permalink === 'function');
assert(page.data.permalink === 'c.html');
});
it('should emit the plugin on `app`', function(cb) {
app.on('plugin', function(plugin) {
assert.equal(plugin, 'assemble-permalinks');
cb();
});
app.use(permalink());
});
it('should emit the plugin instance', function(cb) {
app.on('plugin', function(plugin) {
assert(this.isApp);
cb();
});
app.use(permalink());
});
it('should support passing the plugin to a collection instance:', function() {
app.create('posts')
.use(permalink());
app.posts('a/b/aaa.txt', {content: '...'});
var post = app.posts.getView('a/b/aaa.txt')
.permalink(':name.html');
assert(typeof post.permalink === 'function');
assert(post.data.permalink === 'aaa.html');
});
it('should support passing the plugin to a view:', function() {
app.create('posts');
app.post('a/b/aaa.txt', {content: '...'});
app.post('a/b/bbb.txt', {content: '...'});
app.post('a/b/ccc.txt', {content: '...'});
var post = app.posts.getView('a/b/aaa.txt')
.use(permalink())
.permalink(':name.html');
assert(typeof post.permalink === 'function');
assert(post.data.permalink === 'aaa.html');
});
it.skip('should support passing the plugin to a view and executing immediately:', function() {
app.create('posts');
app.post('a/b/aaa.txt', {content: '...'});
app.post('a/b/bbb.txt', {content: '...'});
app.post('a/b/ccc.txt', {content: '...'});
var post = app.posts.getView('a/b/aaa.txt')
.use(permalink(':name.html'));
assert(typeof post.permalink === 'function');
assert(post.data.permalink === 'aaa.html');
});
it('should support passing the pattern to the plugin', function() {
app.create('posts')
.use(permalink('foo/:name.html'));
app.post('a/b/aaa.txt', {content: '...'});
app.post('a/b/bbb.txt', {content: '...'});
app.post('a/b/ccc.txt', {content: '...'});
var post = app.posts.getView('a/b/aaa.txt');
assert(typeof post.permalink === 'function');
assert(post.data.permalink === 'foo/aaa.html');
});
it('should support passing the config to the plugin', function() {
app.create('posts')
.use(permalink({
foo: function(name) {
return 'bar-' + name + '.html';
}
}));
app.post('a/b/aaa.txt', {content: '...'});
app.post('a/b/bbb.txt', {content: '...'});
app.post('a/b/ccc.txt', {content: '...'});
var post = app.posts.getView('a/b/aaa.txt');
assert(typeof post.permalink === 'function');
post.permalink('dist/:foo(name)');
assert(post.data.permalink === 'dist/bar-aaa.html');
});
it('should expose a `permalink` method on `app`', function() {
app.use(permalink());
assert(typeof app.permalink === 'function');
});
it('should use `app.permalink()` as a pipeline plugin', function(cb) {
app.use(permalink());
app.task('site', function() {
return app.src('*.js')
.pipe(app.permalink('actual/:name/index.html'))
.pipe(app.dest('.'));
});
app.build('site', function(err) {
if (err) return cb(err);
rimraf('actual', cb);
});
});
it('should handle errors in the pipeline plugin', function(cb) {
app.use(permalink({
foo: function(name) {
return 'bar-' + name;
}
}));
app.task('site', function() {
return app.src('*.js')
.pipe(app.permalink('actual/:foo(:name)/index.html'))
.on('error', function(err) {
if (err) cb();
})
.pipe(app.dest('.'));
});
app.build('site', function(err) {
if (err) return cb(err);
rimraf('actual', cb);
});
});
it('should append permalink to dest path', function(cb) {
app.use(permalink());
app.task('site', function() {
return app.src('*.js')
.pipe(app.permalink(':name/index.html'))
.pipe(app.dest('actual/'));
});
app.build('site', function(err) {
if (err) return cb(err);
rimraf('actual', cb);
});
});
it('should expose a `permalink` method on a collection', function() {
app.create('posts')
.use(permalink('foo/:name.html'));
assert(typeof app.posts.permalink === 'function');
});
it('should use the permalink pattern passed to the collection plugin', function(cb) {
var posts = app.create('posts')
.use(permalink('actual/:name/index.html'));
app.task('site', function() {
return posts.src('*.js')
.pipe(posts.permalink())
.pipe(posts.dest('.'));
});
app.build('site', function(err) {
if (err) return cb(err);
rimraf('actual/', cb);
});
});
it('should append the plugin pattern to the dest path', function(cb) {
var posts = app.create('posts')
.use(permalink(':name/index.html'));
app.task('site', function() {
return posts.src('*.js')
.pipe(posts.permalink())
.pipe(posts.dest('actual/'));
});
app.build('site', function(err) {
if (err) return cb(err);
rimraf('actual/', cb);
});
});
it('should use permalink locals', function() {
app.create('posts')
.use(permalink());
var post = app.post('a/b/aaa.txt', {content: '...'})
.permalink(':dirname/:foo/:baz.html', {
foo: 'bar',
baz: 'qux'
});
assert(typeof post.permalink === 'function');
assert(post.data.permalink === 'a/b/bar/qux.html');
});
it('should use custom parsePath option', function() {
app.create('posts')
.use(permalink({
parsePath: function(paths) {
paths.foo = 'bar-' + paths.name;
}
}));
var post = app.post('a/b/aaa.txt', {content: '...'})
.permalink(':dirname/:foo.html');
assert(typeof post.permalink === 'function');
assert(post.data.permalink === 'a/b/bar-aaa.html');
});
});