task-master
Version:
A helper to make Grunt task declaration and organization cleaner.
194 lines (182 loc) • 6.95 kB
text/coffeescript
describe 'builder', ->
Given -> = spyObj 'get', 'load'
Given -> = spyObj 'generate'
Given -> = sandbox '../lib/builder',
'./loader':
'file-manifest':
describe '.buildOpts', ->
afterEach -> .merge.restore()
Given -> sinon.stub , 'merge'
Given -> = {}
Given -> .load.withArgs('opts', , '/root', ['tasks'], true).returns
opts: true
context: 'foo'
alias: 'bar'
Given -> .load.withArgs('context', 'foo', '/root', ['tasks']).returns
context: true
Given -> .load.withArgs('alias', 'bar', '/root', ['tasks']).returns
alias: true
When -> .buildOpts '/root',
Then -> expect(.merge).to.have.been.calledWith
opts: true
context:
context: true
alias:
alias: true
describe '.merge', ->
context 'no opts passed in', ->
Given -> = {}
When -> = .merge
Then -> expect().to.deep.equal
devDependencies: true
dependencies: false
optionalDependencies: false
peerDependencies: false
pattern: /^grunt-/
include: []
exclude: []
ignore: []
tasks: ['tasks']
context 'opts passed in', ->
Given -> =
devDependencies: false
dependencies: true
optionalDependencies: true
peerDependencies: true
pattern: '^foo-'
include: 'bar'
exclude: 'baz'
ignore: 'quux'
tasks: 'blah'
When -> = .merge
Then -> expect().to.deep.equal
devDependencies: false
dependencies: true
optionalDependencies: true
peerDependencies: true
pattern: /^foo-/
include: ['bar']
exclude: ['baz']
ignore: ['quux']
tasks: ['blah']
describe '.buildConfig', ->
Given -> = {}
context 'with no context and no ignored files', ->
Given -> =
tasks: ['foo']
Given -> .generate.withArgs('/root/foo',
memo: {}
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*']
reduce: sinon.match.func
).returns foo: 'bar'
When -> = .buildConfig '/root', ,
Then -> expect().to.deep.equal
foo: 'bar'
context 'with a context', ->
Given -> =
tasks: ['foo']
context:
foo: 'bar'
Given -> .generate.withArgs('/root/foo',
memo:
foo: 'bar'
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*']
reduce: sinon.match.func
).returns foo: 'bar'
When -> = .buildConfig '/root', ,
Then -> expect().to.deep.equal
foo: 'bar'
context 'with ignored files', ->
Given -> =
tasks: ['foo']
ignore: ['baz.js']
Given -> .generate.withArgs('/root/foo',
memo: {}
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*', '!baz.js']
reduce: sinon.match.func
).returns foo: 'bar'
When -> = .buildConfig '/root', ,
Then -> expect().to.deep.equal
foo: 'bar'
context 'reduce function', ->
context 'no override', ->
Given -> .get.withArgs('/root/fruit.js', , { foo: 'bar' }).returns 'banana'
Given -> .load.withArgs('override.fruit', null, '/root', ['foo']).returns {}
Given -> .generate.withArgs('/root/foo',
memo: {}
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*', '!baz.js']
reduce: sinon.match.func
).returns foo: 'bar'
When -> .buildConfig '/root', { tasks: ['foo'] },
And -> = .generate.getCall(0).args[1].reduce
And -> =
foo: 'bar'
,
abs: -> '/root/fruit.js'
name: -> 'fruit'
Then -> expect().to.deep.equal
foo: 'bar'
fruit: 'banana'
context 'with overrides', ->
Given -> .get.withArgs('/root/fruit.js', , { foo: 'bar' }).returns 'banana'
Given -> .load.withArgs('override.fruit', null, '/root', ['foo']).returns 'apple'
Given -> .generate.withArgs('/root/foo',
memo: {}
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*', '!baz.js']
reduce: sinon.match.func
).returns foo: 'bar'
When -> .buildConfig '/root', { tasks: ['foo'] },
And -> = .generate.getCall(0).args[1].reduce
And -> =
foo: 'bar'
,
abs: -> '/root/fruit.js'
name: -> 'fruit'
Then -> expect().to.deep.equal
foo: 'bar'
fruit: 'apple'
context 'with <task>.<target>.js style file', ->
Given -> .get.withArgs('/root/fruit.banana.js', , { foo: 'bar' }).returns 'yellow'
Given -> .load.withArgs('override.fruit.banana', null, '/root', ['foo']).returns {}
Given -> .generate.withArgs('/root/foo',
memo: {}
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*', '!baz.js']
reduce: sinon.match.func
).returns foo: 'bar'
When -> .buildConfig '/root', { tasks: ['foo'] },
And -> = .generate.getCall(0).args[1].reduce
And -> =
foo: 'bar'
,
abs: -> '/root/fruit.banana.js'
name: -> 'fruit.banana'
Then -> expect().to.deep.equal
foo: 'bar'
fruit:
banana: 'yellow'
context 'with <task>.<target>.js style file plus base file', ->
Given -> .get.withArgs('/root/fruit.banana.js', , {}).returns 'yellow'
Given -> .get.withArgs('/root/fruit.js', ,
fruit:
banana: 'yellow'
).returns
color: 'yellow'
Given -> .load.withArgs('override.fruit.banana', null, '/root', ['foo']).returns {}
Given -> .load.withArgs('override.fruit', null, '/root', ['foo']).returns {}
Given -> .generate.withArgs('/root/foo',
memo: {}
match: ['**/*.{js,coffee,json,yml}', '!**/_*.*', '!baz.js']
reduce: sinon.match.func
).returns foo: 'bar'
When -> .buildConfig '/root', { tasks: ['foo'] },
And -> = .generate.getCall(0).args[1].reduce
And -> = {},
abs: -> '/root/fruit.banana.js'
name: -> 'fruit.banana'
And -> = ,
abs: -> '/root/fruit.js'
name: -> 'fruit'
Then -> expect().to.deep.equal
fruit:
banana: 'yellow'
color: 'yellow'