-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from opentable/yarn-support
yarn-support closes #487
- Loading branch information
Showing
4 changed files
with
56 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const injectr = require('injectr'); | ||
const path = require('path'); | ||
const _ = require('lodash'); | ||
|
||
const requireTemplate = require('../../src/utils/require-template'); | ||
|
||
describe('utils : require-template', () => { | ||
const globals = { | ||
'__dirname': '.', | ||
}; | ||
|
||
const deps = { | ||
'path': { | ||
join (a, b, c, template) { | ||
return path.join(a,b,c,template); | ||
}, | ||
resolve (a,b,template) { | ||
const dir = path.join( | ||
path.resolve(), | ||
'node_modules/oc-template-handlebars/node_modules', | ||
template | ||
); | ||
return dir; | ||
} | ||
} | ||
}; | ||
|
||
const requireTemplate = injectr( | ||
'../../src/utils/require-template.js', deps, globals | ||
); | ||
|
||
it('should return the template found if its of the correct type', () => { | ||
const template = requireTemplate('oc-template-jade'); | ||
const templateAPIs = _.keys(template); | ||
|
||
expect(_.includes(templateAPIs, | ||
'getInfo', | ||
'getCompiledTemplate', | ||
'compile', | ||
'render') | ||
).to.be.true; | ||
it('expect type of `requireTemplate` to be function', () => { | ||
expect(typeof requireTemplate).to.equal('function'); | ||
}); | ||
|
||
it('should throw an error if the template found hasn\'t the right format', () => { | ||
try { | ||
requireTemplate('handlebars'); | ||
} catch (e) { | ||
expect(e).to.equal('Error requiring oc-template: "handlebars" is not a valid oc-template'); | ||
} | ||
describe('valid', () => { | ||
const scenarios = [ | ||
{ name: 'oc-template-handlebars' }, | ||
{ name: 'oc-template-jade' } | ||
]; | ||
|
||
scenarios.forEach(scenario => { | ||
it(scenario.name, () => { | ||
const template = requireTemplate(scenario.name); | ||
|
||
[ | ||
'compile', | ||
'getCompiledTemplate', | ||
'getInfo', | ||
'render' | ||
].forEach(method => { | ||
expect(template).to.have.property(method); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('not valid', () => { | ||
const scenarios = [{ name: 'lodash' }, { name: 'oc-invalid-template' }]; | ||
|
||
scenarios.forEach(scenario => { | ||
it(scenario.name, () => { | ||
const sut = () => { | ||
requireTemplate(scenario.name); | ||
}; | ||
|
||
expect(sut).to.throw(); | ||
}); | ||
}); | ||
}); | ||
}); |