mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
test: integration cases for opts.fs, see #181
This commit is contained in:
@@ -113,6 +113,7 @@
|
|||||||
"@semantic-release/git",
|
"@semantic-release/git",
|
||||||
{
|
{
|
||||||
"assets": [
|
"assets": [
|
||||||
|
"package.json",
|
||||||
"docs",
|
"docs",
|
||||||
"CHANGELOG.md"
|
"CHANGELOG.md"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ import { Liquid } from '../../../src/liquid'
|
|||||||
describe('LiquidOptions#fs', function () {
|
describe('LiquidOptions#fs', function () {
|
||||||
let engine: Liquid
|
let engine: Liquid
|
||||||
const fs = {
|
const fs = {
|
||||||
exists: () => Promise.resolve(true),
|
exists: (x: string) => Promise.resolve(x.match(/^\/root\/files\//)),
|
||||||
readFile: () => Promise.resolve('test file content'),
|
existsSync: (x: string) => x.match(/^\/root\/files\//),
|
||||||
resolve: () => 'resolved'
|
readFile: (x: string) => Promise.resolve(`content for ${x}`),
|
||||||
|
readFileSync: (x: string) => `content for ${x}`,
|
||||||
|
fallback: (x: string) => '/root/files/fallback',
|
||||||
|
resolve: (base: string, path: string) => base + path
|
||||||
}
|
}
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
engine = new Liquid({
|
engine = new Liquid({
|
||||||
@@ -14,8 +17,18 @@ describe('LiquidOptions#fs', function () {
|
|||||||
fs
|
fs
|
||||||
} as any)
|
} as any)
|
||||||
})
|
})
|
||||||
it('should be used to read templates', function () {
|
it('should be used to read templates', async function () {
|
||||||
return engine.renderFile('files/foo')
|
const html = await engine.renderFile('files/foo')
|
||||||
.then(x => expect(x).to.equal('test file content'))
|
expect(html).to.equal('content for /root/files/foo')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should support fallback', async function () {
|
||||||
|
const html = await engine.renderFile('notexist/foo')
|
||||||
|
expect(html).to.equal('content for /root/files/fallback')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should support renderSync', function () {
|
||||||
|
const html = engine.renderFileSync('notexist/foo')
|
||||||
|
expect(html).to.equal('content for /root/files/fallback')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user