refactor: import rollup

This commit is contained in:
harttle
2018-08-20 23:58:41 +08:00
parent 4ece4e208f
commit bc9d8f92af
82 changed files with 8589 additions and 3963 deletions
+6 -5
View File
@@ -1,18 +1,19 @@
const chai = require('chai')
import chai from 'chai'
import assert from '../../src/util/assert.js'
const expect = chai.expect
const assert = require('../../src/util/assert.js')
describe('assert', function () {
it('should not throw if predicate is truthy', function () {
let fn = () => assert('foo', 'bar')
const fn = () => assert('foo', 'bar')
expect(fn).to.not.throw()
})
it('should not throw if predicate is truthy', function () {
let fn = () => assert('', 'bar')
const fn = () => assert('', 'bar')
expect(fn).to.throw(/bar/)
})
it('should populate default message', function () {
let fn = () => assert(false)
const fn = () => assert(false)
expect(fn).to.throw(/expect false to be true/)
})
})
+150 -236
View File
@@ -7,7 +7,7 @@ const expect = chai.expect
chai.use(require('chai-as-promised'))
let engine = Liquid()
let strictEngine = Liquid({
const strictEngine = Liquid({
strict_variables: true,
strict_filters: true
})
@@ -18,80 +18,59 @@ describe('error', function () {
})
describe('TokenizationError', function () {
it('should throw TokenizationError when tag illegal', function () {
return expect(engine.parseAndRender('{% . a %}', {})).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('TokenizationError')
expect(err.message).to.contain('illegal tag syntax')
})
it('should throw TokenizationError when tag illegal', async function () {
const err = await expect(engine.parseAndRender('{% . a %}', {})).be.rejected
expect(err.name).to.equal('TokenizationError')
expect(err.message).to.contain('illegal tag syntax')
})
it('should contain template content in err.message', function () {
let html = ['1st', '2nd', 'X{% . a %} Y', '4th']
let message = [
it('should contain template content in err.message', async function () {
const html = ['1st', '2nd', 'X{% . a %} Y', '4th']
const message = [
' 1| 1st',
' 2| 2nd',
'>> 3| X{% . a %} Y',
' 4| 4th',
'TokenizationError'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.equal('illegal tag syntax, line:3')
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('TokenizationError')
})
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
expect(err.message).to.equal('illegal tag syntax, line:3')
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('TokenizationError')
})
it('should contain the whole template content in err.input', function () {
let html = 'bar\nfoo{% . a %}\nfoo'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
expect(err.input).to.equal(html)
})
it('should contain the whole template content in err.input', async function () {
const html = 'bar\nfoo{% . a %}\nfoo'
const err = await expect(engine.parseAndRender(html)).be.rejected
expect(err.input).to.equal(html)
})
it('should contain line number in err.line', function () {
return expect(engine.parseAndRender('1\n2\n{% . a %}\n4', {})).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('TokenizationError')
expect(err.line).to.equal(3)
})
it('should contain line number in err.line', async function () {
const err = await expect(engine.parseAndRender('1\n2\n{% . a %}\n4')).be.rejected
expect(err.name).to.equal('TokenizationError')
expect(err.line).to.equal(3)
})
it('should contain stack in err.stack', function () {
return expect(engine.parseAndRender('{% . a %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.contain('illegal tag syntax')
expect(err.stack).to.contain('at Object.parse')
})
it('should contain stack in err.stack', async function () {
const err = await expect(engine.parseAndRender('{% . a %}')).be.rejected
expect(err.message).to.contain('illegal tag syntax')
expect(err.stack).to.contain('at Object.parse')
})
describe('captureStackTrace compatibility', function () {
let captureStackTrace = Error.captureStackTrace
const captureStackTrace = Error.captureStackTrace
before(() => (Error.captureStackTrace = null))
after(() => (Error.captureStackTrace = captureStackTrace))
it('should use empty string if captureStackTrace not defined', function () {
return expect(engine.parseAndRender('{% . a %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.stack).to.contain('illegal tag syntax')
expect(err.stack).to.not.contain('at Object.parse')
})
it('should be empty when captureStackTrace undefined', async function () {
const err = await expect(engine.parseAndRender('{% . a %}')).be.rejected
expect(err.stack).to.contain('illegal tag syntax')
expect(err.stack).to.not.contain('at Object.parse')
})
})
it('should contain file path in err.file', function () {
let html = '<html>\n<head>\n\n{% . a %}\n\n'
it('should contain file path in err.file', async function () {
const html = '<html>\n<head>\n\n{% . a %}\n\n'
mock({
'/foo.html': html
})
return expect(engine.renderFile('/foo.html')).to.eventually
.be.rejected
.then(function (err) {
mock.restore()
expect(err.name).to.equal('TokenizationError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
const err = await expect(engine.renderFile('/foo.html')).be.rejected
mock.restore()
expect(err.name).to.equal('TokenizationError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
})
@@ -106,55 +85,43 @@ describe('error', function () {
}
})
engine.registerTag('rejectingTag', {
render: function () {
return Promise.reject(new Error('intended render reject'))
render: async function () {
throw new Error('intended render reject')
}
})
engine.registerFilter('throwingFilter', () => {
throw new Error('throwed by filter')
})
})
it('should throw RenderError when tag throws', function () {
let src = '{%throwingTag%}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('RenderError')
expect(err.message).to.contain('intended render error')
})
it('should throw RenderError when tag throws', async function () {
const src = '{%throwingTag%}'
const err = await expect(engine.parseAndRender(src)).be.rejected
expect(err.name).to.equal('RenderError')
expect(err.message).to.contain('intended render error')
})
it('should throw RenderError when tag rejects', function () {
let src = '{%rejectingTag%}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('RenderError')
expect(err.message).to.contain('intended render reject')
})
it('should throw RenderError when tag rejects', async function () {
const src = '{%rejectingTag%}'
const err = await expect(engine.parseAndRender(src)).be.rejected
expect(err.name).to.equal('RenderError')
expect(err.message).to.contain('intended render reject')
})
it('should throw RenderError when filter throws', function () {
let src = '{{1|throwingFilter}}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('RenderError')
expect(err.message).to.contain('throwed by filter')
})
it('should throw RenderError when filter throws', async function () {
const src = '{{1|throwingFilter}}'
const err = await expect(engine.parseAndRender(src)).be.rejected
expect(err.name).to.equal('RenderError')
expect(err.message).to.contain('throwed by filter')
})
it('should not throw when variable undefined by default', function () {
return expect(engine.parseAndRender('X{{a}}Y')).to.eventually.equal('XY')
})
it('should throw RenderError when variable not defined', function () {
return expect(strictEngine.parseAndRender('{{a}}')).to.eventually
.be.rejected
.then(function (e) {
expect(e).to.have.property('name', 'RenderError')
expect(e.message).to.contain('undefined variable: a')
})
it('should throw RenderError when variable not defined', async function () {
const err = await expect(strictEngine.parseAndRender('{{a}}')).be.rejected
expect(err).to.have.property('name', 'RenderError')
expect(err.message).to.contain('undefined variable: a')
})
it('should contain template context in err.stack', function () {
let html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
let message = [
it('should contain template context in err.stack', async function () {
const html = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
const message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
@@ -163,15 +130,12 @@ describe('error', function () {
' 7| 7th',
'RenderError'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.equal('intended render error, line:4')
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('RenderError')
})
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
expect(err.message).to.equal('intended render error, line:4')
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('RenderError')
})
it('should contain original error info for {% layout %}', function () {
it('should contain original error info for {% layout %}', async function () {
mock({
'/throwing-tag.html': [
'1st',
@@ -183,8 +147,8 @@ describe('error', function () {
'7th'
].join('\n')
})
let html = '{%layout "throwing-tag.html"%}'
let message = [
const html = '{%layout "throwing-tag.html"%}'
const message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
@@ -193,23 +157,20 @@ describe('error', function () {
' 7| 7th',
'RenderError'
]
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
console.log(err.message)
console.log(err.stack)
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4`)
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('RenderError')
})
const err = await expect(engine.parseAndRender(html)).be.rejected
console.log(err.message)
console.log(err.stack)
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4`)
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('RenderError')
})
it('should contain original error info for {% include %}', function () {
let origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
it('should contain original error info for {% include %}', async function () {
const origin = ['1st', '2nd', '3rd', 'X{%throwingTag%} Y', '5th', '6th', '7th']
mock({
'/throwing-tag.html': origin.join('\n')
})
let html = '{%include "throwing-tag.html"%}'
let message = [
const html = '{%include "throwing-tag.html"%}'
const message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{%throwingTag%} Y',
@@ -218,54 +179,39 @@ describe('error', function () {
' 7| 7th',
'RenderError'
]
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4`)
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('RenderError')
})
const err = await expect(engine.parseAndRender(html)).be.rejected
expect(err.message).to.equal(`intended render error, file:${path.resolve('/throwing-tag.html')}, line:4`)
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('RenderError')
})
it('should contain the whole template content in err.input', function () {
let html = 'bar\nfoo{%throwingTag%}\nfoo'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
expect(err.input).to.equal(html)
expect(err.name).to.equal('RenderError')
})
it('should contain the whole template content in err.input', async function () {
const html = 'bar\nfoo{%throwingTag%}\nfoo'
const err = await expect(engine.parseAndRender(html)).be.rejected
expect(err.input).to.equal(html)
expect(err.name).to.equal('RenderError')
})
it('should contain line number in err.line', function () {
let src = '1\n2\n{{1|throwingFilter}}\n4'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
expect(err.line).to.equal(3)
expect(err.name).to.equal('RenderError')
})
it('should contain line number in err.line', async function () {
const src = '1\n2\n{{1|throwingFilter}}\n4'
const err = await expect(engine.parseAndRender(src)).be.rejected
expect(err.line).to.equal(3)
expect(err.name).to.equal('RenderError')
})
it('should contain stack in err.stack', function () {
return expect(engine.parseAndRender('{%rejectingTag%}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.contain('intended render reject')
expect(err.stack).to.match(/at .*:\d+:\d+/)
})
it('should contain stack in err.stack', async function () {
const err = await expect(engine.parseAndRender('{%rejectingTag%}')).be.rejected
expect(err.message).to.contain('intended render reject')
expect(err.stack).to.match(/at .*:\d+:\d+/)
})
it('should contain file path in err.file', function () {
let html = '<html>\n<head>\n\n{% throwingTag %}\n\n'
it('should contain file path in err.file', async function () {
const html = '<html>\n<head>\n\n{% throwingTag %}\n\n'
mock({
'/foo.html': html
})
return expect(engine.renderFile('/foo.html')).to.eventually
.be.rejected
.then(function (err) {
mock.restore()
console.log(err, err.name)
expect(err.name).to.equal('RenderError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
const err = await expect(engine.renderFile('/foo.html')).be.rejected
mock.restore()
console.log(err, err.name)
expect(err.name).to.equal('RenderError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
})
@@ -278,53 +224,36 @@ describe('error', function () {
}
})
})
it('should throw RenderError when filter not defined', function () {
return expect(strictEngine.parseAndRender('{{1 | a}}')).to.eventually
.be.rejected
.then(function (e) {
expect(e).to.have.property('name', 'ParseError')
expect(e.message).to.contain('undefined filter: a')
})
it('should throw RenderError when filter not defined', async function () {
const err = await expect(strictEngine.parseAndRender('{{1 | a}}')).be.rejected
expect(err).to.have.property('name', 'ParseError')
expect(err.message).to.contain('undefined filter: a')
})
it('should throw ParseError when tag not closed', function () {
return expect(engine.parseAndRender('{% if %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('tag {% if %} not closed')
})
it('should throw ParseError when tag not closed', async function () {
const err = await expect(engine.parseAndRender('{% if %}')).be.rejected
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('tag {% if %} not closed')
})
it('should throw ParseError when tag parse throws', function () {
let src = '{%throwsOnParse%}'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('intended parse error')
})
it('should throw ParseError when tag parse throws', async function () {
const err = await expect(engine.parseAndRender('{%throwsOnParse%}')).be.rejected
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('intended parse error')
})
it('should throw ParseError when tag not found', function () {
let src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
return expect(engine.parseAndRender(src)).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('tag -a not found')
})
it('should throw ParseError when tag not found', async function () {
const src = '{%if true%}\naaa{%endif%}\n{% -a %}\n3'
const err = await expect(engine.parseAndRender(src)).be.rejected
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('tag -a not found')
})
it('should throw ParseError when tag not exist', async function () {
const err = await expect(engine.parseAndRender('{% a %}')).be.rejected
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('tag a not found')
})
it('should throw ParseError when tag not exist', function () {
return expect(engine.parseAndRender('{% a %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.name).to.equal('ParseError')
expect(err.message).to.contain('tag a not found')
})
})
it('should contain template context in err.stack', function () {
let html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th']
let message = [
it('should contain template context in err.stack', async function () {
const html = ['1st', '2nd', '3rd', 'X{% a %} {% enda %} Y', '5th', '6th', '7th']
const message = [
' 2| 2nd',
' 3| 3rd',
'>> 4| X{% a %} {% enda %} Y',
@@ -333,62 +262,47 @@ describe('error', function () {
' 7| 7th',
'ParseError: tag a not found'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.equal('tag a not found, line:4')
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('ParseError')
})
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
expect(err.message).to.equal('tag a not found, line:4')
expect(err.stack).to.contain(message.join('\n'))
expect(err.name).to.equal('ParseError')
})
it('should handle err.message when context not enough', function () {
let html = ['1st', 'X{% a %} {% enda %} Y', '3rd', '4th']
let message = [
it('should handle err.message when context not enough', async function () {
const html = ['1st', 'X{% a %} {% enda %} Y', '3rd', '4th']
const message = [
' 1| 1st',
'>> 2| X{% a %} {% enda %} Y',
' 3| 3rd',
' 4| 4th',
'ParseError: tag a not found'
]
return expect(engine.parseAndRender(html.join('\n'))).to.eventually
.be.rejected
.then(function (err) {
expect(err.message).to.equal('tag a not found, line:2')
expect(err.stack).to.contain(message.join('\n'))
})
const err = await expect(engine.parseAndRender(html.join('\n'))).be.rejected
expect(err.message).to.equal('tag a not found, line:2')
expect(err.stack).to.contain(message.join('\n'))
})
it('should contain line number in err.line', function () {
let html = '<html>\n<head>\n\n{% raw %}\n\n'
return expect(engine.parseAndRender(html)).to.eventually
.be.rejected
.then(function (err) {
expect(err.line).to.equal(4)
})
it('should contain line number in err.line', async function () {
const html = '<html>\n<head>\n\n{% raw %}\n\n'
const err = await expect(engine.parseAndRender(html)).be.rejected
expect(err.line).to.equal(4)
})
it('should contain stack in err.stack', function () {
return expect(engine.parseAndRender('{% -a %}')).to.eventually
.be.rejected
.then(function (err) {
expect(err.stack).to.contain('ParseError: tag -a not found')
expect(err.stack).to.match(/at .*:\d+:\d+\)/)
})
it('should contain stack in err.stack', async function () {
const err = await expect(engine.parseAndRender('{% -a %}')).be.rejected
expect(err.stack).to.contain('ParseError: tag -a not found')
expect(err.stack).to.match(/at .*:\d+:\d+\)/)
})
it('should contain file path in err.file', function () {
let html = '<html>\n<head>\n\n{% raw %}\n\n'
it('should contain file path in err.file', async function () {
const html = '<html>\n<head>\n\n{% raw %}\n\n'
mock({
'/foo.html': html
})
return expect(engine.renderFile('/foo.html')).to.eventually
.be.rejected
.then(function (err) {
mock.restore()
expect(err.name).to.equal('ParseError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
const err = await expect(engine.renderFile('/foo.html')).be.rejected
mock.restore()
expect(err.name).to.equal('ParseError')
expect(err.file).to.equal(path.resolve('/foo.html'))
})
})
})
+11 -11
View File
@@ -4,13 +4,13 @@ const expect = chai.expect
chai.use(require('chai-as-promised'))
chai.use(require('sinon-chai'))
let P = require('../../src/util/promise.js')
const P = require('../../src/util/promise.js')
describe('util/promise', function () {
describe('.anySeries()', function () {
it('should resolve in series', function () {
let spy1 = sinon.spy()
let spy2 = sinon.spy()
const spy1 = sinon.spy()
const 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 () {
let p = P.anySeries(['first', 'second', 'third'],
const 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', () => {
let p = P.anySeries(['first', 'second'],
const 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', () => {
let spy = sinon.spy()
const 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 () {
let p = P.mapSeries(['first', 'second', 'third'],
const 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', () => {
let p = P.mapSeries(['first', 'second'],
const p = P.mapSeries(['first', 'second'],
item => Promise.reject(item))
return expect(p).to.rejectedWith('first')
})
it('should resolve in series', function () {
let spy1 = sinon.spy()
let spy2 = sinon.spy()
const spy1 = sinon.spy()
const 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', () => {
let spy = sinon.spy()
const spy = sinon.spy()
return P
.mapSeries(['first', 'second'], (item, idx) => {
if (idx > 0) {
+13 -13
View File
@@ -1,7 +1,7 @@
const chai = require('chai')
const expect = chai.expect
import chai from 'chai'
import t from '../../src/util/strftime.js'
let t = require('../../src/util/strftime.js')
const expect = chai.expect
describe('util/strftime', function () {
let now
@@ -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 () {
let date = new Date('2016-01-01T00:00:00.000Z')
const 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 () {
let date = new Date('2001-03-01')
const date = new Date('2001-03-01')
expect(t(date, '%j')).to.equal('060')
})
it('should take count of leap years', function () {
let date = new Date('2000-03-01')
const 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 () {
let date = new Date('2016-01-01T00:00:00.000Z')
const 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 () {
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')
const st = new Date('2016-03-01T03:05:03.000Z')
const nd = new Date('2016-03-02T03:05:03.000Z')
const 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 () {
let date = new Date('2016-01-04T13:15:23.000Z')
const 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 () {
let p = Date.prototype
const p = Date.prototype
p._getHours = p.getHours
p.getHours = p.getUTCHours
@@ -139,7 +139,7 @@ function mockUTC () {
}
function restoreUTC () {
let p = Date.prototype
const p = Date.prototype
p.getHours = p._getHours
p.getDays = p._getDays
p.getTimezoneOffset = p._getTimezoneOffset
+12 -11
View File
@@ -1,10 +1,11 @@
import chai from 'chai'
import sinonChai from 'sinon-chai'
import sinon from 'sinon'
import {RenderError, RenderBreakError} from '../../src/util/error.js'
import _ from '../../src/util/underscore.js'
import * as _ from '../../src/util/underscore.js'
const expect = chai.expect
chai.use(require('sinon-chai'))
chai.use(sinonChai)
describe('util/underscore', function () {
describe('.isError()', function () {
@@ -12,7 +13,7 @@ describe('util/underscore', function () {
expect(_.isError(new Error())).to.be.true
})
it('should return true for RenderError', function () {
let tpl = {
const tpl = {
token: {
input: 'xx'
}
@@ -53,21 +54,21 @@ describe('util/underscore', function () {
})
describe('.forOwn()', function () {
it('should iterate all properties', function () {
let spy = sinon.spy()
let obj = {
const spy = sinon.spy()
const obj = {
foo: 'bar'
}
_.forOwn(obj, spy)
expect(spy).to.have.been.calledWith('bar', 'foo', obj)
})
it('should default to empty object', function () {
let spy = sinon.spy()
const spy = sinon.spy()
_.forOwn(undefined, spy)
expect(spy).to.have.not.been.called
})
it('should not iterate over properties on prototype', function () {
let spy = sinon.spy()
let obj = Object.create({
const spy = sinon.spy()
const obj = Object.create({
bar: 'foo'
})
obj.foo = 'bar'
@@ -76,7 +77,7 @@ describe('util/underscore', function () {
expect(spy).to.have.been.calledWith('bar', 'foo', obj)
})
it('should break when returned false', function () {
let spy = sinon.stub().returns(false)
const spy = sinon.stub().returns(false)
_.forOwn({
'foo': 'foo',
'bar': 'foo'
@@ -101,11 +102,11 @@ describe('util/underscore', function () {
})
})
it('should assign 2 objects', function () {
let src = {
const src = {
foo: 'foo',
bar: 'bar'
}
let dst = {
const dst = {
foo: 'bar',
kaa: 'kaa'
}
+10 -12
View File
@@ -1,4 +1,4 @@
import {resolve} from '../../src/util/url.js'
import {extname, resolve} from '../../src/util/url.js'
import chai from 'chai'
const expect = chai.expect
@@ -22,23 +22,23 @@ describe('util/url', function () {
})
describe('resolve', function () {
describe('root', function () {
it('should support width relative path', function () {
it('should support relative root', function () {
expect(resolve('./views', 'foo'))
.to.equal('https://example.com/foo/bar/views/foo')
expect(resolve('./views/', 'foo'))
.to.equal('https://example.com/foo/bar/views/foo')
})
it('should support width absolute path', function () {
it('should support absolute root', function () {
expect(resolve('/views', 'foo'))
.to.equal('https://example.com/views/foo')
expect(resolve('/views/', 'foo'))
.to.equal('https://example.com/views/foo')
})
it('should support with empty', function () {
it('should support empty root', function () {
expect(resolve('', 'page.html'))
.to.equal('https://example.com/foo/bar/page.html')
})
it('should support with url', function () {
it('should support full url as root', function () {
expect(resolve('https://example.com/views', 'page.html'))
.to.equal('https://example.com/views/page.html')
expect(resolve('https://example.com/views/', 'page.html'))
@@ -51,14 +51,12 @@ describe('util/url', function () {
.to.equal('https://example.com/views/page.html')
})
})
describe('path', function () {
it('should support width relative path', function () {
expect(resolve('./views/', 'page.html'))
.to.equal('https://example.com/foo/bar/views/page.html')
describe('extname', function () {
it('should support relative path', function () {
expect(extname('./views/page.html')).to.equal('.html')
})
it('should support with absolute path', function () {
expect(resolve('/views/', '/page.html'))
.to.equal('https://example.com/page.html')
it('should support absolute path', function () {
expect(extname('/views/page.xml')).to.equal('.xml')
})
})
})