feature: get nyc, babel and coveralls working

This commit is contained in:
harttle
2018-08-26 21:54:35 +08:00
parent d828c4021e
commit 31c39561c9
50 changed files with 361 additions and 482 deletions
-11
View File
@@ -1,11 +0,0 @@
{
"presets": ["env"],
"plugins": [
["transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}]
]
}
-1
View File
@@ -2,7 +2,6 @@ language: node_js
node_js:
- "8"
- "6"
- "4"
before_script:
- npm install -g mocha
after_script:
+51 -132
View File
@@ -45,36 +45,6 @@ var asyncToGenerator = function (fn) {
};
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
@@ -877,7 +847,7 @@ function uniq(arr) {
*/
function isObject(value) {
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
return value != null && (type === 'object' || type === 'function');
return value !== null && (type === 'object' || type === 'function');
}
/*
@@ -981,117 +951,66 @@ function parseLiteral(str) {
throw new TypeError('cannot parse \'' + str + '\' as literal');
}
var LiquidError = function (_Error) {
inherits(LiquidError, _Error);
function LiquidError(message) {
classCallCheck(this, LiquidError);
var _this = possibleConstructorReturn(this, (LiquidError.__proto__ || Object.getPrototypeOf(LiquidError)).call(this, message));
_this.name = _this.constructor.name;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(_this, _this.constructor);
} else {
_this.stack = new Error(message).stack;
}
return _this;
function initError() {
this.name = this.constructor.name;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
return LiquidError;
}(Error);
function initLiquidError(err, token) {
initError.call(this);
var TemplateError = function (_LiquidError) {
inherits(TemplateError, _LiquidError);
this.input = token.input;
this.line = token.line;
this.file = token.file;
function TemplateError(err, token) {
classCallCheck(this, TemplateError);
var context = mkContext(token.input, token.line);
this.message = mkMessage(err.message, token);
this.stack = context + '\n' + (this.stack || this.message) + (err.stack ? '\nFrom ' + err.stack : '');
}
var _this2 = possibleConstructorReturn(this, (TemplateError.__proto__ || Object.getPrototypeOf(TemplateError)).call(this));
function TokenizationError(message, token) {
initLiquidError.call(this, { message: message }, token);
}
TokenizationError.prototype = create(Error.prototype);
TokenizationError.prototype.constructor = TokenizationError;
_this2.input = token.input;
_this2.line = token.line;
_this2.file = token.file;
_this2.message = mkMessage(err.message, token);
var context = mkContext(token.input, token.line);
_this2.stack = context + '\n' + (_this2.stack || _this2.message) + (err.stack ? '\nFrom ' + err.stack : '');
return _this2;
function ParseError(e, token) {
assign(this, e);
this.originalError = e;
initLiquidError.call(this, e, token);
}
ParseError.prototype = create(Error.prototype);
ParseError.prototype.constructor = ParseError;
function RenderError(e, tpl) {
// return the original render error
if (e instanceof RenderError) {
return e;
}
assign(this, e);
this.originalError = e;
return TemplateError;
}(LiquidError);
initLiquidError.call(this, e, tpl.token);
}
RenderError.prototype = create(Error.prototype);
RenderError.prototype.constructor = RenderError;
var TokenizationError = function (_TemplateError) {
inherits(TokenizationError, _TemplateError);
function RenderBreakError(message) {
initError.call(this);
this.message = message + '';
}
RenderBreakError.prototype = create(Error.prototype);
RenderBreakError.prototype.constructor = RenderBreakError;
function TokenizationError(message, token) {
classCallCheck(this, TokenizationError);
return possibleConstructorReturn(this, (TokenizationError.__proto__ || Object.getPrototypeOf(TokenizationError)).call(this, { message: message }, token));
}
return TokenizationError;
}(TemplateError);
var ParseError = function (_TemplateError2) {
inherits(ParseError, _TemplateError2);
function ParseError(e, token) {
classCallCheck(this, ParseError);
var _this4 = possibleConstructorReturn(this, (ParseError.__proto__ || Object.getPrototypeOf(ParseError)).call(this, e, token));
assign(_this4, e);
_this4.originalError = e;
return _this4;
}
return ParseError;
}(TemplateError);
var RenderError = function (_TemplateError3) {
inherits(RenderError, _TemplateError3);
function RenderError(e, tpl) {
classCallCheck(this, RenderError);
// return the original render error
if (e instanceof RenderError) {
var _ret;
return _ret = e, possibleConstructorReturn(_this5, _ret);
}
var _this5 = possibleConstructorReturn(this, (RenderError.__proto__ || Object.getPrototypeOf(RenderError)).call(this, e, tpl.token));
assign(_this5, e);
_this5.originalError = e;
return _this5;
}
return RenderError;
}(TemplateError);
var RenderBreakError = function (_LiquidError2) {
inherits(RenderBreakError, _LiquidError2);
function RenderBreakError(message) {
classCallCheck(this, RenderBreakError);
return possibleConstructorReturn(this, (RenderBreakError.__proto__ || Object.getPrototypeOf(RenderBreakError)).call(this, message + ''));
}
return RenderBreakError;
}(LiquidError);
var AssertionError = function (_LiquidError3) {
inherits(AssertionError, _LiquidError3);
function AssertionError(message) {
classCallCheck(this, AssertionError);
return possibleConstructorReturn(this, (AssertionError.__proto__ || Object.getPrototypeOf(AssertionError)).call(this, message + ''));
}
return AssertionError;
}(LiquidError);
function AssertionError(message) {
initError.call(this);
this.message = message + '';
}
AssertionError.prototype = create(Error.prototype);
AssertionError.prototype.constructor = AssertionError;
function mkContext(input, line) {
var lines = input.split('\n');
+1 -1
View File
File diff suppressed because one or more lines are too long
+51 -132
View File
@@ -44,36 +44,6 @@
};
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
@@ -876,7 +846,7 @@
*/
function isObject(value) {
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
return value != null && (type === 'object' || type === 'function');
return value !== null && (type === 'object' || type === 'function');
}
/*
@@ -980,117 +950,66 @@
throw new TypeError('cannot parse \'' + str + '\' as literal');
}
var LiquidError = function (_Error) {
inherits(LiquidError, _Error);
function LiquidError(message) {
classCallCheck(this, LiquidError);
var _this = possibleConstructorReturn(this, (LiquidError.__proto__ || Object.getPrototypeOf(LiquidError)).call(this, message));
_this.name = _this.constructor.name;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(_this, _this.constructor);
} else {
_this.stack = new Error(message).stack;
}
return _this;
function initError() {
this.name = this.constructor.name;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
return LiquidError;
}(Error);
function initLiquidError(err, token) {
initError.call(this);
var TemplateError = function (_LiquidError) {
inherits(TemplateError, _LiquidError);
this.input = token.input;
this.line = token.line;
this.file = token.file;
function TemplateError(err, token) {
classCallCheck(this, TemplateError);
var context = mkContext(token.input, token.line);
this.message = mkMessage(err.message, token);
this.stack = context + '\n' + (this.stack || this.message) + (err.stack ? '\nFrom ' + err.stack : '');
}
var _this2 = possibleConstructorReturn(this, (TemplateError.__proto__ || Object.getPrototypeOf(TemplateError)).call(this));
function TokenizationError(message, token) {
initLiquidError.call(this, { message: message }, token);
}
TokenizationError.prototype = create(Error.prototype);
TokenizationError.prototype.constructor = TokenizationError;
_this2.input = token.input;
_this2.line = token.line;
_this2.file = token.file;
_this2.message = mkMessage(err.message, token);
var context = mkContext(token.input, token.line);
_this2.stack = context + '\n' + (_this2.stack || _this2.message) + (err.stack ? '\nFrom ' + err.stack : '');
return _this2;
function ParseError(e, token) {
assign(this, e);
this.originalError = e;
initLiquidError.call(this, e, token);
}
ParseError.prototype = create(Error.prototype);
ParseError.prototype.constructor = ParseError;
function RenderError(e, tpl) {
// return the original render error
if (e instanceof RenderError) {
return e;
}
assign(this, e);
this.originalError = e;
return TemplateError;
}(LiquidError);
initLiquidError.call(this, e, tpl.token);
}
RenderError.prototype = create(Error.prototype);
RenderError.prototype.constructor = RenderError;
var TokenizationError = function (_TemplateError) {
inherits(TokenizationError, _TemplateError);
function RenderBreakError(message) {
initError.call(this);
this.message = message + '';
}
RenderBreakError.prototype = create(Error.prototype);
RenderBreakError.prototype.constructor = RenderBreakError;
function TokenizationError(message, token) {
classCallCheck(this, TokenizationError);
return possibleConstructorReturn(this, (TokenizationError.__proto__ || Object.getPrototypeOf(TokenizationError)).call(this, { message: message }, token));
}
return TokenizationError;
}(TemplateError);
var ParseError = function (_TemplateError2) {
inherits(ParseError, _TemplateError2);
function ParseError(e, token) {
classCallCheck(this, ParseError);
var _this4 = possibleConstructorReturn(this, (ParseError.__proto__ || Object.getPrototypeOf(ParseError)).call(this, e, token));
assign(_this4, e);
_this4.originalError = e;
return _this4;
}
return ParseError;
}(TemplateError);
var RenderError = function (_TemplateError3) {
inherits(RenderError, _TemplateError3);
function RenderError(e, tpl) {
classCallCheck(this, RenderError);
// return the original render error
if (e instanceof RenderError) {
var _ret;
return _ret = e, possibleConstructorReturn(_this5, _ret);
}
var _this5 = possibleConstructorReturn(this, (RenderError.__proto__ || Object.getPrototypeOf(RenderError)).call(this, e, tpl.token));
assign(_this5, e);
_this5.originalError = e;
return _this5;
}
return RenderError;
}(TemplateError);
var RenderBreakError = function (_LiquidError2) {
inherits(RenderBreakError, _LiquidError2);
function RenderBreakError(message) {
classCallCheck(this, RenderBreakError);
return possibleConstructorReturn(this, (RenderBreakError.__proto__ || Object.getPrototypeOf(RenderBreakError)).call(this, message + ''));
}
return RenderBreakError;
}(LiquidError);
var AssertionError = function (_LiquidError3) {
inherits(AssertionError, _LiquidError3);
function AssertionError(message) {
classCallCheck(this, AssertionError);
return possibleConstructorReturn(this, (AssertionError.__proto__ || Object.getPrototypeOf(AssertionError)).call(this, message + ''));
}
return AssertionError;
}(LiquidError);
function AssertionError(message) {
initError.call(this);
this.message = message + '';
}
AssertionError.prototype = create(Error.prototype);
AssertionError.prototype.constructor = AssertionError;
function mkContext(input, line) {
var lines = input.split('\n');
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+34 -3
View File
@@ -7,9 +7,11 @@
"browser": "dist/liquid.js",
"scripts": {
"lint": "eslint src/ test/ *.js",
"test": "mocha --require babel-core/register --recursive",
"coverage": "nyc report --require babel-core/register mocha test/ --recursive ",
"coveralls": "nyc report --reporter=text-lcov --require babel-core/register mocha test/ --recursive | coveralls",
"test": "npm run test:unit && npm run test:e2e",
"test:unit": "mocha test/unit",
"test:e2e": "mocha test/e2e",
"coverage": "cross-env NODE_ENV=test nyc report --reporter=html mocha test/unit",
"coveralls": "cross-env NODE_ENV=test nyc report --reporter=text-lcov mocha | coveralls",
"dist": "rollup -c && ls -lh dist",
"demo:browser": "echo open http://localhost:8080/demo/browser && http-server -c-1",
"demo:nodejs": "node ./demo/nodejs/index.js",
@@ -41,11 +43,14 @@
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-runtime": "^6.26.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.0",
"cross-env": "^5.2.0",
"eslint": "^5.2.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.7.0",
@@ -68,5 +73,31 @@
"sinon": "^6.1.4",
"sinon-chai": "^3.2.0",
"supertest": "^3.0.0"
},
"nyc": {
"require": [
"babel-core/register"
],
"sourceMap": false,
"instrument": false
},
"babel": {
"presets": ["env"],
"plugins": [
[
"transform-runtime",
{
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
}
+1 -1
View File
@@ -116,7 +116,7 @@ export function uniq (arr) {
*/
export function isObject (value) {
const type = typeof value
return value != null && (type === 'object' || type === 'function')
return value !== null && (type === 'object' || type === 'function')
}
/*
+6
View File
@@ -0,0 +1,6 @@
{
"rules": {
"no-var": 0,
"prefer-const": 0
}
}
+7 -7
View File
@@ -1,15 +1,15 @@
import chai from 'chai'
import request from 'supertest'
import express from 'express'
import mock from 'mock-fs'
import Liquid from '../src'
import chaiAsPromised from 'chai-as-promised'
const chai = require('chai')
const request = require('supertest')
const express = require('express')
const mock = require('mock-fs')
const Liquid = require('../..')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(chaiAsPromised)
describe('engine#express()', function () {
let app, engine
var app, engine
beforeEach(function () {
app = express()
+59
View File
@@ -0,0 +1,59 @@
var chai = require('chai')
var Liquid = require('../..')
var expect = chai.expect
chai.use(require('chai-as-promised'))
describe('.parseAndRender()', function () {
var engine, strictEngine
beforeEach(function () {
engine = Liquid()
strictEngine = Liquid({
strict_filters: true
})
})
it('should value object', function () {
var ctx = { obj: {foo: 'bar'} }
return expect(engine.parseAndRender('{{obj}}', ctx)).to.eventually.equal('{"foo":"bar"}')
})
it('should value 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 () {
return expect(engine.parseAndRender('foo{{zzz}}bar', {})).to.eventually.equal('foobar')
})
it('should render as null when filter undefined', function () {
return expect(engine.parseAndRender('{{"foo" | filter1}}', {})).to.eventually.equal('foo')
})
it('should throw upon undefined filter when strict_filters set', function () {
return expect(strictEngine.parseAndRender('{{"foo" | filter1}}', {})).to
.be.rejectedWith(/undefined filter: filter1/)
})
it('should parse html', function () {
expect(function () {
engine.parse('{{obj}}')
}).to.not.throw()
expect(function () {
engine.parse('<html><head>{{obj}}</head></html>')
}).to.not.throw()
})
it('should render template multiple times', function () {
var ctx = {obj: {foo: 'bar'}}
var template = engine.parse('{{obj}}')
return engine.render(template, ctx)
.then(result => expect(result).to.equal('{"foo":"bar"}'))
.then(() => engine.render(template, ctx))
.then((result) => expect(result).to.equal('{"foo":"bar"}'))
})
it('should render filters', function () {
var ctx = {names: ['alice', 'bob']}
var template = engine.parse('<p>{{names | join: ","}}</p>')
return expect(engine.render(template, ctx)).to.eventually.equal('<p>alice,bob</p>')
})
it('should render accessive filters', function () {
var src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
'{{ my_array | first }}'
return expect(engine.parseAndRender(src)).to.eventually.equal('apples')
})
})
+82
View File
@@ -0,0 +1,82 @@
var chai = require('chai')
var mock = require('mock-fs')
var Liquid = require('../..')
var expect = chai.expect
chai.use(require('chai-as-promised'))
describe('#renderFile()', function () {
var engine
beforeEach(function () {
engine = Liquid({
root: '/root/',
extname: '.html'
})
mock({
'/root/files/bar': 'bar',
'/root/files/foo.html': 'foo',
'/root/files/name.html': 'My name is {{name}}.',
'/un-readable.html': mock.file({
mode: '0000'
})
})
})
afterEach(function () {
mock.restore()
})
it('should ignore invalid root option', function () {
var liquid = Liquid({ root: /regex/ })
expect(liquid.options.root).to.deep.equal([])
})
it('should render file', function () {
return expect(engine.renderFile('/root/files/foo.html', {}))
.to.eventually.equal('foo')
})
it('should find files without extname', function () {
var engine = Liquid({root: '/root'})
return expect(engine.renderFile('/root/files/bar', {}))
.to.eventually.equal('bar')
})
it('should accept relative path', function () {
return expect(engine.renderFile('files/foo.html'))
.to.eventually.equal('foo')
})
it('should resolve array as root', function () {
engine = Liquid({
root: ['/boo', '/root/'],
extname: '.html'
})
return expect(engine.renderFile('files/foo.html'))
.to.eventually.equal('foo')
})
it('should default root to cwd', function () {
var files = {}
files[process.cwd() + '/foo.html'] = 'FOO'
mock(files)
engine = Liquid({
extname: '.html'
})
return expect(engine.renderFile('foo.html'))
.to.eventually.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 use default extname', function () {
return expect(engine.renderFile('files/name', {name: 'harttle'})).to.eventually.equal('My name is harttle.')
})
it('should throw with lookup list when file not exist', function () {
engine = Liquid({
root: ['/boo', '/root/'],
extname: '.html'
})
return expect(engine.renderFile('/not/exist.html')).to
.be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i)
})
it('should throw when file not readable', function () {
return expect(engine.renderFile('/un-readable.html')).to
.be.rejectedWith(/EACCES/)
})
})
@@ -1,6 +1,5 @@
import chai from 'chai'
import Liquid from '../src'
const chai = require('chai')
const Liquid = require('../..')
const liquid = new Liquid()
const expect = chai.expect
chai.use(require('chai-as-promised'))
+6 -6
View File
@@ -1,15 +1,15 @@
import Liquid from '../src'
import sinon from 'sinon'
import chai from 'chai'
const expect = chai.expect
var Liquid = require('../..')
var sinon = require('sinon')
var chai = require('chai')
var expect = chai.expect
chai.use(require('chai-as-promised'))
describe('xhr', () => {
if (process.version.match(/^v(\d+)/)[1] < 8) {
return
}
const JSDOM = require('jsdom').JSDOM
let server, engine, dom
var JSDOM = require('jsdom').JSDOM
var server, engine, dom
beforeEach(() => {
server = sinon.createFakeServer()
server.autoRespond = true
-140
View File
@@ -1,140 +0,0 @@
import chai from 'chai'
import mock from 'mock-fs'
import Liquid from '../src'
import chaiAsPromised from 'chai-as-promised'
const expect = chai.expect
chai.use(chaiAsPromised)
describe('liquid', function () {
let engine, strictEngine, ctx
beforeEach(function () {
ctx = {
name: 'harttle',
arr: [-2, 'a'],
obj: {
foo: 'bar'
}
}
engine = Liquid({
root: '/root/',
extname: '.html'
})
strictEngine = Liquid({
root: '/root',
extname: '.html',
strict_filters: true
})
mock({
'/root/files/bar': 'bar',
'/root/files/foo.html': 'foo',
'/root/files/name.html': 'My name is {{name}}.',
'/un-readable.html': mock.file({
mode: '0000'
})
})
})
afterEach(function () {
mock.restore()
})
describe('Liquid', function () {
it('should ignore invalid root option', function () {
const liquid = Liquid({ root: /regex/ })
expect(liquid.options.root).to.deep.equal([])
})
})
describe('{{value}}', function () {
it('should value object', function () {
return expect(engine.parseAndRender('{{obj}}', ctx)).to.eventually.equal('{"foo":"bar"}')
})
it('should value array', function () {
return expect(engine.parseAndRender('{{arr}}', ctx)).to.eventually.equal('[-2,"a"]')
})
it('should value undefined to empty', function () {
return expect(engine.parseAndRender('foo{{zzz}}bar', ctx)).to.eventually.equal('foobar')
})
it('should render as null when filter undefined', function () {
return expect(engine.parseAndRender('{{"foo" | filter1}}', ctx)).to.eventually.equal('foo')
})
it('should throw upon undefined filter when strict_filters set', function () {
return expect(strictEngine.parseAndRender('{{arr | filter1}}', ctx)).to
.be.rejectedWith(/undefined filter: filter1/)
})
})
it('should parse html', function () {
expect(function () {
engine.parse('{{obj}}')
}).to.not.throw()
expect(function () {
engine.parse('<html><head>{{obj}}</head></html>')
}).to.not.throw()
})
it('should render template multiple times', function () {
const template = engine.parse('{{obj}}')
return engine.render(template, ctx)
.then(result => expect(result).to.equal('{"foo":"bar"}'))
.then(() => engine.render(template, ctx))
.then((result) => expect(result).to.equal('{"foo":"bar"}'))
})
it('should render filters', function () {
const template = engine.parse('<p>{{arr | join: "_"}}</p>')
return expect(engine.render(template, ctx)).to.eventually.equal('<p>-2_a</p>')
})
it('should render accessive filters', function () {
const src = '{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}' +
'{{ my_array | first }}'
return expect(engine.parseAndRender(src)).to.eventually.equal('apples')
})
describe('#renderFile()', function () {
it('should render file', function () {
return expect(engine.renderFile('/root/files/foo.html', ctx))
.to.eventually.equal('foo')
})
it('should find files without extname', function () {
const engine = Liquid({root: '/root'})
return expect(engine.renderFile('/root/files/bar', ctx))
.to.eventually.equal('bar')
})
it('should accept relative path', function () {
return expect(engine.renderFile('files/foo.html'))
.to.eventually.equal('foo')
})
it('should resolve array as root', function () {
engine = Liquid({
root: ['/boo', '/root/'],
extname: '.html'
})
return expect(engine.renderFile('files/foo.html'))
.to.eventually.equal('foo')
})
it('should default root to cwd', function () {
const files = {}
files[process.cwd() + '/foo.html'] = 'FOO'
mock(files)
engine = Liquid({
extname: '.html'
})
return expect(engine.renderFile('foo.html'))
.to.eventually.equal('FOO')
})
it('should render file with context', function () {
return expect(engine.renderFile('/root/files/name.html', ctx)).to.eventually.equal('My name is harttle.')
})
it('should use default extname', function () {
return expect(engine.renderFile('files/name', ctx)).to.eventually.equal('My name is harttle.')
})
it('should throw with lookup list when file not exist', function () {
engine = Liquid({
root: ['/boo', '/root/'],
extname: '.html'
})
return expect(engine.renderFile('/not/exist.html')).to
.be.rejectedWith(/failed to lookup \/not\/exist.html in: \/boo,\/root\//i)
})
it('should throw when file not readable', function () {
return expect(engine.renderFile('/un-readable.html')).to
.be.rejectedWith(/EACCES/)
})
})
})
+2
View File
@@ -0,0 +1,2 @@
--require babel-core/register
--recursive
+2 -2
View File
@@ -1,8 +1,8 @@
import chai from 'chai'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import Filter from '../src/filter.js'
import {factory as scopeFactory} from '../src/scope.js'
import Filter from '../../src/filter.js'
import {factory as scopeFactory} from '../../src/scope.js'
chai.use(sinonChai)
const expect = chai.expect
+1 -1
View File
@@ -1,6 +1,6 @@
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import Liquid from '../src/index'
import Liquid from '../../src/index'
chai.use(chaiAsPromised)
const liquid = new Liquid()
+1 -1
View File
@@ -1,7 +1,7 @@
const chai = require('chai')
const expect = chai.expect
const lexical = require('../src/lexical.js')
const lexical = require('../../src/lexical.js')
describe('lexical', function () {
it('should test filter syntax', function () {
@@ -1,6 +1,6 @@
import chai from 'chai'
import mock from 'mock-fs'
import Liquid from '../../src'
import Liquid from '../../../src'
import chaiAsPromised from 'chai-as-promised'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,5 +1,5 @@
import chai from 'chai'
import Liquid from '../../src'
import Liquid from '../../../src'
import chaiAsPromised from 'chai-as-promised'
const expect = chai.expect
+3 -3
View File
@@ -1,8 +1,8 @@
import chai from 'chai'
import sinonChai from 'sinon-chai'
import Filter from '../src/filter.js'
import Tag from '../src/tag.js'
import Template from '../src/parser.js'
import Filter from '../../src/filter.js'
import Tag from '../../src/tag.js'
import Template from '../../src/parser.js'
const expect = chai.expect
const filter = Filter()
+5 -5
View File
@@ -2,11 +2,11 @@ import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import Tag from '../src/tag.js'
import {factory as scopeFactory} from '../src/scope.js'
import Filter from '../src/filter'
import Render from '../src/render.js'
import parser from '../src/parser.js'
import Tag from '../../src/tag.js'
import {factory as scopeFactory} from '../../src/scope.js'
import Filter from '../../src/filter'
import Render from '../../src/render.js'
import parser from '../../src/parser.js'
chai.use(sinonChai)
chai.use(chaiAsPromised)
+1 -1
View File
@@ -1,5 +1,5 @@
import chai from 'chai'
import {factory as scopeFactory} from '../src/scope.js'
import {factory as scopeFactory} from '../../src/scope.js'
const expect = chai.expect
+2 -2
View File
@@ -1,7 +1,7 @@
const chai = require('chai')
const expect = chai.expect
const syntax = require('../src/syntax.js')
const Scope = require('../src/scope.js')
const syntax = require('../../src/syntax.js')
const Scope = require('../../src/scope.js')
const evalExp = syntax.evalExp
const evalValue = syntax.evalValue
+2 -2
View File
@@ -1,6 +1,6 @@
import chai from 'chai'
import Tag from '../src/tag.js'
import {factory as scopeFactory} from '../src/scope.js'
import Tag from '../../src/tag.js'
import {factory as scopeFactory} from '../../src/scope.js'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
import sinonChai from 'chai-as-promised'
@@ -1,4 +1,4 @@
import Liquid from '../../src/index'
import Liquid from '../../../src/index'
import chai from 'chai'
const expect = chai.expect
+1 -1
View File
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
+1 -1
View File
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
+1 -1
View File
@@ -1,4 +1,4 @@
import Liquid from '../../src/index'
import Liquid from '../../../src/index'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import mock from 'mock-fs'
import chai from 'chai'
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import mock from 'mock-fs'
import chai from 'chai'
+1 -1
View File
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import chai from 'chai'
const expect = chai.expect
+1 -1
View File
@@ -1,5 +1,5 @@
const chai = require('chai')
const parse = require('../src/tokenizer.js').parse
const parse = require('../../src/tokenizer.js').parse
const expect = chai.expect
describe('tokenizer', function () {
@@ -1,5 +1,5 @@
import chai from 'chai'
import assert from '../../src/util/assert.js'
import assert from '../../../src/util/assert.js'
const expect = chai.expect
@@ -1,4 +1,4 @@
import Liquid from '../../src'
import Liquid from '../../../src'
import mock from 'mock-fs'
import chai from 'chai'
import path from 'path'
@@ -4,7 +4,7 @@ const expect = chai.expect
chai.use(require('chai-as-promised'))
chai.use(require('sinon-chai'))
const P = require('../../src/util/promise.js')
const P = require('../../../src/util/promise.js')
describe('util/promise', function () {
describe('.anySeries()', function () {
@@ -1,5 +1,5 @@
import chai from 'chai'
import t from '../../src/util/strftime.js'
import t from '../../../src/util/strftime.js'
const expect = chai.expect
@@ -1,8 +1,8 @@
import chai from 'chai'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import {RenderError, RenderBreakError} from '../../src/util/error.js'
import * as _ from '../../src/util/underscore.js'
import {RenderError, RenderBreakError} from '../../../src/util/error.js'
import * as _ from '../../../src/util/underscore.js'
const expect = chai.expect
chai.use(sinonChai)
@@ -93,6 +93,20 @@ describe('util/underscore', function () {
expect(_.range(3)).to.deep.equal([0, 1, 2])
})
})
describe('.isObject()', function () {
it('should return true for function', function () {
expect(_.isObject(x => x)).to.be.true
})
it('should return true for plain object', function () {
expect(_.isObject({})).to.be.true
})
it('should return false for null', function () {
expect(_.isObject(null)).to.be.false
})
it('should return false for number', function () {
expect(_.isObject(2)).to.be.false
})
})
describe('.assign()', function () {
it('should handle null dst', function () {
expect(_.assign(null, {
+1 -1
View File
@@ -1,4 +1,4 @@
import {extname, resolve} from '../../src/util/url.js'
import {extname, resolve} from '../../../src/util/url.js'
import chai from 'chai'
const expect = chai.expect