mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
feat: renderSync, parseAndRenderSync and renderFileSync, see #48
This commit is contained in:
@@ -59,6 +59,12 @@ describe('fs/browser', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#existsSync()', () => {
|
||||
it('should always return true', function () {
|
||||
expect(fs.existsSync('/foo/bar')).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#readFile()', () => {
|
||||
let server: sinon.SinonFakeServer
|
||||
beforeEach(() => {
|
||||
@@ -87,4 +93,29 @@ describe('fs/browser', function () {
|
||||
return result
|
||||
})
|
||||
})
|
||||
|
||||
describe('#readFileSync()', () => {
|
||||
let server: sinon.SinonFakeServer
|
||||
beforeEach(() => {
|
||||
server = sinon.fakeServer.create()
|
||||
server.autoRespond = true
|
||||
server.respondWith(
|
||||
'GET', 'https://example.com/views/hello.html',
|
||||
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']
|
||||
);
|
||||
(global as any).XMLHttpRequest = sinon.useFakeXMLHttpRequest()
|
||||
})
|
||||
afterEach(() => {
|
||||
server.restore()
|
||||
delete (global as any).XMLHttpRequest
|
||||
})
|
||||
it('should get corresponding text', function () {
|
||||
const html = fs.readFileSync('https://example.com/views/hello.html')
|
||||
return expect(html).to.equal('hello {{name}}')
|
||||
})
|
||||
it('should throw 404', () => {
|
||||
return expect(() => fs.readFileSync('https://example.com/not/exist.html'))
|
||||
.to.throw('Not Found')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+23
-6
@@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user