fix: skip root check for renderFile()

This commit is contained in:
Harttle
2021-10-06 18:38:58 +08:00
parent a3455ebd0b
commit 822ba0be0f
9 changed files with 31 additions and 24 deletions
+1 -1
View File
@@ -55,6 +55,6 @@ describe('#renderFile()', function () {
extname: '.html'
})
return expect(engine.renderFile('/not/exist.html')).to
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo\/,\/root\/"/)
})
})
+1 -1
View File
@@ -250,7 +250,7 @@ describe('tags/render', function () {
})
describe('static partial', function () {
it('should support filename with extention', async function () {
it('should support filename with extension', async function () {
mock({
'/parent.html': 'X{% render child.html color:"red" %}Y',
'/child.html': 'child with {{color}}'
+5 -5
View File
@@ -75,7 +75,7 @@ describe('Liquid', function () {
extname: '.html'
})
return expect(engine.renderFile('/not/exist.html')).to
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo\/,\/root\/"/)
})
})
describe('#parseFile', function () {
@@ -85,7 +85,7 @@ describe('Liquid', function () {
extname: '.html'
})
return expect(engine.parseFile('/not/exist.html')).to
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
.be.rejectedWith(/Failed to lookup "\/not\/exist.html" in "\/boo\/,\/root\/"/)
})
it('should fallback to require.resolve in Node.js', async function () {
const engine = new Liquid({
@@ -120,7 +120,7 @@ describe('Liquid', function () {
extname: '.html'
})
return expect(() => engine.parseFileSync('/not/exist.html'))
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo\/,\/root\/"/)
})
it('should throw with lookup list when file not exist', function () {
const engine = new Liquid({
@@ -128,7 +128,7 @@ describe('Liquid', function () {
extname: '.html'
})
return expect(() => engine.parseFileSync('/not/exist.html'))
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo\/,\/root\/"/)
})
})
describe('#enderToNodeStream', function () {
@@ -158,7 +158,7 @@ describe('Liquid', function () {
expect(drainStream(stream)).to.be.eventually.equal('foo')
})
it('should throw RenderError when tag throws', async () => {
const stream = engine.renderFileToNodeStream('error.html')
const stream = await engine.renderFileToNodeStream('error.html')
expect(drainStream(stream)).to.be.rejectedWith(/intended render error/)
})
})
+2 -1
View File
@@ -1,11 +1,12 @@
import { normalize } from '../../../src/liquid-options'
import { expect } from 'chai'
import { resolve } from 'path'
describe('LiquidOptions#root', function () {
describe('#normalize ()', function () {
it('should normalize string typed root array', function () {
const options = normalize({ root: 'foo' })
expect(options.root).to.eql(['foo'])
expect(options.root).to.eql([resolve('foo') + '/'])
})
it('should normalize null typed root as empty array', function () {
const options = normalize({ root: null } as any)
+1 -1
View File
@@ -9,7 +9,7 @@ describe('fs/loader', function () {
describe('.candidates()', function () {
it('should break once found', async function () {
const loader = new Loader({ relativeReference: true, fs, extname: '' } as any)
const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current')]
const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current', true)]
expect(candidates.join()).to.equal('/root/foo/bar')
})
})