file-manifest
Version:
Require all the files in a directory into a single object
877 lines (769 loc) • 33.7 kB
text/coffeescript
sinon = require('sinon')
path = require('path')
describe 'integration', ->
describe 'success cases', ->
Given -> = require '../../lib/file-manifest'
describe 'sync', ->
describe 'with relative dir', ->
When -> = .generate "./fixtures"
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bazQuux: 'quux'
baBlah: 'json'
describe 'with relative dir with no dot', ->
When -> = .generate "fixtures"
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bazQuux: 'quux'
baBlah: 'json'
describe 'with dir', ->
When -> = .generate "#{__dirname}/fixtures"
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bazQuux: 'quux'
baBlah: 'json'
describe 'with dir and options.match', ->
When -> = .generate "#{__dirname}/fixtures", match: ['*.js']
Then -> .should.eql
foo: 'foo'
describe 'with multiple patterns in options.match', ->
When -> = .generate "#{__dirname}/fixtures", match: ['**/*.js', '*.json', '!foo*']
Then -> .should.eql
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir and options.match as a string', ->
When -> = .generate "#{__dirname}/fixtures", match: '*.js'
Then -> .should.eql
foo: 'foo'
describe 'with dir and reducer', ->
When -> = .generate "#{__dirname}/fixtures", reduce: (manifest, file) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
return manifest
Then -> .should.eql
foo: 'oof'
bar: 'rab'
quux: 'xuuq'
'ba-blah': 'nosj'
describe 'with dir, options.match, and options.reduce', ->
When -> = .generate "#{__dirname}/fixtures", { match: ['*.js'], reduce: (manifest, file) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
return manifest
}
Then -> .should.eql
foo: 'oof'
describe 'with dir and options.memo', ->
When -> = .generate "#{__dirname}/fixtures", { memo: { hello: 'world' } }
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bazQuux: 'quux'
baBlah: 'json'
hello: 'world'
describe 'with dir and options.name as function', ->
When -> = .generate "#{__dirname}/fixtures", { name: (file) -> file.name().split('').reverse().join('') }
Then -> .should.eql
oof: 'foo'
rab: "module.exports = \'bar\';\n"
xuuq: 'quux'
'halb-ab': 'json'
describe 'with dir and options.name as string', ->
context 'camelCase', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'camelCase' }
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
context 'dash', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'dash' }
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba-blah': 'json'
'baz-quux': 'quux'
context 'pipe', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'pipe' }
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba|blah': 'json'
'baz|quux': 'quux'
context 'class', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'class' }
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
BaBlah: 'json'
BazQuux: 'quux'
context 'lower', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'lower' }
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bablah: 'json'
bazquux: 'quux'
context 'upper', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'upper' }
Then -> .should.eql
FOO: 'foo'
BAR: "module.exports = \'bar\';\n"
BABLAH: 'json'
BAZQUUX: 'quux'
context 'underscore', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'underscore' }
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
ba_blah: 'json'
baz_quux: 'quux'
context 'human', ->
When -> = .generate "#{__dirname}/fixtures", { name: 'human' }
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
'Ba blah': 'json'
'Baz quux': 'quux'
describe 'with dir and options.load as function', ->
When -> = .generate "#{__dirname}/fixtures", load: (file) -> file.ext()
Then -> .should.eql
foo: '.js'
bar: '.txt'
baBlah: '.json'
bazQuux: '.js'
describe 'with dir and options.load as string', ->
context 'require', ->
When -> = .generate "#{__dirname}/fixtures", { load: 'require' }
Then -> .should.eql
foo: 'foo'
bar: 'bar'
baBlah: 'json'
bazQuux: 'quux'
context 'readfile', ->
When -> = .generate "#{__dirname}/fixtures", { load: 'readFile' }
Then -> .should.eql
foo: 'module.exports = \'foo\';\n'
bar: 'module.exports = \'bar\';\n'
baBlah: '"json"\n'
bazQuux: 'module.exports = \'quux\';\n'
describe 'with dir, options.memo, and options.reduce', ->
When -> = .generate "#{__dirname}/fixtures",
memo:
a: []
b: []
reduce: (manifest, file) -> manifest.b.push(file.name()); return manifest
And -> .b.sort()
Then -> .should.eql
a: []
b: ['ba-blah', 'bar', 'foo', 'quux']
describe 'with options.reduce as a string', ->
context 'nested', ->
When -> = .generate "./fixtures", reduce: 'nested'
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baz:
quux: 'quux'
baBlah: 'json'
context 'list without memo', ->
When -> = .generate './fixtures', reduce: 'list'
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'no list but with array memo', ->
When -> = .generate './fixtures', memo: []
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'objectList', ->
When -> = .generate './fixtures', reduce: 'objectList'
Then -> .should.eql [
name: 'ba-blah'
contents: 'json'
,
name: 'bar',
contents: "module.exports = \'bar\';\n"
,
name: 'foo'
contents: 'foo'
,
name: 'baz/quux'
contents: 'quux'
]
describe 'async', ->
describe 'with a relative dir', ->
When (done) -> .generate "./fixtures", (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with a relative dir with no dot', ->
When (done) -> .generate "fixtures", (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir', ->
When (done) -> .generate "#{__dirname}/fixtures", (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir and options.match', ->
When (done) -> .generate "#{__dirname}/fixtures", match: ['*.js'], (err, ) => done()
Then -> .should.eql
foo: 'foo'
describe 'with dir and options.reduce', ->
When (done) -> .generate "#{__dirname}/fixtures", reduce: (manifest, file, cb) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
cb(null, manifest)
, (err, ) => done()
Then -> .should.eql
foo: 'oof'
bar: 'rab'
quux: 'xuuq'
'ba-blah': 'nosj'
describe 'with dir, options.match, and options.reduce', ->
When (done) -> .generate "#{__dirname}/fixtures", { match: ['*.js'], reduce: (manifest, file, cb) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
cb(null, manifest)
}, (err, ) => done()
Then -> .should.eql
foo: 'oof'
describe 'with dir and options.match as string', ->
When (done) -> .generate "#{__dirname}/fixtures", { match: '*.js' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
describe 'with dir and options.memo', ->
When (done) -> .generate "#{__dirname}/fixtures", { memo: { hello: 'world' } }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
hello: 'world'
describe 'with dir and options.name as function', ->
When (done) -> .generate "#{__dirname}/fixtures",
name: (file) -> file.name().split('').reverse().join('')
, (err, ) => done()
Then -> .should.eql
oof: 'foo'
rab: "module.exports = \'bar\';\n"
'halb-ab': 'json'
xuuq: 'quux'
describe 'with dir and options.name as string', ->
context 'camelCase', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'camelCase' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
context 'dash', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'dash' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba-blah': 'json'
'baz-quux': 'quux'
context 'pipe', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'pipe' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba|blah': 'json'
'baz|quux': 'quux'
context 'class', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'class' }, (err, ) => done()
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
BaBlah: 'json'
BazQuux: 'quux'
context 'lower', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'lower' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bablah: 'json'
bazquux: 'quux'
context 'upper', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'upper' }, (err, ) => done()
Then -> .should.eql
FOO: 'foo'
BAR: "module.exports = \'bar\';\n"
BABLAH: 'json'
BAZQUUX: 'quux'
context 'underscore', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'underscore' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
ba_blah: 'json'
baz_quux: 'quux'
context 'human', ->
When (done) -> .generate "#{__dirname}/fixtures", { name: 'human' }, (err, ) => done()
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
'Ba blah': 'json'
'Baz quux': 'quux'
describe 'with dir and options.load as function', ->
When (done) -> .generate "#{__dirname}/fixtures",
load: (file, cb) -> cb(null, file.ext())
, (err, ) => done()
Then -> .should.eql
foo: '.js'
bar: '.txt'
baBlah: '.json'
bazQuux: '.js'
describe 'with dir and options.load as string', ->
context 'require', ->
When (done) -> .generate "#{__dirname}/fixtures", { load: 'require' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: 'bar'
baBlah: 'json'
bazQuux: 'quux'
context 'readfile', ->
When (done) -> .generate "#{__dirname}/fixtures", { load: 'readFile' }, (err, ) => done()
Then -> .should.eql
foo: 'module.exports = \'foo\';\n'
bar: 'module.exports = \'bar\';\n'
baBlah: '"json"\n'
bazQuux: 'module.exports = \'quux\';\n'
describe 'with dir, options.memo, and options.reduce', ->
When (done) -> .generate "#{__dirname}/fixtures",
memo:
a: []
b: []
reduce: (manifest, file, cb) ->
manifest.b.push(file.name())
cb(null, manifest)
, (err, ) => done()
And -> .b.sort()
Then -> .should.eql
a: []
b: ['ba-blah', 'bar', 'foo', 'quux']
describe 'with options.reduce as a string', ->
context 'nested', ->
When (done) -> = .generate "./fixtures", { reduce: 'nested' }, (err, ) => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baz:
quux: 'quux'
baBlah: 'json'
context 'list without memo', ->
When (done) -> = .generate './fixtures', { reduce: 'list' }, (err, ) => done()
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'no list but with array memo', ->
When (done) -> = .generate './fixtures', { memo: [] }, (err, ) => done()
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'objectList', ->
When (done) -> = .generate './fixtures', { reduce: 'objectList' }, (err, ) => done()
Then -> .should.eql [
name: 'ba-blah'
contents: 'json'
,
name: 'bar',
contents: "module.exports = \'bar\';\n"
,
name: 'foo'
contents: 'foo'
,
name: 'baz/quux'
contents: 'quux'
]
describe 'promise', ->
describe 'with a relative dir', ->
When (done) -> .generatePromise("./fixtures").then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with a relative dir with no dot', ->
When (done) -> .generatePromise("fixtures").then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir', ->
When (done) -> .generatePromise("#{__dirname}/fixtures").then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir and options.match', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", match: ['*.js']).then () => done()
Then -> .should.eql
foo: 'foo'
describe 'with dir and options.reduce', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", reduce: (manifest, file, cb) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
cb(null, manifest)
).then () => done()
Then -> .should.eql
foo: 'oof'
bar: 'rab'
quux: 'xuuq'
'ba-blah': 'nosj'
describe 'with dir, options.match, and options.reduce', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { match: ['*.js'], reduce: (manifest, file, cb) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
cb(null, manifest)
}).then () => done()
Then -> .should.eql
foo: 'oof'
describe 'with dir and options.match as string', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { match: '*.js' }).then () => done()
Then -> .should.eql
foo: 'foo'
describe 'with dir and options.memo', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { memo: { hello: 'world' } }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
hello: 'world'
describe 'with dir and options.name as function', ->
When (done) -> .generatePromise("#{__dirname}/fixtures",
name: (file) -> file.name().split('').reverse().join('')
).then () => done()
Then -> .should.eql
oof: 'foo'
rab: "module.exports = \'bar\';\n"
'halb-ab': 'json'
xuuq: 'quux'
describe 'with dir and options.name as string', ->
context 'camelCase', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'camelCase' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
context 'dash', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'dash' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba-blah': 'json'
'baz-quux': 'quux'
context 'pipe', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'pipe' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba|blah': 'json'
'baz|quux': 'quux'
context 'class', ->
When (done) -> .generatePromise( "#{__dirname}/fixtures", { name: 'class' }).then () => done()
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
BaBlah: 'json'
BazQuux: 'quux'
context 'lower', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'lower' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bablah: 'json'
bazquux: 'quux'
context 'upper', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'upper' }).then () => done()
Then -> .should.eql
FOO: 'foo'
BAR: "module.exports = \'bar\';\n"
BABLAH: 'json'
BAZQUUX: 'quux'
context 'underscore', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'underscore' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
ba_blah: 'json'
baz_quux: 'quux'
context 'human', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { name: 'human' }).then () => done()
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
'Ba blah': 'json'
'Baz quux': 'quux'
describe 'with dir and options.load as function', ->
When (done) -> .generatePromise("#{__dirname}/fixtures",
load: (file, cb) -> cb(null, file.ext())
).then () => done()
Then -> .should.eql
foo: '.js'
bar: '.txt'
baBlah: '.json'
bazQuux: '.js'
describe 'with dir and options.load as string', ->
context 'require', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { load: 'require' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: 'bar'
baBlah: 'json'
bazQuux: 'quux'
context 'readfile', ->
When (done) -> .generatePromise("#{__dirname}/fixtures", { load: 'readFile' }).then () => done()
Then -> .should.eql
foo: 'module.exports = \'foo\';\n'
bar: 'module.exports = \'bar\';\n'
baBlah: '"json"\n'
bazQuux: 'module.exports = \'quux\';\n'
describe 'with dir, options.memo, and options.reduce', ->
When (done) -> .generatePromise("#{__dirname}/fixtures",
memo:
a: []
b: []
reduce: (manifest, file, cb) ->
manifest.b.push(file.name())
cb(null, manifest)
).then () => done()
And -> .b.sort()
Then -> .should.eql
a: []
b: ['ba-blah', 'bar', 'foo', 'quux']
describe 'with options.reduce as a string', ->
context 'nested', ->
When (done) -> = .generatePromise("./fixtures", { reduce: 'nested' }).then () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baz:
quux: 'quux'
baBlah: 'json'
context 'list without memo', ->
When (done) -> = .generatePromise('./fixtures', { reduce: 'list' }).then () => done()
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'no list but with array memo', ->
When (done) -> = .generatePromise('./fixtures', { memo: [] }).then () => done()
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'objectList', ->
When (done) -> = .generatePromise('./fixtures', { reduce: 'objectList' }).then () => done()
Then -> .should.eql [
name: 'ba-blah'
contents: 'json'
,
name: 'bar',
contents: "module.exports = \'bar\';\n"
,
name: 'foo'
contents: 'foo'
,
name: 'baz/quux'
contents: 'quux'
]
describe 'event', ->
describe 'with a relative dir', ->
When (done) -> .generateEvent("./fixtures").on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with a relative dir with no dot', ->
When (done) -> .generateEvent("fixtures").on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir', ->
When (done) -> .generateEvent("#{__dirname}/fixtures").on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
describe 'with dir and options.match', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", match: ['*.js']).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
describe 'with dir and options.reduce', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", reduce: (manifest, file, cb) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
cb(null, manifest)
).on 'manifest', () => done()
Then -> .should.eql
foo: 'oof'
bar: 'rab'
quux: 'xuuq'
'ba-blah': 'nosj'
describe 'with dir, options.match, and options.reduce', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { match: ['*.js'], reduce: (manifest, file, cb) ->
manifest[file.name()] = require(file.abs()).split('').reverse().join('')
cb(null, manifest)
}).on 'manifest', () => done()
Then -> .should.eql
foo: 'oof'
describe 'with dir and options.match as string', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { match: '*.js' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
describe 'with dir and options.memo', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { memo: { hello: 'world' } }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
hello: 'world'
describe 'with dir and options.name as function', ->
When (done) -> .generateEvent("#{__dirname}/fixtures",
name: (file) -> file.name().split('').reverse().join('')
).on 'manifest', () => done()
Then -> .should.eql
oof: 'foo'
rab: "module.exports = \'bar\';\n"
'halb-ab': 'json'
xuuq: 'quux'
describe 'with dir and options.name as string', ->
context 'camelCase', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'camelCase' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baBlah: 'json'
bazQuux: 'quux'
context 'dash', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'dash' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba-blah': 'json'
'baz-quux': 'quux'
context 'pipe', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'pipe' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
'ba|blah': 'json'
'baz|quux': 'quux'
context 'class', ->
When (done) -> .generateEvent( "#{__dirname}/fixtures", { name: 'class' }).on 'manifest', () => done()
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
BaBlah: 'json'
BazQuux: 'quux'
context 'lower', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'lower' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
bablah: 'json'
bazquux: 'quux'
context 'upper', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'upper' }).on 'manifest', () => done()
Then -> .should.eql
FOO: 'foo'
BAR: "module.exports = \'bar\';\n"
BABLAH: 'json'
BAZQUUX: 'quux'
context 'underscore', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'underscore' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
ba_blah: 'json'
baz_quux: 'quux'
context 'human', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { name: 'human' }).on 'manifest', () => done()
Then -> .should.eql
Foo: 'foo'
Bar: "module.exports = \'bar\';\n"
'Ba blah': 'json'
'Baz quux': 'quux'
describe 'with dir and options.load as function', ->
When (done) -> .generateEvent("#{__dirname}/fixtures",
load: (file, cb) -> cb(null, file.ext())
).on 'manifest', () => done()
Then -> .should.eql
foo: '.js'
bar: '.txt'
baBlah: '.json'
bazQuux: '.js'
describe 'with dir and options.load as string', ->
context 'require', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { load: 'require' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: 'bar'
baBlah: 'json'
bazQuux: 'quux'
context 'readfile', ->
When (done) -> .generateEvent("#{__dirname}/fixtures", { load: 'readFile' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'module.exports = \'foo\';\n'
bar: 'module.exports = \'bar\';\n'
baBlah: '"json"\n'
bazQuux: 'module.exports = \'quux\';\n'
describe 'with dir, options.memo, and options.reduce', ->
When (done) -> .generateEvent("#{__dirname}/fixtures",
memo:
a: []
b: []
reduce: (manifest, file, cb) ->
manifest.b.push(file.name())
cb(null, manifest)
).on 'manifest', () => done()
And -> .b.sort()
Then -> .should.eql
a: []
b: ['ba-blah', 'bar', 'foo', 'quux']
describe 'with options.reduce as a string', ->
context 'nested', ->
When (done) -> = .generateEvent("./fixtures", { reduce: 'nested' }).on 'manifest', () => done()
Then -> .should.eql
foo: 'foo'
bar: "module.exports = \'bar\';\n"
baz:
quux: 'quux'
baBlah: 'json'
context 'list without memo', ->
When (done) -> = .generateEvent('./fixtures', { reduce: 'list' }).on 'manifest', () => done()
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'no list but with array memo', ->
When (done) -> = .generateEvent('./fixtures', { memo: [] }).on 'manifest', () => done()
Then -> .should.eql ['json', "module.exports = \'bar\';\n", 'foo', 'quux']
context 'objectList', ->
When (done) -> = .generateEvent('./fixtures', { reduce: 'objectList' }).on 'manifest', () => done()
Then -> .should.eql [
name: 'ba-blah'
contents: 'json'
,
name: 'bar',
contents: "module.exports = \'bar\';\n"
,
name: 'foo'
contents: 'foo'
,
name: 'baz/quux'
contents: 'quux'
]
describe 'failure cases', ->
Given -> =
walk: sinon.stub()
Given -> = require('proxyquire') '../../lib/file-manifest',
pedestrian:
Given -> .walk.callsArgWithAsync 2, 'Error', null
describe 'async', ->
When (done) -> .generate './fixtures', (, manifest) => done()
Then -> .should.equal 'Error'
describe 'promise', ->
When (done) -> .generatePromise('./fixtures').catch () => done()
Then -> .should.equal 'Error'
describe 'event', ->
When (done) -> .generateEvent('./fixtures').on 'error', () => done()
Then -> .should.equal 'Error'