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

Commit f224899

Browse files
committed
Test having multiple roots to search
1 parent 5c5cb94 commit f224899

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

test/index.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,52 @@ test('engine-munger', function (t) {
210210
});
211211
});
212212

213+
t.test('multiple roots - found', function (t) {
214+
var view = makeView('dust', 'test', {
215+
root: [
216+
path.resolve(__dirname, 'fixtures', 'not-here'),
217+
path.resolve(__dirname, 'fixtures', 'templates')
218+
]
219+
});
220+
view.lookupMain({}, function (err) {
221+
t.error(err);
222+
t.equal(view.path, path.resolve(__dirname, 'fixtures', 'templates', 'test.dust'));
223+
t.end();
224+
});
225+
});
226+
227+
t.test('multiple roots - not found', function (t) {
228+
var path1 = path.resolve(__dirname, 'fixtures', 'not-here');
229+
var path2 = path.resolve(__dirname, 'fixtures', 'nor-there')
230+
var view = makeView('dust', 'test', {
231+
root: [
232+
path1,
233+
path2
234+
]
235+
});
236+
view.lookupMain({}, function (err) {
237+
t.match(err.message, /Failed to lookup view "test.dust"/);
238+
t.match(err.message, /not-here/);
239+
t.match(err.message, /nor-there/);
240+
t.same(view.path, true);
241+
t.end();
242+
});
243+
});
244+
245+
t.test('multiple roots - deferred stat', function (t) {
246+
var view = makeView('dust', 'test', { });
247+
var pending = 0;
248+
for (var i = 0; i < 11; i++) {
249+
pending++;
250+
view.lookup('test', {}, function (err) {
251+
t.error(err);
252+
if (--pending === 0) {
253+
t.end();
254+
}
255+
});
256+
}
257+
});
258+
213259
});
214260

215261
function makeView(ext, tmpl, config) {
@@ -219,7 +265,7 @@ function makeView(ext, tmpl, config) {
219265
var engines = {};
220266
engines['.' + ext] = adaro[ext]();
221267
return new View(tmpl, {
222-
root: ext == 'js' ? path.resolve(__dirname, 'fixtures/.build') : path.resolve(__dirname, 'fixtures/templates'),
268+
root: config.root ? config.root : ext == 'js' ? path.resolve(__dirname, 'fixtures/.build') : path.resolve(__dirname, 'fixtures/templates'),
223269
defaultEngine: '.' + ext,
224270
engines: engines
225271
});

0 commit comments

Comments
 (0)