feat: renderSync, parseAndRenderSync and renderFileSync, see #48

This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 8028f82499
commit 7fb01ad69a
66 changed files with 896 additions and 272 deletions
+23 -6
View File
@@ -6,7 +6,7 @@ import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('fs', function () {
describe('#resolve()', function () {
describe('.resolve()', function () {
it('should resolve based on root', async function () {
const filepath = fs.resolve('/foo', 'bar.html', '.liquid')
const expected = path.resolve('/foo/bar.html')
@@ -18,23 +18,40 @@ describe('fs', function () {
return expect(filepath).to.equal(expected)
})
})
describe('#exists', () => {
describe('.existsSync', () => {
it('should resolve as false if not exists', () => {
expect(fs.existsSync('/foo/bar')).to.be.false
})
it('should resolve as true if exists', () => {
expect(fs.existsSync(__filename)).to.be.true
})
})
describe('.exists', () => {
it('should resolve as false if not exists', async () => {
const result = await fs.exists('/foo/bar')
return expect(result).to.be.false
expect(result).to.be.false
})
it('should resolve as true if exists', async () => {
const result = await fs.exists(__filename)
return expect(result).to.be.true
expect(result).to.be.true
})
})
describe('#readFile', function () {
describe('.readFileSync', function () {
it('should throw when not exist', function () {
return expect(() => fs.readFileSync('/foo/bar')).to.throw('ENOENT')
})
it('should read content if exists', function () {
const content = fs.readFileSync(__filename)
expect(content).to.contain('should read content if exists')
})
})
describe('.readFile', function () {
it('should throw when not exist', function () {
return expect(fs.readFile('/foo/bar')).to.rejectedWith('ENOENT')
})
it('should read content if exists', async function () {
const content = await fs.readFile(__filename)
return expect(content).to.contain('should read content if exists')
expect(content).to.contain('should read content if exists')
})
})
})