Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More test coverage with more unit tests
- Loading branch information
ItsJonQ
committed
May 28, 2017
1 parent
6fb01fb
commit aa2ee53
Showing
10 changed files
with
244 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
const isString = function(string) { | ||
return (string && typeof string === 'string' && string !== ''); | ||
if (string && typeof string === 'string' && string !== '') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
module.exports = isString; |
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,22 +1,14 @@ | ||
const emmet = require('../vendor/emmet'); | ||
const isString = require('./isString'); | ||
const sanitizeForEmmet = require('./cssSelector').sanitizeForEmmet; | ||
const hasProp = require('./object').hasProp; | ||
|
||
const sanitize = (selectors = '') => { | ||
return selectors.trim() | ||
.replace(/\ > \ /g, ' ') | ||
.replace(/>/g, ' ') | ||
.replace(/\ \ \ \ /g, ' ') | ||
.replace(/\ \ \ /g, ' ') | ||
.replace(/\ \ /g, ' ') | ||
.replace(/\ /g, ' > '); | ||
}; | ||
|
||
const renderer = (document, selectors) => { | ||
if (!document || !isString(selectors)) { | ||
return; | ||
const renderer = (document = false, selectors = '') => { | ||
if (!document || !hasProp(document, 'location') || !isString(selectors)) { | ||
return false; | ||
} | ||
|
||
return emmet(document, sanitize(selectors)); | ||
return emmet(document, sanitizeForEmmet(selectors)); | ||
}; | ||
|
||
module.exports = renderer; |
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* globals barista: true, expect: true, describe: true, it: true, sinon: true, utils: true */ | ||
|
||
const isString = global.utils.isString; | ||
|
||
describe('utils', () => { | ||
describe('isString', () => { | ||
it('should return false for non-strings', () => { | ||
expect(isString(0)).to.be.false; | ||
expect(isString(1)).to.be.false; | ||
expect(isString([])).to.be.false; | ||
expect(isString(true)).to.be.false; | ||
expect(isString(false)).to.be.false; | ||
expect(isString({})).to.be.false; | ||
expect(isString()).to.be.false; | ||
}); | ||
|
||
it('should return false for empty strings', () => { | ||
expect(isString('')).to.be.false; | ||
}); | ||
|
||
it('should return true for non-empty strings', () => { | ||
expect(isString('y')).to.be.true; | ||
expect(isString('yiss')).to.be.true; | ||
expect(isString('aw yiss')).to.be.true; | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* globals barista: true, expect: true, describe: true, it: true, sinon: true, utils: true */ | ||
|
||
const renderer = global.utils.renderer; | ||
|
||
describe('utils', () => { | ||
describe('renderer', () => { | ||
it('should return false for invalid args', () => { | ||
expect(renderer(true, '')).to.be.false; | ||
expect(renderer(true, '.selector')).to.be.false; | ||
expect(renderer({}, '.selector')).to.be.false; | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* globals barista: true, expect: true, describe: true, it: true, sinon: true, utils: true */ | ||
|
||
const sass = global.utils.sass; | ||
|
||
describe('utils', () => { | ||
describe('sass', () => { | ||
describe('render', () => { | ||
it('should render CSS with valid option.content', () => { | ||
const output = sass.render({ content: 'h1 { color: black; }' }); | ||
|
||
expect(output).to.be.a('string'); | ||
expect(output).to.contain('h1'); | ||
}); | ||
|
||
it('should render SCSS with valid option.content', () => { | ||
const output = sass.render({ content: 'h1 { color: black; a { display: block; } }' }); | ||
|
||
expect(output).to.be.a('string'); | ||
expect(output).to.contain('h1 a'); | ||
}); | ||
}); | ||
}); | ||
}); |