test: coverage to 100%

This commit is contained in:
Harttle
2021-10-01 15:55:31 +08:00
committed by harttle
parent 9a96b4aba3
commit 4358c9630f
11 changed files with 115 additions and 65 deletions
+3
View File
@@ -30,6 +30,9 @@ describe('filters/date', function () {
it('should apply numeric timezone offset (+2.30)', function () {
return test('{{ "1990-12-31T23:00:00+02:30" | date: "%Y-%m-%dT%H:%M:%S"}}', '1990-12-31T23:00:00', undefined, opts)
})
it('should automatically work when timezone not specified', function () {
return test('{{ "1990-12-31T23:00:00" | date: "%Y-%m-%dT%H:%M:%S"}}', '1990-12-31T23:00:00', undefined, opts)
})
})
it('should render string as string if not valid', function () {
return test('{{ "foo" | date: "%Y"}}', 'foo')
+9
View File
@@ -191,6 +191,15 @@ describe('tags/layout', function () {
return expect(html).to.equal('blackA')
})
it('should support none', async function () {
mock({
'/main.html': '{% layout none %}foo'
})
const staticLiquid = new Liquid({ root: '/', dynamicPartials: false })
const html = await staticLiquid.renderFile('/main.html')
return expect(html).to.equal('foo')
})
it('should support subpaths', async function () {
mock({
'/foo/parent.html': '{{color}}{%block%}{%endblock%}',
+20 -2
View File
@@ -1,6 +1,8 @@
import { Liquid, Drop } from '../../../../src/liquid'
import { expect } from 'chai'
import { expect, use } from 'chai'
import { mock, restore } from '../../../stub/mockfs'
import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('tags/render', function () {
let liquid: Liquid
@@ -93,6 +95,22 @@ describe('tags/render', function () {
const html = await liquid.renderFile('with.html')
expect(html).to.equal('color:red, shape:rect')
})
it('should treat as normal key/value if followed by ":"', async () => {
mock({
'/with.html': '{% render "color" with: "foo" %}',
'/color.html': 'color:{{color}}, with:{{with}}'
})
const html = await liquid.renderFile('with.html')
expect(html).to.equal('color:, with:foo')
})
it('should treat as normal key if with value not specified', async () => {
mock({
'/with.html': '{% render "color" with, shape: "rect" %}',
'/color.html': 'color:{{color}}, with:{{with}}, shape:{{shape}}'
})
const html = await liquid.renderFile('with.html')
expect(html).to.equal('color:, with:true, shape:rect')
})
it('should support with...as', async function () {
mock({
'/with.html': '{% render "color" with color as c %}',
@@ -271,7 +289,7 @@ describe('tags/render', function () {
const html = liquid.renderFileSync('with.html')
expect(html).to.equal('color:red, shape:rect')
})
it('should support filename with extention', function () {
it('should support filename with extension', function () {
mock({
'/parent.html': 'X{% render child.html color:"red" %}Y',
'/child.html': 'child with {{color}}'
+12 -1
View File
@@ -1,5 +1,7 @@
import { expect } from 'chai'
import { expect, use } from 'chai'
import { Liquid } from '../../../src/liquid'
import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('LiquidOptions#fs', function () {
let engine: Liquid
@@ -31,4 +33,13 @@ describe('LiquidOptions#fs', function () {
const html = engine.renderFileSync('notexist/foo')
expect(html).to.equal('content for /root/files/fallback')
})
it('should throw lookup failure if fallback not specified', function () {
const engine = new Liquid({
root: '/root/',
fs: { ...fs, fallback: undefined }
} as any)
return expect(engine.renderFile('notexist/foo'))
.to.be.rejectedWith('Failed to lookup')
})
})
+9
View File
@@ -130,4 +130,13 @@ describe('Liquid', function () {
.to.throw(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
})
})
describe('#enderToNodeStream', function () {
const engine = new Liquid()
it('should render a simple value', function (done) {
const stream = engine.renderToNodeStream(engine.parse('{{"foo"}}'))
let html = ''
stream.on('data', data => { html += data })
stream.on('end', () => { expect(html).to.equal('foo'); done() })
})
})
})