mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
chore(TypeScript): refactor objects into classes
fix: `Nil`(null, undefined) now renders as empty string change: `parser.parseValue()` renamed to `parser.parseOutput` change: registered tags/filters become static and shared across different liquid instances
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
var chai = require('chai')
|
||||
var Liquid = require('../..')
|
||||
var expect = chai.expect
|
||||
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('.evalValue()', function () {
|
||||
var engine
|
||||
beforeEach(() => engine = new Liquid())
|
||||
|
||||
it('should throw when scope undefined', function () {
|
||||
expect(() => engine.evalValue('{{"foo"}}')).to.throw(/scope undefined/)
|
||||
})
|
||||
})
|
||||
@@ -1,14 +1,14 @@
|
||||
const chai = require('chai')
|
||||
const request = require('supertest')
|
||||
const express = require('express')
|
||||
const mock = require('mock-fs')
|
||||
const Liquid = require('../../dist/liquid.common.js')
|
||||
const chaiAsPromised = require('chai-as-promised')
|
||||
import * as chai from 'chai'
|
||||
import * as request from 'supertest'
|
||||
import * as express from 'express'
|
||||
import * as mock from 'mock-fs'
|
||||
import Liquid from '../../dist/liquid.common.js'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('engine#express()', function () {
|
||||
describe('express()', function () {
|
||||
var app, engine
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -84,7 +84,7 @@ describe('engine#express()', function () {
|
||||
.expect('bar')
|
||||
.expect(200, done)
|
||||
})
|
||||
it('should respect express views (Undefined) when lookup', function (done) {
|
||||
it('should respect express views (undefined) when lookup', function (done) {
|
||||
const files = {}
|
||||
files[process.cwd() + '/views/include.html'] = '{% include file %}'
|
||||
files[process.cwd() + '/views/bar.html'] = 'bar'
|
||||
@@ -12,15 +12,15 @@ describe('.parseAndRender()', function () {
|
||||
strict_filters: true
|
||||
})
|
||||
})
|
||||
it('should value object', function () {
|
||||
it('should stringify object', function () {
|
||||
var ctx = { obj: { foo: 'bar' } }
|
||||
return expect(engine.parseAndRender('{{obj}}', ctx)).to.eventually.equal('{"foo":"bar"}')
|
||||
})
|
||||
it('should value array', function () {
|
||||
it('should stringify array ', function () {
|
||||
var ctx = { arr: [-2, 'a'] }
|
||||
return expect(engine.parseAndRender('{{arr}}', ctx)).to.eventually.equal('[-2,"a"]')
|
||||
})
|
||||
it('should value undefined to empty', function () {
|
||||
it('should render undefined as empty', function () {
|
||||
return expect(engine.parseAndRender('foo{{zzz}}bar', {})).to.eventually.equal('foobar')
|
||||
})
|
||||
it('should render as null when filter undefined', function () {
|
||||
@@ -1,8 +1,10 @@
|
||||
const chai = require('chai')
|
||||
const Liquid = require('../..')
|
||||
import * as chai from 'chai'
|
||||
import Liquid from '../..'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
const liquid = new Liquid()
|
||||
const expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
const cases = [
|
||||
{
|
||||
@@ -1,28 +1,30 @@
|
||||
var Liquid = require('../../dist/liquid.js')
|
||||
var sinon = require('sinon')
|
||||
var chai = require('chai')
|
||||
var expect = chai.expect
|
||||
chai.use(require('chai-as-promised'))
|
||||
import Liquid from '../../dist/liquid.js'
|
||||
import { createFakeServer, useFakeXMLHttpRequest } from 'sinon'
|
||||
import * as chai from 'chai'
|
||||
import * as chaiAsPromised from 'chai-as-promised'
|
||||
import { JSDOM } from 'jsdom'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('xhr', () => {
|
||||
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
||||
if (+process.version.match(/^v(\d+)/)[1] < 8) {
|
||||
console.info('jsdom not supported, skipping xhr...')
|
||||
return
|
||||
}
|
||||
var JSDOM = require('jsdom').JSDOM
|
||||
var server, engine
|
||||
let server, engine
|
||||
beforeEach(() => {
|
||||
server = sinon.createFakeServer()
|
||||
server = createFakeServer()
|
||||
server.autoRespond = true
|
||||
server.respondWith('GET', 'https://example.com/views/hello.html',
|
||||
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
|
||||
var dom = new JSDOM('', {
|
||||
let dom = new JSDOM('', {
|
||||
url: 'https://example.com/foo/bar.html',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true
|
||||
})
|
||||
global.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
|
||||
global.document = dom.window.document
|
||||
});
|
||||
(global as any).XMLHttpRequest = useFakeXMLHttpRequest();
|
||||
(global as any).document = dom.window.document;
|
||||
engine = new Liquid({
|
||||
root: 'https://example.com/views/',
|
||||
extname: '.html'
|
||||
@@ -30,8 +32,8 @@ describe('xhr', () => {
|
||||
})
|
||||
afterEach(() => {
|
||||
server.restore()
|
||||
delete global.XMLHttpRequest
|
||||
delete global.document
|
||||
delete (global as any).XMLHttpRequest
|
||||
delete (global as any).document
|
||||
})
|
||||
describe('#renderFile()', () => {
|
||||
it('should support without extname', () => {
|
||||
@@ -70,8 +72,8 @@ describe('xhr', () => {
|
||||
.catch(function (e) {
|
||||
expect(e.message).to.equal('An error occurred whilst receiving the response.')
|
||||
done()
|
||||
})
|
||||
global.XMLHttpRequest.onCreate = function (request) {
|
||||
});
|
||||
(global as any).XMLHttpRequest.onCreate = function (request) {
|
||||
setTimeout(() => request.error())
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user