test: cases for parse(<tpl>, <relative filepath>), #395

This commit is contained in:
Harttle
2021-10-10 20:37:26 +08:00
parent a525f45b46
commit 1de6adf308
3 changed files with 27 additions and 3 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ export class Loader {
if (!enforceRoot || referenced.startsWith(dir)) {
// the relatively referenced file is within one of root dirs
yield referenced
return
break
}
}
}
+24
View File
@@ -113,6 +113,30 @@ describe('Liquid', function () {
expect(str).to.equal('foo')
})
})
describe('#parse', function () {
it('should resolve relative partials', function () {
const engine = new Liquid({
root: ['/'],
extname: '.html'
})
mock({
'/root/partial.html': 'foo'
})
const tpls = engine.parse('{% render "./partial.html" %}', '/root/index.html')
return expect(engine.renderSync(tpls)).to.equal('foo')
})
it('should resolve against pwd for relative filepath', function () {
const engine = new Liquid({
root: ['/'],
extname: '.html'
})
mock({
[`${process.cwd()}/partial.html`]: 'foo'
})
const tpls = engine.parse('{% render "./partial.html" %}', './index.html')
return expect(engine.renderSync(tpls)).to.equal('foo')
})
})
describe('#parseFileSync', function () {
it('should throw with lookup list when file not exist', function () {
const engine = new Liquid({
+2 -2
View File
@@ -7,10 +7,10 @@ use(chaiAsPromised)
describe('fs/loader', function () {
describe('.candidates()', function () {
it('should break once found', async function () {
it('should resolve relatively', async function () {
const loader = new Loader({ relativeReference: true, fs, extname: '' } as any)
const candidates = [...loader.candidates('./foo/bar', ['/root', '/root/foo'], '/root/current', true)]
expect(candidates.join()).to.equal('/root/foo/bar')
expect(candidates).to.contain('/root/foo/bar')
})
})
})