chore(TypeScript): fix linting and generate .d.ts

This commit is contained in:
harttle
2019-02-17 18:20:04 +08:00
parent 7ee87008c7
commit fc9ebdb90f
79 changed files with 809 additions and 820 deletions
+38 -42
View File
@@ -1,11 +1,10 @@
import Liquid from '../../dist/liquid.js'
import { createFakeServer, useFakeXMLHttpRequest } from 'sinon'
import * as chai from 'chai'
import * as chaiAsPromised from 'chai-as-promised'
import { expect, use } from 'chai'
import { JSDOM } from 'jsdom'
import * as chaiAsPromised from 'chai-as-promised'
const expect = chai.expect
chai.use(chaiAsPromised)
use(chaiAsPromised)
describe('xhr', () => {
if (+process.version.match(/^v(\d+)/)[1] < 8) {
@@ -24,7 +23,7 @@ describe('xhr', () => {
includeNodeLocations: true
});
(global as any).XMLHttpRequest = useFakeXMLHttpRequest();
(global as any).document = dom.window.document;
(global as any).document = dom.window.document
engine = new Liquid({
root: 'https://example.com/views/',
extname: '.html'
@@ -36,97 +35,94 @@ describe('xhr', () => {
delete (global as any).document
})
describe('#renderFile()', () => {
it('should support without extname', () => {
return expect(engine.renderFile('hello', { name: 'alice1' }))
.to.eventually.equal('hello alice1')
it('should support without extname', async () => {
const html = await engine.renderFile('hello', { name: 'alice1' })
return expect(html).to.equal('hello alice1')
})
it('should support with extname', () => {
return expect(engine.renderFile('hello.html', { name: 'alice2' }))
.to.eventually.equal('hello alice2')
it('should support with extname', async () => {
const html = await engine.renderFile('hello.html', { name: 'alice2' })
return expect(html).to.equal('hello alice2')
})
it('should support with absolute path', () => {
it('should support with absolute path', async () => {
server.respondWith('GET', 'https://example.com/foo.html',
[200, { 'Content-Type': 'text/plain' }, 'foo'])
return expect(engine.renderFile('/foo.html'))
.to.eventually.equal('foo')
const html = await engine.renderFile('/foo.html')
return expect(html).to.equal('foo')
})
it('should support with url', () => {
return expect(engine.renderFile('https://example.com/views/hello.html', { name: 'alice4' }))
.to.eventually.equal('hello alice4')
it('should support with url', async () => {
const html = await engine.renderFile('https://example.com/views/hello.html', { name: 'alice4' })
return expect(html).to.equal('hello alice4')
})
it('should support include', () => {
it('should support include', async () => {
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, { 'Content-Type': 'text/plain' }, "hello {% include 'name.html' %}"])
server.respondWith('GET', 'https://example.com/views/name.html',
[200, { 'Content-Type': 'text/plain' }, '{{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
const html = await engine.renderFile('hello.html', { name: 'alice5' })
return expect(html).to.equal('hello alice5')
})
it('should throw 404', () => {
return expect(engine.renderFile('/not/exist.html'))
.to.be.rejectedWith('Not Found')
})
it('should throw error', function (done) {
engine.renderFile('hello.html')
.then(() => done('should not be resolved'))
.catch(function (e) {
expect(e.message).to.equal('An error occurred whilst receiving the response.')
done()
});
it('should throw error', function () {
const result = expect(engine.renderFile('hello.html'))
.to.be.rejectedWith('An error occurred whilst receiving the response.');
(global as any).XMLHttpRequest.onCreate = function (request) {
setTimeout(() => request.error())
}
return result
})
})
describe('#renderFile() with root specified', () => {
it('should support undefined root', () => {
it('should support undefined root', async () => {
engine = new Liquid({
extname: '.html'
})
server.respondWith('GET', 'https://example.com/foo/hello.html',
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
const html = await engine.renderFile('hello.html', { name: 'alice5' })
return expect(html).to.equal('hello alice5')
})
it('should support empty root', () => {
it('should support empty root', async () => {
engine = new Liquid({
root: '',
extname: '.html'
})
server.respondWith('https://example.com/foo/hello.html',
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
const html = await engine.renderFile('hello.html', { name: 'alice5' })
return expect(html).to.equal('hello alice5')
})
it('should support with relative path', () => {
it('should support with relative path', async () => {
engine = new Liquid({
root: './views/',
extname: '.html'
})
server.respondWith('GET', 'https://example.com/foo/views/hello.html',
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
const html = await engine.renderFile('hello.html', { name: 'alice5' })
return expect(html).to.equal('hello alice5')
})
it('should support with absolute path', () => {
it('should support with absolute path', async () => {
engine = new Liquid({
root: '/views/',
extname: '.html'
})
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
const html = await engine.renderFile('hello.html', { name: 'alice5' })
return expect(html).to.equal('hello alice5')
})
it('should support with url', () => {
it('should support with url', async () => {
engine = new Liquid({
root: 'https://foo.com/bar/',
extname: '.html'
})
server.respondWith('GET', 'https://foo.com/bar/hello.html',
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
const html = await engine.renderFile('hello.html', { name: 'alice5' })
return expect(html).to.equal('hello alice5')
})
})
describe('cache options', () => {