refactor: es6 building and linting

This commit is contained in:
harttle
2018-08-16 23:14:12 +08:00
parent 5f634b0b5e
commit 19891b2df0
68 changed files with 1636 additions and 1575 deletions
+3 -3
View File
@@ -4,15 +4,15 @@ const assert = require('../../src/util/assert.js')
describe('assert', function () {
it('should not throw if predicate is truthy', function () {
var fn = () => assert('foo', 'bar')
let fn = () => assert('foo', 'bar')
expect(fn).to.not.throw()
})
it('should not throw if predicate is truthy', function () {
var fn = () => assert('', 'bar')
let fn = () => assert('', 'bar')
expect(fn).to.throw(/bar/)
})
it('should populate default message', function () {
var fn = () => assert(false)
let fn = () => assert(false)
expect(fn).to.throw(/expect false to be true/)
})
})
+28 -28
View File
@@ -4,8 +4,8 @@ const mock = require('mock-fs')
const path = require('path')
chai.use(require('chai-as-promised'))
var engine = require('../..')()
var strictEngine = require('../..')({
let engine = require('../..')()
let strictEngine = require('../..')({
strict_variables: true,
strict_filters: true
})
@@ -25,8 +25,8 @@ describe('error', function () {
})
})
it('should contain template content in err.message', function () {
var html = ['1st', '2nd', 'X{% . a %} Y', '4th']
var message = [
let html = ['1st', '2nd', 'X{% . a %} Y', '4th']
let message = [
' 1| 1st',
' 2| 2nd',
'>> 3| X{% . a %} Y',
@@ -42,7 +42,7 @@ describe('error', function () {
})
})
it('should contain the whole template content in err.input', function () {
var html = 'bar\nfoo{% . a %}\nfoo'
let html = 'bar\nfoo{% . a %}\nfoo'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
@@ -66,7 +66,7 @@ describe('error', function () {
})
})
describe('captureStackTrace compatibility', function () {
var captureStackTrace = Error.captureStackTrace
let captureStackTrace = Error.captureStackTrace
before(() => (Error.captureStackTrace = null))
after(() => (Error.captureStackTrace = captureStackTrace))
it('should use empty string if captureStackTrace not defined', function () {
@@ -79,7 +79,7 @@ describe('error', function () {
})
})
it('should contain file path in err.file', function () {
var html = '<html>\n<head>\n\n{% . a %}\n\n'
let html = '<html>\n<head>\n\n{% . a %}\n\n'
mock({
'/foo.html': html
})
@@ -113,7 +113,7 @@ describe('error', function () {
})
})
it('should throw RenderError when tag throws', function () {
var src = '{%throwingTag%}'
let src = '{%throwingTag%}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
@@ -122,7 +122,7 @@ describe('error', function () {
})
})
it('should throw RenderError when tag rejects', function () {
var src = '{%rejectingTag%}'
let src = '{%rejectingTag%}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
@@ -131,7 +131,7 @@ describe('error', function () {
})
})
it('should throw RenderError when filter throws', function () {
var src = '{{1|throwingFilter}}'
let src = '{{1|throwingFilter}}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
@@ -151,8 +151,8 @@ describe('error', function () {
})
})
it('should contain template context in err.stack', function () {
var html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
var message = [
let html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
let message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
@@ -181,8 +181,8 @@ describe('error', function () {
'7th'
].join('\n')
})
var html = '{%layout "throwing-tag.html"%}'
var message = [
let html = '{%layout "throwing-tag.html"%}'
let message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
@@ -202,12 +202,12 @@ describe('error', function () {
})
})
it('should contain original error info for {% include %}', function () {
var origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
let origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
mock({
'/throwing-tag.html': origin.join('\n')
})
var html = '{%include "throwing-tag.html"%}'
var message = [
let html = '{%include "throwing-tag.html"%}'
let message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
@@ -225,7 +225,7 @@ describe('error', function () {
})
})
it('should contain the whole template content in err.input', function () {
var html = 'bar\nfoo{%throwingTag%}\nfoo'
let html = 'bar\nfoo{%throwingTag%}\nfoo'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
@@ -234,7 +234,7 @@ describe('error', function () {
})
})
it('should contain line number in err.line', function () {
var src = '1\n2\n{{1|throwingFilter}}\n4'
let src = '1\n2\n{{1|throwingFilter}}\n4'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
@@ -252,7 +252,7 @@ describe('error', function () {
})
it('should contain file path in err.file', function () {
var html = '<html>\n<head>\n\n{% throwingTag %}\n\n'
let html = '<html>\n<head>\n\n{% throwingTag %}\n\n'
mock({
'/foo.html': html
})
@@ -293,7 +293,7 @@ describe('error', function () {
})
})
it('should throw ParseError when tag parse throws', function () {
var src = '{%throwsOnParse%}'
let src = '{%throwsOnParse%}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
@@ -302,7 +302,7 @@ describe('error', function () {
})
})
it('should throw ParseError when tag not found', function () {
var src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
let src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
@@ -321,8 +321,8 @@ describe('error', function () {
})
it('should contain template context in err.stack', function () {
var html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th']
var message = [
let html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th']
let message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{% a %} {% enda %} Y',
@@ -341,8 +341,8 @@ describe('error', function () {
})
it('should handle err.message when context not enough', function () {
var html = ['1st', 'X{% a %} {% enda %} Y', '3rd', '4th']
var message = [
let html = ['1st', 'X{% a %} {% enda %} Y', '3rd', '4th']
let message = [
' 1| 1st',
'>> 2| X{% a %} {% enda %} Y',
' 3| 3rd',
@@ -358,7 +358,7 @@ describe('error', function () {
})
it('should contain line number in err.line', function () {
var html = '<html>\n<head>\n\n{% raw %}\n\n'
let html = '<html>\n<head>\n\n{% raw %}\n\n'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
@@ -376,7 +376,7 @@ describe('error', function () {
})
it('should contain file path in err.file', function () {
var html = '<html>\n<head>\n\n{% raw %}\n\n'
let html = '<html>\n<head>\n\n{% raw %}\n\n'
mock({
'/foo.html': html
})
+11 -11
View File
@@ -4,13 +4,13 @@ const expect = chai.expect
chai.use(require('chai-as-promised'))
chai.use(require('sinon-chai'))
var P = require('../../src/util/promise.js')
let P = require('../../src/util/promise.js')
describe('util/promise', function () {
describe('.anySeries()', function () {
it('should resolve in series', function () {
var spy1 = sinon.spy()
var spy2 = sinon.spy()
let spy1 = sinon.spy()
let spy2 = sinon.spy()
return P
.anySeries(
['first', 'second'],
@@ -28,17 +28,17 @@ describe('util/promise', function () {
.then(() => expect(spy2).to.have.been.calledAfter(spy1))
})
it('should reject when all rejected', function () {
var p = P.anySeries(['first', 'second', 'third'],
let p = P.anySeries(['first', 'second', 'third'],
item => Promise.reject(new Error(item)))
return expect(p).to.be.rejectedWith('third')
})
it('should resolve the value that first callback resolved', () => {
var p = P.anySeries(['first', 'second'],
let p = P.anySeries(['first', 'second'],
item => Promise.resolve(item))
return expect(p).to.eventually.equal('first')
})
it('should not call rest of callbacks once resolved', () => {
var spy = sinon.spy()
let spy = sinon.spy()
return P
.anySeries(['first', 'second'], (item, idx) => {
if (idx > 0) {
@@ -51,18 +51,18 @@ describe('util/promise', function () {
})
describe('.mapSeries()', function () {
it('should resolve when all resolved', function () {
var p = P.mapSeries(['first', 'second', 'third'],
let p = P.mapSeries(['first', 'second', 'third'],
item => Promise.resolve(item))
return expect(p).to.eventually.deep.equal(['first', 'second', 'third'])
})
it('should reject with the error that first callback rejected', () => {
var p = P.mapSeries(['first', 'second'],
let p = P.mapSeries(['first', 'second'],
item => Promise.reject(item))
return expect(p).to.rejectedWith('first')
})
it('should resolve in series', function () {
var spy1 = sinon.spy()
var spy2 = sinon.spy()
let spy1 = sinon.spy()
let spy2 = sinon.spy()
return P
.mapSeries(
['first', 'second'],
@@ -80,7 +80,7 @@ describe('util/promise', function () {
.then(() => expect(spy2).to.have.been.calledAfter(spy1))
})
it('should not call rest of callbacks once rejected', () => {
var spy = sinon.spy()
let spy = sinon.spy()
return P
.mapSeries(['first', 'second'], (item, idx) => {
if (idx > 0) {
+13 -13
View File
@@ -1,11 +1,11 @@
const chai = require('chai')
const expect = chai.expect
var t = require('../../src/util/strftime.js')
let t = require('../../src/util/strftime.js')
describe('util/strftime', function () {
var now
var then
let now
let then
before(function () {
mockUTC()
now = new Date('2016-01-04T13:15:23.000Z')
@@ -37,7 +37,7 @@ describe('util/strftime', function () {
expect(t(now, '%I')).to.equal('01')
})
it('should format %I as 12 for 00:00', function () {
var date = new Date('2016-01-01T00:00:00.000Z')
let date = new Date('2016-01-01T00:00:00.000Z')
expect(t(date, '%I')).to.equal('12')
})
describe('%j', function () {
@@ -45,11 +45,11 @@ describe('util/strftime', function () {
expect(t(then, '%j')).to.equal('066')
})
it('should take count of leap years', function () {
var date = new Date('2001-03-01')
let date = new Date('2001-03-01')
expect(t(date, '%j')).to.equal('060')
})
it('should take count of leap years', function () {
var date = new Date('2000-03-01')
let date = new Date('2000-03-01')
expect(t(date, '%j')).to.equal('061')
})
})
@@ -60,7 +60,7 @@ describe('util/strftime', function () {
expect(t(now, '%l')).to.equal(' 1')
})
it('should format %l as 12 for 00:00', function () {
var date = new Date('2016-01-01T00:00:00.000Z')
let date = new Date('2016-01-01T00:00:00.000Z')
expect(t(date, '%l')).to.equal('12')
})
it('should format %L as 0 padded millisecond', function () {
@@ -75,9 +75,9 @@ describe('util/strftime', function () {
expect(t(then, '%P')).to.equal('am')
})
it('should format %q as date suffix', function () {
var st = new Date('2016-03-01T03:05:03.000Z')
var nd = new Date('2016-03-02T03:05:03.000Z')
var rd = new Date('2016-03-03T03:05:03.000Z')
let st = new Date('2016-03-01T03:05:03.000Z')
let nd = new Date('2016-03-02T03:05:03.000Z')
let rd = new Date('2016-03-03T03:05:03.000Z')
expect(t(st, '%q')).to.equal('st')
expect(t(nd, '%q')).to.equal('nd')
expect(t(rd, '%q')).to.equal('rd')
@@ -113,7 +113,7 @@ describe('util/strftime', function () {
expect(t(now, '%z')).to.equal('+0800')
})
it('should format %z as negative time zone', function () {
var date = new Date('2016-01-04T13:15:23.000Z')
let date = new Date('2016-01-04T13:15:23.000Z')
date.getTimezoneOffset = () => 480
expect(t(date, '%z')).to.equal('-0800')
})
@@ -126,7 +126,7 @@ describe('util/strftime', function () {
})
function mockUTC () {
var p = Date.prototype
let p = Date.prototype
p._getHours = p.getHours
p.getHours = p.getUTCHours
@@ -139,7 +139,7 @@ function mockUTC () {
}
function restoreUTC () {
var p = Date.prototype
let p = Date.prototype
p.getHours = p._getHours
p.getDays = p._getDays
p.getTimezoneOffset = p._getTimezoneOffset
+15 -15
View File
@@ -1,10 +1,10 @@
const chai = require('chai')
const sinon = require('sinon')
const expect = chai.expect
const Errors = require('../../src/util/error.js')
chai.use(require('sinon-chai'))
import chai from 'chai'
import sinon from 'sinon'
import Errors from '../../src/util/error.js'
import _ from '../../src/util/underscore.js'
var _ = require('../../src/util/underscore.js')
const expect = chai.expect
chai.use(require('sinon-chai'))
describe('util/underscore', function () {
describe('.isError()', function () {
@@ -12,7 +12,7 @@ describe('util/underscore', function () {
expect(_.isError(new Error())).to.be.true
})
it('should return true for RenderError', function () {
var tpl = {
let tpl = {
token: {
input: 'xx'
}
@@ -53,21 +53,21 @@ describe('util/underscore', function () {
})
describe('.forOwn()', function () {
it('should iterate all properties', function () {
var spy = sinon.spy()
var obj = {
let spy = sinon.spy()
let obj = {
foo: 'bar'
}
_.forOwn(obj, spy)
expect(spy).to.have.been.calledWith('bar', 'foo', obj)
})
it('should default to empty object', function () {
var spy = sinon.spy()
let spy = sinon.spy()
_.forOwn(undefined, spy)
expect(spy).to.have.not.been.called
})
it('should not iterate over properties on prototype', function () {
var spy = sinon.spy()
var obj = Object.create({
let spy = sinon.spy()
let obj = Object.create({
bar: 'foo'
})
obj.foo = 'bar'
@@ -76,7 +76,7 @@ describe('util/underscore', function () {
expect(spy).to.have.been.calledWith('bar', 'foo', obj)
})
it('should break when returned false', function () {
var spy = sinon.stub().returns(false)
let spy = sinon.stub().returns(false)
_.forOwn({
'foo': 'foo',
'bar': 'foo'
@@ -101,11 +101,11 @@ describe('util/underscore', function () {
})
})
it('should assign 2 objects', function () {
var src = {
let src = {
foo: 'foo',
bar: 'bar'
}
var dst = {
let dst = {
foo: 'bar',
kaa: 'kaa'
}
+1 -1
View File
@@ -7,7 +7,7 @@ describe('util/url', function () {
return
}
const JSDOM = require('jsdom').JSDOM
var dom
let dom
beforeEach(function () {
dom = new JSDOM(``, {
url: 'https://example.com/foo/bar/',