mirror of
https://github.com/vale981/metalsmith-collections
synced 2025-03-06 01:41:38 -05:00
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
![]() |
|
||
|
var assert = require('assert');
|
||
|
var Metalsmith = require('metalsmith');
|
||
|
var collections = require('..');
|
||
|
|
||
|
describe('metalsmith-collections', function(){
|
||
|
it('should add collections to metadata', function(done){
|
||
|
var metalsmith = Metalsmith('test/fixtures/basic');
|
||
|
metalsmith
|
||
|
.use(collections({ articles: {}}))
|
||
|
.build(function(err){
|
||
|
if (err) return done(err);
|
||
|
assert.equal(2, metalsmith.metadata().articles.length);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('should accept a "sortBy" option', function(done){
|
||
|
var metalsmith = Metalsmith('test/fixtures/sort');
|
||
|
metalsmith
|
||
|
.use(collections({ articles: { sortBy: 'title' }}))
|
||
|
.build(function(err){
|
||
|
if (err) return done(err);
|
||
|
var articles = metalsmith.metadata().articles;
|
||
|
assert.equal('Alpha', articles[0].title);
|
||
|
assert.equal('Beta', articles[1].title);
|
||
|
assert.equal('Gamma', articles[2].title);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('should accept a "reverse" option', function(done){
|
||
|
var metalsmith = Metalsmith('test/fixtures/sort');
|
||
|
metalsmith
|
||
|
.use(collections({
|
||
|
articles: {
|
||
|
sortBy: 'title',
|
||
|
reverse: true
|
||
|
}
|
||
|
}))
|
||
|
.build(function(err){
|
||
|
if (err) return done(err);
|
||
|
var articles = metalsmith.metadata().articles;
|
||
|
assert.equal('Alpha', articles[2].title);
|
||
|
assert.equal('Beta', articles[1].title);
|
||
|
assert.equal('Gamma', articles[0].title);
|
||
|
done();
|
||
|
});
|
||
|
});
|
||
|
});
|