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
+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