{{names | join: ","}}
') - return expect(engine.render(template, ctx)).to.eventually.equal('alice,bob
') + const html = await engine.render(template, ctx) + return expect(html).to.equal('alice,bob
') }) - it('should render accessive filters', function () { + it('should render accessive filters', async function () { var src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' + '{{ my_array | first }}' - return expect(engine.parseAndRender(src)).to.eventually.equal('apples') + const html = await engine.parseAndRender(src) + return expect(html).to.equal('apples') }) }) diff --git a/test/e2e/render-file.ts b/test/e2e/render-file.ts index 14c5c93d3..c2eaec566 100644 --- a/test/e2e/render-file.ts +++ b/test/e2e/render-file.ts @@ -1,9 +1,6 @@ -var chai = require('chai') -var mock = require('mock-fs') -var Liquid = require('../..') -var expect = chai.expect - -chai.use(require('chai-as-promised')) +import { expect } from 'chai' +import * as mock from 'mock-fs' +import Liquid from '../..' describe('#renderFile()', function () { var engine @@ -24,28 +21,28 @@ describe('#renderFile()', function () { afterEach(function () { mock.restore() }) - it('should render file', function () { - return expect(engine.renderFile('/root/files/foo.html', {})) - .to.eventually.equal('foo') + it('should render file', async function () { + const html = await engine.renderFile('/root/files/foo.html', {}) + return expect(html).to.equal('foo') }) - it('should find files without extname', function () { + it('should find files without extname', async function () { var engine = new Liquid({ root: '/root' }) - return expect(engine.renderFile('/root/files/bar', {})) - .to.eventually.equal('bar') + const html = await engine.renderFile('/root/files/bar', {}) + return expect(html).to.equal('bar') }) - it('should accept relative path', function () { - return expect(engine.renderFile('files/foo.html')) - .to.eventually.equal('foo') + it('should accept relative path', async function () { + const html = await engine.renderFile('files/foo.html') + return expect(html).to.equal('foo') }) - it('should resolve array as root', function () { + it('should resolve array as root', async function () { engine = new Liquid({ root: ['/boo', '/root/'], extname: '.html' }) - return expect(engine.renderFile('files/foo.html')) - .to.eventually.equal('foo') + const html = await engine.renderFile('files/foo.html') + return expect(html).to.equal('foo') }) - it('should default root to cwd', function () { + it('should default root to cwd', async function () { var files = {} files[process.cwd() + '/foo.html'] = 'FOO' mock(files) @@ -53,15 +50,16 @@ describe('#renderFile()', function () { engine = new Liquid({ extname: '.html' }) - return expect(engine.renderFile('foo.html')) - .to.eventually.equal('FOO') + const html = await engine.renderFile('foo.html') + return expect(html).to.equal('FOO') }) - it('should render file with context', function () { - return expect(engine.renderFile('/root/files/name.html', { name: 'harttle' })) - .to.eventually.equal('My name is harttle.') + it('should render file with context', async function () { + const html = await engine.renderFile('/root/files/name.html', { name: 'harttle' }) + return expect(html).to.equal('My name is harttle.') }) - it('should use default extname', function () { - return expect(engine.renderFile('files/name', { name: 'harttle' })).to.eventually.equal('My name is harttle.') + it('should use default extname', async function () { + const html = await engine.renderFile('files/name', { name: 'harttle' }) + return expect(html).to.equal('My name is harttle.') }) it('should throw with lookup list when file not exist', function () { engine = new Liquid({ diff --git a/test/e2e/whitespace-ctrl.ts b/test/e2e/whitespace-ctrl.ts index e3778c92d..c26e9a38d 100644 --- a/test/e2e/whitespace-ctrl.ts +++ b/test/e2e/whitespace-ctrl.ts @@ -1,10 +1,7 @@ -import * as chai from 'chai' +import { expect } from 'chai' import Liquid from '../..' -import * as chaiAsPromised from 'chai-as-promised' const liquid = new Liquid() -const expect = chai.expect -chai.use(chaiAsPromised) const cases = [ { @@ -445,6 +442,9 @@ const cases = [ describe('Whitespace Control', function () { cases.forEach(item => it( item.text, - () => expect(liquid.parseAndRender(item.text)).to.eventually.equal(item.expected) + async () => { + const html = await liquid.parseAndRender(item.text) + expect(html).to.equal(item.expected) + } )) }) diff --git a/test/e2e/xhr.ts b/test/e2e/xhr.ts index 8a4987910..b6c164512 100644 --- a/test/e2e/xhr.ts +++ b/test/e2e/xhr.ts @@ -1,11 +1,10 @@ import Liquid from '../../dist/liquid.js' import { createFakeServer, useFakeXMLHttpRequest } from 'sinon' -import * as chai from 'chai' -import * as chaiAsPromised from 'chai-as-promised' +import { expect, use } from 'chai' import { JSDOM } from 'jsdom' +import * as chaiAsPromised from 'chai-as-promised' -const expect = chai.expect -chai.use(chaiAsPromised) +use(chaiAsPromised) describe('xhr', () => { if (+process.version.match(/^v(\d+)/)[1] < 8) { @@ -24,7 +23,7 @@ describe('xhr', () => { includeNodeLocations: true }); (global as any).XMLHttpRequest = useFakeXMLHttpRequest(); - (global as any).document = dom.window.document; + (global as any).document = dom.window.document engine = new Liquid({ root: 'https://example.com/views/', extname: '.html' @@ -36,97 +35,94 @@ describe('xhr', () => { delete (global as any).document }) describe('#renderFile()', () => { - it('should support without extname', () => { - return expect(engine.renderFile('hello', { name: 'alice1' })) - .to.eventually.equal('hello alice1') + it('should support without extname', async () => { + const html = await engine.renderFile('hello', { name: 'alice1' }) + return expect(html).to.equal('hello alice1') }) - it('should support with extname', () => { - return expect(engine.renderFile('hello.html', { name: 'alice2' })) - .to.eventually.equal('hello alice2') + it('should support with extname', async () => { + const html = await engine.renderFile('hello.html', { name: 'alice2' }) + return expect(html).to.equal('hello alice2') }) - it('should support with absolute path', () => { + it('should support with absolute path', async () => { server.respondWith('GET', 'https://example.com/foo.html', [200, { 'Content-Type': 'text/plain' }, 'foo']) - return expect(engine.renderFile('/foo.html')) - .to.eventually.equal('foo') + const html = await engine.renderFile('/foo.html') + return expect(html).to.equal('foo') }) - it('should support with url', () => { - return expect(engine.renderFile('https://example.com/views/hello.html', { name: 'alice4' })) - .to.eventually.equal('hello alice4') + it('should support with url', async () => { + const html = await engine.renderFile('https://example.com/views/hello.html', { name: 'alice4' }) + return expect(html).to.equal('hello alice4') }) - it('should support include', () => { + it('should support include', async () => { server.respondWith('GET', 'https://example.com/views/hello.html', [200, { 'Content-Type': 'text/plain' }, "hello {% include 'name.html' %}"]) server.respondWith('GET', 'https://example.com/views/name.html', [200, { 'Content-Type': 'text/plain' }, '{{name}}']) - return expect(engine.renderFile('hello.html', { name: 'alice5' })) - .to.eventually.equal('hello alice5') + const html = await engine.renderFile('hello.html', { name: 'alice5' }) + return expect(html).to.equal('hello alice5') }) it('should throw 404', () => { return expect(engine.renderFile('/not/exist.html')) .to.be.rejectedWith('Not Found') }) - it('should throw error', function (done) { - engine.renderFile('hello.html') - .then(() => done('should not be resolved')) - .catch(function (e) { - expect(e.message).to.equal('An error occurred whilst receiving the response.') - done() - }); + it('should throw error', function () { + const result = expect(engine.renderFile('hello.html')) + .to.be.rejectedWith('An error occurred whilst receiving the response.'); (global as any).XMLHttpRequest.onCreate = function (request) { setTimeout(() => request.error()) } + return result }) }) describe('#renderFile() with root specified', () => { - it('should support undefined root', () => { + it('should support undefined root', async () => { engine = new Liquid({ extname: '.html' }) server.respondWith('GET', 'https://example.com/foo/hello.html', [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']) - return expect(engine.renderFile('hello.html', { name: 'alice5' })) - .to.eventually.equal('hello alice5') + const html = await engine.renderFile('hello.html', { name: 'alice5' }) + return expect(html).to.equal('hello alice5') }) - it('should support empty root', () => { + it('should support empty root', async () => { engine = new Liquid({ root: '', extname: '.html' }) server.respondWith('https://example.com/foo/hello.html', [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']) - return expect(engine.renderFile('hello.html', { name: 'alice5' })) - .to.eventually.equal('hello alice5') + const html = await engine.renderFile('hello.html', { name: 'alice5' }) + return expect(html).to.equal('hello alice5') }) - it('should support with relative path', () => { + it('should support with relative path', async () => { engine = new Liquid({ root: './views/', extname: '.html' }) server.respondWith('GET', 'https://example.com/foo/views/hello.html', [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']) - return expect(engine.renderFile('hello.html', { name: 'alice5' })) - .to.eventually.equal('hello alice5') + const html = await engine.renderFile('hello.html', { name: 'alice5' }) + return expect(html).to.equal('hello alice5') }) - it('should support with absolute path', () => { + it('should support with absolute path', async () => { engine = new Liquid({ root: '/views/', extname: '.html' }) server.respondWith('GET', 'https://example.com/views/hello.html', [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']) - return expect(engine.renderFile('hello.html', { name: 'alice5' })) - .to.eventually.equal('hello alice5') + const html = await engine.renderFile('hello.html', { name: 'alice5' }) + return expect(html).to.equal('hello alice5') }) - it('should support with url', () => { + it('should support with url', async () => { engine = new Liquid({ root: 'https://foo.com/bar/', extname: '.html' }) server.respondWith('GET', 'https://foo.com/bar/hello.html', [200, { 'Content-Type': 'text/plain' }, 'hello {{name}}']) - return expect(engine.renderFile('hello.html', { name: 'alice5' })) - .to.eventually.equal('hello alice5') + const html = await engine.renderFile('hello.html', { name: 'alice5' }) + return expect(html).to.equal('hello alice5') }) }) describe('cache options', () => { diff --git a/test/unit/filters.ts b/test/unit/filters.ts index 74144be54..daedd8cb5 100644 --- a/test/unit/filters.ts +++ b/test/unit/filters.ts @@ -1,10 +1,6 @@ -import * as chai from 'chai' -import * as chaiAsPromised from 'chai-as-promised' +import { expect } from 'chai' import Liquid from '../../src/liquid' -chai.use(chaiAsPromised) -const expect = chai.expect - const ctx = { date: new Date(), foo: 'bar', @@ -21,12 +17,13 @@ const ctx = { } let liquid -function test (src, dst) { - return expect(liquid.parseAndRender(src, ctx)).to.eventually.equal(dst) +async function test (src, dst) { + const html = await liquid.parseAndRender(src, ctx) + return expect(html).to.equal(dst) } describe('filters', function () { - before(() => liquid = new Liquid()) + before(() => { liquid = new Liquid() }) describe('abs', function () { it('should return 3 for -3', () => test('{{ -3 | abs }}', '3')) it('should return 2 for arr[0]', () => test('{{ arr[0] | abs }}', '2')) diff --git a/test/unit/liquid.ts b/test/unit/liquid.ts index a831078b1..3bf00f677 100644 --- a/test/unit/liquid.ts +++ b/test/unit/liquid.ts @@ -7,13 +7,13 @@ const expect = chai.expect describe('Liquid', function () { describe('#constructor()', function () { it('should throw on illegal root', function () { - expect(() => new (Liquid as any)({root: {}})).to.throw(/illegal root/) + expect(() => new (Liquid as any)({ root: {} })).to.throw(/illegal root/) }) }) describe('#plugin()', function () { it('should call plugin on the instance', async function () { const engine = new Liquid() - engine.plugin(function (Liquid) { + engine.plugin(function () { this.registerFilter('foo', x => `foo${x}foo`) }) const html = await engine.parseAndRender('{{"bar"|foo}}') diff --git a/test/unit/options/cache.ts b/test/unit/options/cache.ts index 0a2e61c56..7ac742cd2 100644 --- a/test/unit/options/cache.ts +++ b/test/unit/options/cache.ts @@ -1,10 +1,6 @@ -import * as chai from 'chai' +import { expect } from 'chai' import * as mock from 'mock-fs' import Liquid from '../../../src/liquid' -import * as chaiAsPromised from 'chai-as-promised' - -const expect = chai.expect -chai.use(chaiAsPromised) describe('LiquidOptions#cache', function () { let engine diff --git a/test/unit/options/strict.ts b/test/unit/options/strict.ts index 24ac99f2a..04c30d53d 100644 --- a/test/unit/options/strict.ts +++ b/test/unit/options/strict.ts @@ -1,8 +1,5 @@ -import Liquid from '../../../src/liquid' -import * as chai from 'chai' - -const expect = chai.expect -chai.use(require('chai-as-promised')) +import Liquid from 'src/liquid' +import { expect } from 'chai' describe('LiquidOptions#strict_*', function () { let engine @@ -13,9 +10,9 @@ describe('LiquidOptions#strict_*', function () { extname: '.html' }) }) - it('should not throw when strict_variables false (default)', function () { - return expect(engine.parseAndRender('before{{notdefined}}after', ctx)).to - .eventually.equal('beforeafter') + it('should not throw when strict_variables false (default)', async function () { + const html = await engine.parseAndRender('before{{notdefined}}after', ctx) + return expect(html).to.equal('beforeafter') }) it('should throw when strict_variables true', function () { const tpl = engine.parse('before{{notdefined}}after') diff --git a/test/unit/options/trimming.ts b/test/unit/options/trimming.ts index f5be96e4d..899aced70 100644 --- a/test/unit/options/trimming.ts +++ b/test/unit/options/trimming.ts @@ -1,62 +1,58 @@ -import * as chai from 'chai' +import { expect } from 'chai' import Liquid from '../../../src/liquid' -import * as chaiAsPromised from 'chai-as-promised' - -const expect = chai.expect -chai.use(chaiAsPromised) describe('LiquidOptions#trimming', function () { const ctx = { name: 'harttle' } describe('tag trimming', function () { - it('should respect trim_tag_left', function () { + it('should respect trim_tag_left', async function () { const engine = new Liquid({ trim_tag_left: true }) - return expect(engine.parseAndRender(' \n \t{%if true%}foo{%endif%} ')) - .to.eventually.equal('foo ') + const html = await engine.parseAndRender(' \n \t{%if true%}foo{%endif%} ') + return expect(html).to.equal('foo ') }) - it('should respect trim_tag_right', function () { + it('should respect trim_tag_right', async function () { const engine = new Liquid({ trim_tag_right: true }) - return expect(engine.parseAndRender('\t{%if true%}foo{%endif%} \n')) - .to.eventually.equal('\tfoo') + const html = engine.parseAndRender('\t{%if true%}foo{%endif%} \n') + return expect(html).to.equal('\tfoo') }) - it('should not trim value', function () { + it('should not trim value', async function () { const engine = new Liquid({ trim_tag_left: true, trim_tag_right: true }) - return expect(engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx)) - .to.eventually.equal('a harttle b') + const html = await engine.parseAndRender('{%if true%}a {{name}} b{%endif%}', ctx) + return expect(html).to.equal('a harttle b') }) }) describe('value trimming', function () { - it('should respect trim_value_left', function () { + it('should respect trim_value_left', async function () { const engine = new Liquid({ trim_value_left: true }) - return expect(engine.parseAndRender(' \n \t{{name}} ', ctx)) - .to.eventually.equal('harttle ') + const html = await engine.parseAndRender(' \n \t{{name}} ', ctx) + return expect(html).to.equal('harttle ') }) - it('should respect trim_value_right', function () { + it('should respect trim_value_right', async function () { const engine = new Liquid({ trim_value_right: true }) - return expect(engine.parseAndRender(' \n \t{{name}} ', ctx)) - .to.eventually.equal(' \n \tharttle') + const html = await engine.parseAndRender(' \n \t{{name}} ', ctx) + return expect(html).to.equal(' \n \tharttle') }) - it('should respect not trim tag', function () { + it('should respect not trim tag', async function () { const engine = new Liquid({ trim_value_left: true, trim_value_right: true }) - return expect(engine.parseAndRender('\t{% if true %} aha {%endif%}\t')) - .to.eventually.equal('\t aha \t') + const html = await engine.parseAndRender('\t{% if true %} aha {%endif%}\t') + return expect(html).to.equal('\t aha \t') }) }) describe('greedy', function () { const src = '\n {%-if true-%}\n a \n{{-name-}}{%-endif-%}\n ' - it('should enable greedy by default', function () { + it('should enable greedy by default', async function () { const engine = new Liquid() - return expect(engine.parseAndRender(src, ctx)) - .to.eventually.equal('aharttle') + const html = await engine.parseAndRender(src, ctx) + return expect(html).to.equal('aharttle') }) - it('should respect to greedy:false by default', function () { + it('should respect to greedy:false by default', async function () { const engine = new Liquid({ greedy: false }) - return expect(engine.parseAndRender(src, ctx)) - .to.eventually.equal('\n a \nharttle ') + const html = await engine.parseAndRender(src, ctx) + return expect(html).to.equal('\n a \nharttle ') }) }) describe('markup', function () { - it('should support trim using markup', function () { + it('should support trim using markup', async function () { const engine = new Liquid() const src = [ '{%- assign username = "John G. Chalmers-Smith" -%}', @@ -67,9 +63,10 @@ describe('LiquidOptions#trimming', function () { '{%- endif -%}' ].join('\n') const dst = 'Wow, John G. Chalmers-Smith, you have a long name!' - return expect(engine.parseAndRender(src)).to.eventually.equal(dst) + const html = await engine.parseAndRender(src) + return expect(html).to.equal(dst) }) - it('should not trim when not specified', function () { + it('should not trim when not specified', async function () { const engine = new Liquid() const src = [ '{% assign username = "John G. Chalmers-Smith" %}', @@ -80,7 +77,8 @@ describe('LiquidOptions#trimming', function () { '{% endif %}' ].join('\n') const dst = '\n\n Wow, John G. Chalmers-Smith, you have a long name!\n' - return expect(engine.parseAndRender(src)).to.eventually.equal(dst) + const html = await engine.parseAndRender(src) + return expect(html).to.equal(dst) }) }) }) diff --git a/test/unit/output.ts b/test/unit/output.ts index a279e2738..0d970af41 100644 --- a/test/unit/output.ts +++ b/test/unit/output.ts @@ -1,14 +1,9 @@ import * as chai from 'chai' -import * as chaiAsPromised from 'chai-as-promised' -import * as sinonChai from 'sinon-chai' -import * as sinon from 'sinon' import Scope from '../../src/scope/scope' import Output from '../../src/template/output' +import OutputToken from 'src/parser/output-token' import Filter from 'src/template/filter' -chai.use(sinonChai) -chai.use(chaiAsPromised) - const expect = chai.expect describe('Output', function () { @@ -16,41 +11,51 @@ describe('Output', function () { Filter.clear() }) - it('should respect to .to_liquid() method', function () { + it('should respect to .to_liquid() method', async function () { const scope = new Scope({ - bar: { to_liquid: x => 'custom' } + bar: { to_liquid: () => 'custom' } }) - return expect(new Output({value: 'bar'}).render(scope)).to.eventually.equal('custom') + const output = new Output({ value: 'bar' } as OutputToken) + const html = await output.render(scope) + return expect(html).to.equal('custom') }) - it('should stringify objects', function () { + it('should stringify objects', async function () { const scope = new Scope({ foo: { obj: { arr: ['a', 2] } } }) - return expect(new Output({value: 'foo'}).render(scope)).to.eventually.equal('{"obj":{"arr":["a",2]}}') + const output = new Output({ value: 'foo' } as OutputToken) + const html = await output.render(scope) + return expect(html).to.equal('{"obj":{"arr":["a",2]}}') }) - it('should skip circular property', function () { + it('should skip circular property', async function () { const ctx = { foo: { num: 2 }, bar: 'bar' } as any ctx.foo.circular = ctx - const scope = new Scope(ctx) - return expect(new Output({value: 'foo'}).render(scope)).to.eventually.equal('{"num":2,"circular":{"bar":"bar"}}') + const output = new Output({ value: 'foo' } as OutputToken) + const html = await output.render(new Scope(ctx)) + return expect(html).equal('{"num":2,"circular":{"bar":"bar"}}') }) - it('should skip function property', function () { + it('should skip function property', async function () { const scope = new Scope({ obj: { foo: 'foo', bar: x => x } }) - return expect(new Output({value: 'obj'}).render(scope)).to.eventually.equal('{"foo":"foo"}') + const output = new Output({ value: 'obj' } as OutputToken) + const html = await output.render(scope) + return expect(html).to.equal('{"foo":"foo"}') }) it('should respect to .toString()', async () => { const scope = new Scope({ obj: { toString: () => 'FOO' } }) - const str = await new Output({value: 'obj'}).render(scope) + const output = new Output({ value: 'obj' } as OutputToken) + const str = await output.render(scope) return expect(str).to.equal('FOO') }) it('should respect to .to_s()', async () => { const scope = new Scope({ obj: { to_s: () => 'FOO' } }) - const str = await new Output({value: 'obj'}).render(scope) + const output = new Output({ value: 'obj' } as OutputToken) + const str = await output.render(scope) return expect(str).to.equal('FOO') }) it('should respect to .liquid_method_missing()', async () => { const scope = new Scope({ obj: { liquid_method_missing: x => x.toUpperCase() } }) - const str = await new Output({value: 'obj.foo'}).render(scope) + const output = new Output({ value: 'obj.foo' } as OutputToken) + const str = await output.render(scope) return expect(str).to.equal('FOO') }) }) diff --git a/test/unit/render.ts b/test/unit/render.ts index 49d0254c1..f80345cea 100644 --- a/test/unit/render.ts +++ b/test/unit/render.ts @@ -1,24 +1,14 @@ -import * as chai from 'chai' -import * as chaiAsPromised from 'chai-as-promised' -import * as sinonChai from 'sinon-chai' -import * as sinon from 'sinon' +import { expect } from 'chai' import Scope from '../../src/scope/scope' -import Token from 'src/parser/token' +import Token from '../../src/parser/token' import Tag from 'src/template/tag/tag' import Filter from 'src/template/filter' import Render from '../../src/render/render' -import Parser from '../../src/parser/parser' import HTML from 'src/template/html' -chai.use(sinonChai) -chai.use(chaiAsPromised) - -const expect = chai.expect -const parser = new Parser(null) -let render - describe('render', function () { - beforeEach(function () { + let render + before(function () { Filter.clear() Tag.clear() render = new Render() @@ -29,10 +19,11 @@ describe('render', function () { expect(render.renderTemplates([])).to.be.rejectedWith(/scope undefined/) }) - it('should render html', function () { + it('should render html', async function () { const scope = new Scope() const token = { type: 'html', value: '' } as Token - return expect(render.renderTemplates([new HTML(token)], scope)).to.eventually.equal('
') + const html = await render.renderTemplates([new HTML(token)], scope) + return expect(html).to.equal('
')
})
})
})
diff --git a/test/unit/tag.ts b/test/unit/tag.ts
index 7f8cc5647..ef8701bcb 100644
--- a/test/unit/tag.ts
+++ b/test/unit/tag.ts
@@ -1,14 +1,14 @@
import * as chai from 'chai'
import Tag from 'src/template/tag/tag'
-import TagToken from 'src/parser/tag-token'
import Scope from 'src/scope/scope'
import * as sinon from 'sinon'
import * as sinonChai from 'sinon-chai'
import Liquid from 'src/liquid'
+import TagToken from 'src/parser/tag-token'
chai.use(sinonChai)
const expect = chai.expect
-const liquid = new Liquid();
+const liquid = new Liquid()
describe('tag', function () {
let scope
@@ -29,14 +29,14 @@ describe('tag', function () {
type: 'tag',
value: 'foo',
name: 'foo'
- }, [], liquid)
+ } as TagToken, [], liquid)
}).to.throw(/tag foo not found/)
})
it('should register simple tag', function () {
expect(function () {
Tag.register('foo', {
- render: x => 'bar'
+ render: () => 'bar'
})
}).not.throw()
})
@@ -50,7 +50,7 @@ describe('tag', function () {
type: 'tag',
value: 'foo',
name: 'foo'
- }
+ } as TagToken
await new Tag(token, [], liquid).render(scope)
expect(spy).to.have.been.called
})
diff --git a/test/unit/tags/assign.ts b/test/unit/tags/assign.ts
index f88ac497a..f21dcffc0 100644
--- a/test/unit/tags/assign.ts
+++ b/test/unit/tags/assign.ts
@@ -1,9 +1,8 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
-import * as sinonChai from 'chai-as-promised'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-chai.use(sinonChai)
-const expect = chai.expect
+use(chaiAsPromised)
describe('tags/assign', function () {
const liquid = new Liquid()
@@ -12,65 +11,69 @@ describe('tags/assign', function () {
const ctx = {}
return expect(liquid.parseAndRender(src, ctx)).to.be.rejectedWith(/illegal/)
})
- it('should support assign to a string', function () {
+ it('should support assign to a string', async function () {
const src = '{% assign foo="bar" %}{{foo}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('bar')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('bar')
})
- it('should support assign to a number', function () {
+ it('should support assign to a number', async function () {
const src = '{% assign foo=10086 %}{{foo}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('10086')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('10086')
})
- it('should shading rather than overwriting', function () {
+ it('should shading rather than overwriting', async function () {
const ctx = { foo: 'foo' }
const src = '{% assign foo="FOO" %}{{foo}}'
- return liquid.parseAndRender(src, ctx)
- .then(x => {
- expect(x).to.equal('FOO')
- expect(ctx.foo).to.equal('foo')
- })
+ const html = await liquid.parseAndRender(src, ctx)
+ expect(html).to.equal('FOO')
+ expect(ctx.foo).to.equal('foo')
})
- it('should assign as array', function () {
+ it('should assign as array', async function () {
const src = '{% assign foo=(1..3) %}{{foo}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('[1,2,3]')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('[1,2,3]')
})
- it('should assign as filter result', function () {
+ it('should assign as filter result', async function () {
const src = '{% assign foo="a b" | capitalize | split: " " | first %}{{foo}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('A')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('A')
})
- it('should assign as filter across multiple lines as result', function () {
+ it('should assign as filter across multiple lines as result', async function () {
const src = `{% assign foo="a b"
| capitalize
| split: " "
| first %}{{foo}}`
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('A')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('A')
})
- it('should assign var-1', function () {
+ it('should assign var-1', async function () {
const src = '{% assign var-1 = 5 %}{{ var-1 }}'
- return expect(liquid.parseAndRender(src)).to.eventually.equal('5')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('5')
})
- it('should assign var-', function () {
+ it('should assign var-', async function () {
const src = '{% assign var- = 5 %}{{ var- }}'
- return expect(liquid.parseAndRender(src)).to.eventually.equal('5')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('5')
})
- it('should assign -var', function () {
+ it('should assign -var', async function () {
const src = '{% assign -let = 5 %}{{ -let }}'
- return expect(liquid.parseAndRender(src)).to.eventually.equal('5')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('5')
})
- it('should assign -5-5', function () {
+ it('should assign -5-5', async function () {
const src = '{% assign -5-5 = 5 %}{{ -5-5 }}'
- return expect(liquid.parseAndRender(src)).to.eventually.equal('5')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('5')
})
- it('should assign 4-3', function () {
+ it('should assign 4-3', async function () {
const src = '{% assign 4-3 = 5 %}{{ 4-3 }}'
- return expect(liquid.parseAndRender(src)).to.eventually.equal('5')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('5')
})
- it('should not assign -6', function () {
+ it('should not assign -6', async function () {
const src = '{% assign -6 = 5 %}{{ -6 }}'
- return expect(liquid.parseAndRender(src)).to.eventually.equal('-6')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('-6')
})
})
diff --git a/test/unit/tags/capture.ts b/test/unit/tags/capture.ts
index 6e824328a..5a3b89872 100644
--- a/test/unit/tags/capture.ts
+++ b/test/unit/tags/capture.ts
@@ -1,26 +1,24 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/capture', function () {
const liquid = new Liquid()
- it('should support capture', function () {
+ it('should support capture', async function () {
const src = '{% capture f %}{{"a" | capitalize}}{%endcapture%}{{f}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('A')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('A')
})
- it('should shading rather than overwriting', function () {
+ it('should shading rather than overwriting', async function () {
const src = '{% capture var %}10{% endcapture %}{{var}}'
const ctx = { 'var': 20 }
- return liquid.parseAndRender(src, ctx)
- .then(x => {
- expect(x).to.equal('10')
- expect(ctx.var).to.equal(20)
- })
+ const html = await liquid.parseAndRender(src, ctx)
+ expect(html).to.equal('10')
+ expect(ctx.var).to.equal(20)
})
it('should throw on invalid identifier', function () {
diff --git a/test/unit/tags/case.ts b/test/unit/tags/case.ts
index 10595485c..483f5ec69 100644
--- a/test/unit/tags/case.ts
+++ b/test/unit/tags/case.ts
@@ -1,8 +1,8 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/case', function () {
const liquid = new Liquid()
@@ -12,42 +12,42 @@ describe('tags/case', function () {
return expect(liquid.parseAndRender(src))
.to.be.rejectedWith(/{% case "foo"%} not closed/)
})
- it('should hit the specified case', function () {
+ it('should hit the specified case', async function () {
const src = '{% case "foo"%}' +
'{% when "foo" %}foo{% when "bar"%}bar' +
'{%endcase%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('foo')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('foo')
})
- it('should resolve empty string if not hit', function () {
+ it('should resolve empty string if not hit', async function () {
const src = '{% case empty %}' +
'{% when "foo" %}foo{% when ""%}bar' +
'{%endcase%}'
const ctx = {
empty: ''
}
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('bar')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('bar')
})
- it('should accept empty string as branch name', function () {
+ it('should accept empty string as branch name', async function () {
const src = '{% case false %}' +
'{% when "foo" %}foo{% when ""%}bar' +
'{%endcase%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('')
})
- it('should support boolean case', function () {
+ it('should support boolean case', async function () {
const src = '{% case false %}' +
'{% when "foo" %}foo{% when false%}bar' +
'{%endcase%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('bar')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('bar')
})
- it('should support else branch', function () {
+ it('should support else branch', async function () {
const src = '{% case "a" %}' +
'{% when "b" %}b{% when "c"%}c{%else %}d' +
'{%endcase%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('d')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('d')
})
})
diff --git a/test/unit/tags/comment.ts b/test/unit/tags/comment.ts
index 14aaabc6e..cdd3644cb 100644
--- a/test/unit/tags/comment.ts
+++ b/test/unit/tags/comment.ts
@@ -1,8 +1,8 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/comment', function () {
const liquid = new Liquid()
@@ -11,24 +11,24 @@ describe('tags/comment', function () {
return expect(liquid.parseAndRender(src))
.to.be.rejectedWith(/{% comment %} not closed/)
})
- it('should ignore plain string', function () {
+ it('should ignore plain string', async function () {
const src = 'My name is {% comment %}super{% endcomment %} Shopify.'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('My name is Shopify.')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('My name is Shopify.')
})
- it('should ignore output tokens', function () {
+ it('should ignore output tokens', async function () {
const src = '{% comment %}\n{{ foo}} \n{% endcomment %}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('')
})
- it('should ignore tag tokens', function () {
+ it('should ignore tag tokens', async function () {
const src = '{% comment %}{%if true%}true{%else%}false{%endif%}{% endcomment %}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('')
})
- it('should ignore un-balenced tag tokens', function () {
+ it('should ignore un-balenced tag tokens', async function () {
const src = '{% comment %}{%if true%}true{%else%}false{% endcomment %}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('')
})
})
diff --git a/test/unit/tags/cycle.ts b/test/unit/tags/cycle.ts
index fa965fae3..2c25cea59 100644
--- a/test/unit/tags/cycle.ts
+++ b/test/unit/tags/cycle.ts
@@ -1,16 +1,16 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/cycle', function () {
const liquid = new Liquid()
- it('should support cycle', function () {
+ it('should support cycle', async function () {
const src = "{% cycle '1', '2', '3' %}"
- return expect(liquid.parseAndRender(src + src + src + src))
- .to.eventually.equal('1231')
+ const html = await liquid.parseAndRender(src + src + src + src)
+ return expect(html).to.equal('1231')
})
it('should throw when cycle candidates empty', function () {
@@ -18,23 +18,21 @@ describe('tags/cycle', function () {
.to.be.rejectedWith(/empty candidates/)
})
- it('should support cycle in for block', function () {
+ it('should support cycle in for block', async function () {
const src = '{% for i in (1..5) %}{% cycle one, "e"%}{% endfor %}'
const ctx = {
one: 1
}
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('1e1e1')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('1e1e1')
})
- it('should support cycle group', function () {
+ it('should support cycle group', async function () {
const src = "{% cycle one: '1', '2', '3'%}" +
"{% cycle 1: '1', '2', '3'%}" +
"{% cycle 2: '1', '2', '3'%}"
- const ctx = {
- one: 1
- }
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('121')
+ const ctx = { one: 1 }
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('121')
})
})
diff --git a/test/unit/tags/decrement.ts b/test/unit/tags/decrement.ts
index 44a7a5bf5..6dcf5ff7d 100644
--- a/test/unit/tags/decrement.ts
+++ b/test/unit/tags/decrement.ts
@@ -1,8 +1,8 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/decrement', function () {
const liquid = new Liquid()
@@ -12,49 +12,47 @@ describe('tags/decrement', function () {
return expect(liquid.parseAndRender(src, ctx)).to.be.rejectedWith(/illegal/)
})
- it('should decrement undefined variable', function () {
+ it('should decrement undefined variable', async function () {
const src = '{% decrement var %}{% decrement var %}{% decrement var %}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('-1-2-3')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('-1-2-3')
})
- it('should decrement defined variable', function () {
+ it('should decrement defined variable', async function () {
const src = '{% decrement var %}{% decrement var %}{% decrement var %}'
const ctx = { 'var': 10 }
- return liquid.parseAndRender(src, ctx)
- .then(x => {
- expect(x).to.equal('987')
- expect(ctx.var).to.equal(7)
- })
+ const html = await liquid.parseAndRender(src, ctx)
+ expect(html).to.equal('987')
+ expect(ctx.var).to.equal(7)
})
- it('should be independent from assign', function () {
+ it('should be independent from assign', async function () {
const src = '{% assign var=10 %}{% decrement var %}{% decrement var %}{% decrement var %}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('-1-2-3')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('-1-2-3')
})
- it('should be independent from capture', function () {
+ it('should be independent from capture', async function () {
const src = '{% capture var %}10{% endcapture %}{% decrement var %}{% decrement var %}{% decrement var %}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('-1-2-3')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('-1-2-3')
})
- it('should not shading assign', function () {
+ it('should not shading assign', async function () {
const src = '{% assign var=10 %}{% decrement var %}{% decrement var %}{% decrement var %} {{var}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('-1-2-3 10')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('-1-2-3 10')
})
- it('should not shading capture', function () {
+ it('should not shading capture', async function () {
const src = '{% capture var %}10{% endcapture %}{% decrement var %}{% decrement var %}{% decrement var %} {{var}}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('-1-2-3 10')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('-1-2-3 10')
})
- it('should share the same variable with increment', function () {
+ it('should share the same variable with increment', async function () {
const src = '{%increment var%}{%increment var%}{%decrement var%}{%decrement var%}{%increment var%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('01100')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('01100')
})
})
diff --git a/test/unit/tags/for.ts b/test/unit/tags/for.ts
index f16f6770b..db56b3c1b 100644
--- a/test/unit/tags/for.ts
+++ b/test/unit/tags/for.ts
@@ -1,8 +1,8 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/for', function () {
let liquid, ctx
@@ -22,28 +22,28 @@ describe('tags/for', function () {
emptyArray: []
}
})
- it('should support array', function () {
+ it('should support array', async function () {
const src = '{%for c in alpha%}{{c}}{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('abc')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('abc')
})
- it('should support object', function () {
+ it('should support object', async function () {
const src = '{%for item in obj%}{{item[0]}},{{item[1]}}-{%else%}b{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('foo,bar-coo,haa-')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('foo,bar-coo,haa-')
})
describe('scope', function () {
- it('should read super scope', function () {
+ it('should read super scope', async function () {
const src = '{%for a in (1..2)%}{{num}}{%endfor%}'
- return expect(liquid.parseAndRender(src, { num: 1 }))
- .to.eventually.equal('11')
+ const html = await liquid.parseAndRender(src, { num: 1 })
+ return expect(html).to.equal('11')
})
- it('should write super scope', function () {
+ it('should write super scope', async function () {
const src = '{%for a in (1..2)%}{{num}}{%assign num = 2%}{%endfor%}'
- return expect(liquid.parseAndRender(src, { num: 1 }))
- .to.eventually.equal('12')
+ const html = await liquid.parseAndRender(src, { num: 1 })
+ return expect(html).to.equal('12')
})
})
@@ -62,45 +62,45 @@ describe('tags/for', function () {
})
describe('else', function () {
- it('should goto else for empty array', function () {
+ it('should goto else for empty array', async function () {
const src = '{%for c in emptyArray%}a{%else%}b{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('b')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('b')
})
- it('should treat non-empty string as one single element', function () {
+ it('should treat non-empty string as one single element', async function () {
const src = '{%for c in "abc"%}x{{c}}{%else%}y{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('xabc')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('xabc')
})
- it('should goto else for empty string', function () {
+ it('should goto else for empty string', async function () {
const src = '{%for c in ""%}a{%else%}b{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('b')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('b')
})
- it('should goto else for empty string object', function () {
+ it('should goto else for empty string object', async function () {
// it should be false although `new String` is none-conform
const src = '{%for c in strObj%}a{%else%}b{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('b')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('b')
})
- it('should goto else for empty object', function () {
+ it('should goto else for empty object', async function () {
const src = '{%for c in emptyObj%}a{%else%}b{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('b')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('b')
})
- it('should goto else for null-prototyped object', function () {
+ it('should goto else for null-prototyped object', async function () {
const src = '{%for c in nullProtoObj%}a{%else%}b{%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('b')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('b')
})
})
- it('should support for with forloop', function () {
+ it('should support for with forloop', async function () {
const src = '{%for c in alpha%}' +
'{{forloop.first}}.{{forloop.index}}.{{forloop.index0}}.' +
'{{forloop.last}}.{{forloop.length}}.' +
@@ -110,41 +110,41 @@ describe('tags/for', function () {
const dst = 'true.1.0.false.3.3.2a\n' +
'false.2.1.false.3.2.1b\n' +
'false.3.2.true.3.1.0c\n'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal(dst)
})
- it('should support for with continue', function () {
+ it('should support for with continue', async function () {
const src = '{% for i in (1..5) %}' +
'{{i}}{% continue %}after' +
'{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('12345')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('12345')
})
- it('should support for with break', function () {
+ it('should support for with break', async function () {
const src = '{% for i in (one..5) %}' +
'{% if i == 4 %}{% break %}{% endif %}' +
'{{ i }}' +
'{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('123')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('123')
})
describe('limit', function () {
- it('should support for with limit', function () {
+ it('should support for with limit', async function () {
const src = '{% for i in (1..5) limit:2 %}{{ i }}{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('12')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('12')
})
- it('should set forloop.last properly', function () {
+ it('should set forloop.last properly', async function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.last}} {%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('false true ')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('false true ')
})
- it('should set forloop.first properly', function () {
+ it('should set forloop.first properly', async function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.first}} {%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('true false ')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('true false ')
})
it('should set forloop.length properly', function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.length}} {%endfor%}'
@@ -154,50 +154,50 @@ describe('tags/for', function () {
})
describe('offset', function () {
- it('should support offset with limit', function () {
+ it('should support offset with limit', async function () {
const src = '{% for i in (1..10) limit:2 offset:5%}{{ i }}{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('67')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('67')
})
- it('should set index properly', function () {
+ it('should set index properly', async function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index}} {%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('1 2 ')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('1 2 ')
})
- it('should set index0 properly', function () {
+ it('should set index0 properly', async function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.index0}} {%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('0 1 ')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('0 1 ')
})
- it('should set rindex properly', function () {
+ it('should set rindex properly', async function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex}} {%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('2 1 ')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('2 1 ')
})
- it('should set rindex0 properly', function () {
+ it('should set rindex0 properly', async function () {
const src = '{%for i in (1..10) limit:2 offset:3%}{{forloop.rindex0}} {%endfor%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('1 0 ')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('1 0 ')
})
})
describe('reverse', function () {
- it('should support for reversed in the last position', function () {
+ it('should support for reversed in the last position', async function () {
const src = '{% for i in (1..5) limit:2 reversed %}{{ i }}{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('21')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('21')
})
- it('should support for reversed in the first position', function () {
+ it('should support for reversed in the first position', async function () {
const src = '{% for i in (1..5) reversed limit:2 %}{{ i }}{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('21')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('21')
})
- it('should support for reversed in the middle position', function () {
+ it('should support for reversed in the middle position', async function () {
const src = '{% for i in (1..5) offset:2 reversed limit:4 %}{{ i }}{% endfor %}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('543')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('543')
})
})
})
diff --git a/test/unit/tags/if.ts b/test/unit/tags/if.ts
index 407f1f5be..c624a21e1 100644
--- a/test/unit/tags/if.ts
+++ b/test/unit/tags/if.ts
@@ -1,8 +1,5 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
-
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+import { expect } from 'chai'
describe('tags/if', function () {
const liquid = new Liquid()
@@ -18,99 +15,99 @@ describe('tags/if', function () {
return expect(liquid.parseAndRender(src, ctx))
.to.be.rejectedWith(/tag {% if false%} not closed/)
})
- it('should support nested', function () {
+ it('should support nested', async function () {
const src = '{%if false%}{%if true%}{%else%}a{%endif%}{%endif%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('')
})
describe('single value as condition', function () {
- it('should support boolean', function () {
+ it('should support boolean', async function () {
const src = '{% if false %}1{%elsif true%}2{%else%}3{%endif%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('2')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('2')
})
- it('should treat Array truthy', function () {
+ it('should treat Array truthy', async function () {
const src = '{%if emptyArray%}a{%endif%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('a')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('a')
})
- it('should return true if empty string', function () {
+ it('should return true if empty string', async function () {
const src = '{%if emptyString%}a{%endif%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('a')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('a')
})
})
describe('expression as condition', function () {
- it('should support ==', function () {
+ it('should support ==', async function () {
const src = '{% if 2==3 %}yes{%else%}no{%endif%}'
- return expect(liquid.parseAndRender(src, ctx))
- .to.eventually.equal('no')
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal('no')
})
- it('should support >=', function () {
+ it('should support >=', async function () {
const src = '{% if 1>=2 and one {{person.firstName}} {{person.lastName}} Joe Shmoe Joe Shmoe Lorem Ipsum {% for p in a[1]%} {{foo | date: "%Y-%m-%d"}}
{% include "address" %}
City: Dallas
City: Dallas '
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
- it('should support cols', function () {
+ it('should support cols', async function () {
const src = '{% tablerow i in alpha cols:2 %}{{ i }}{% endtablerow %}'
const ctx = {
alpha: ['a', 'b', 'c']
@@ -21,25 +19,29 @@ describe('tags/tablerow', function () {
const dst =
'1 2 3 ' +
'a b '
- return expect(liquid.parseAndRender(src, ctx)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src, ctx)
+ return expect(html).to.equal(dst)
})
- it('should support cols set to 0', function () {
+ it('should support cols set to 0', async function () {
const src = '{% tablerow i in (1..3) cols:0 %}{{ i }}{% endtablerow %}'
const dst = 'c '
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
- it('should support empty tablerow', function () {
+ it('should support empty tablerow', async function () {
const src = '{% tablerow i in (1..0) cols:2 %}{{ i }}{% endtablerow %}'
const dst = ''
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
- it('should support empty array', function () {
+ it('should support empty array', async function () {
const src = '{% tablerow i in alpha.z cols:2 %}{{ i }}{% endtablerow %}'
const dst = ''
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
it('should throw when tablerow not closed', function () {
@@ -48,26 +50,29 @@ describe('tags/tablerow', function () {
.to.be.rejectedWith(/tag .* not closed/)
})
- it('should support tablerow with range', function () {
+ it('should support tablerow with range', async function () {
const src = '{% tablerow i in (1..5) cols:2 %}{{ i }}{% endtablerow %}'
const dst =
'1 2 3 ' +
'1 2 ' +
'3 4 '
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
- it('should support tablerow with limit', function () {
+ it('should support tablerow with limit', async function () {
const src = '{% tablerow i in (1..5) cols:2 limit:3 %}{{ i }}{% endtablerow %}'
const dst =
'5 ' +
'1 2 '
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
- it('should support tablerow with offset', function () {
+ it('should support tablerow with offset', async function () {
const src = '{% tablerow i in (1..5) cols:2 offset:3 %}{{ i }}{% endtablerow %}'
const dst = '3 '
- return expect(liquid.parseAndRender(src)).to.eventually.equal(dst)
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal(dst)
})
})
diff --git a/test/unit/tags/unless.ts b/test/unit/tags/unless.ts
index efe8078eb..37eac9c1b 100644
--- a/test/unit/tags/unless.ts
+++ b/test/unit/tags/unless.ts
@@ -1,37 +1,37 @@
import Liquid from 'src/liquid'
-import * as chai from 'chai'
+import { expect, use } from 'chai'
+import * as chaiAsPromised from 'chai-as-promised'
-const expect = chai.expect
-chai.use(require('chai-as-promised'))
+use(chaiAsPromised)
describe('tags/unless', function () {
let liquid
before(() => { liquid = new Liquid() })
- it('should render else when predicate yields true', function () {
+ it('should render else when predicate yields true', async function () {
// 0 is truthy
const src = '{% unless 0 %}yes{%else%}no{%endunless%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('no')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('no')
})
- it('should render unless when predicate yields false', function () {
+ it('should render unless when predicate yields false', async function () {
const src = '{% unless false %}yes{%else%}no{%endunless%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('yes')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('yes')
})
it('should reject when tag not closed', function () {
const src = '{% unless 1>2 %}yes'
return expect(liquid.parseAndRender(src))
.to.be.rejectedWith(/tag {% unless 1>2 %} not closed/)
})
- it('should render unless when predicate yields false and else undefined', function () {
+ it('should render unless when predicate yields false and else undefined', async function () {
const src = '{% unless 1>2 %}yes{%endunless%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('yes')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('yes')
})
- it('should render "" when predicate yields false and else undefined', function () {
+ it('should render "" when predicate yields false and else undefined', async function () {
const src = '{% unless 1<2 %}yes{%endunless%}'
- return expect(liquid.parseAndRender(src))
- .to.eventually.equal('')
+ const html = await liquid.parseAndRender(src)
+ return expect(html).to.equal('')
})
})
diff --git a/test/unit/template-browser.ts b/test/unit/template-browser.ts
index a92b57566..8989c3d02 100644
--- a/test/unit/template-browser.ts
+++ b/test/unit/template-browser.ts
@@ -1,7 +1,5 @@
import { resolve } from '../../src/parser/template-browser'
-import * as chai from 'chai'
-
-const expect = chai.expect
+import { expect } from 'chai'
describe('template-browser', function () {
if (+process.version.match(/^v(\d+)/)[1] < 8) {
diff --git a/test/unit/template.ts b/test/unit/template.ts
index 55270717e..146549a07 100644
--- a/test/unit/template.ts
+++ b/test/unit/template.ts
@@ -1,11 +1,7 @@
import { resolve } from '../../src/parser/template'
import * as mock from 'mock-fs'
-import * as chai from 'chai'
+import { expect } from 'chai'
import * as path from 'path'
-import * as chaiAsPromised from 'chai-as-promised'
-
-const expect = chai.expect
-chai.use(chaiAsPromised)
describe('template', function () {
before(function () {
@@ -14,10 +10,10 @@ describe('template', function () {
})
})
describe('#resolve()', function () {
- it('should resolve based on root', function () {
- const filepath = resolve('bar.html', '/foo', { root: [] })
+ it('should resolve based on root', async function () {
+ const filepath = await resolve('bar.html', '/foo', { root: [] })
const expected = path.resolve('/foo/bar.html')
- return expect(filepath).to.eventually.equal(expected)
+ return expect(filepath).to.equal(expected)
})
it('should resolve based on root', function () {
return expect(resolve('foo.html', '/foo', { root: [] }))
diff --git a/test/unit/tokenizer.ts b/test/unit/tokenizer.ts
index c74693efb..1171e1696 100644
--- a/test/unit/tokenizer.ts
+++ b/test/unit/tokenizer.ts
@@ -1,14 +1,15 @@
import { expect } from 'chai'
-import { parse } from 'src/parser/tokenizer'
+import Tokenizer from 'src/parser/tokenizer'
import TagToken from 'src/parser/tag-token'
import OutputToken from 'src/parser/output-token'
import HTMLToken from 'src/parser/html-token'
describe('tokenizer', function () {
+ const tokenizer = new Tokenizer()
describe('parse', function () {
it('should handle plain HTML', function () {
const html = '4 5