mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
refactor: bundle template.js respectively
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ const chai = require('chai')
|
||||
const request = require('supertest')
|
||||
const express = require('express')
|
||||
const mock = require('mock-fs')
|
||||
const Liquid = require('../..')
|
||||
const Liquid = require('../../dist/liquid.common.js')
|
||||
const chaiAsPromised = require('chai-as-promised')
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
+13
-9
@@ -1,4 +1,4 @@
|
||||
var Liquid = require('../..')
|
||||
var Liquid = require('../../dist/liquid.js')
|
||||
var sinon = require('sinon')
|
||||
var chai = require('chai')
|
||||
var expect = chai.expect
|
||||
@@ -6,16 +6,17 @@ chai.use(require('chai-as-promised'))
|
||||
|
||||
describe('xhr', () => {
|
||||
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
||||
console.info('jsdom not supported, skipping xhr...')
|
||||
return
|
||||
}
|
||||
var JSDOM = require('jsdom').JSDOM
|
||||
var server, engine, dom
|
||||
var server, engine
|
||||
beforeEach(() => {
|
||||
server = sinon.createFakeServer()
|
||||
server.autoRespond = true
|
||||
server.respondWith('GET', 'https://example.com/views/hello.html',
|
||||
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
|
||||
dom = new JSDOM('', {
|
||||
var dom = new JSDOM('', {
|
||||
url: 'https://example.com/foo/bar.html',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true
|
||||
@@ -65,15 +66,18 @@ describe('xhr', () => {
|
||||
})
|
||||
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 sending the response.')
|
||||
expect(e.message).to.equal('An error occurred whilst receiving the response.')
|
||||
done()
|
||||
})
|
||||
server.requests[0].error()
|
||||
global.XMLHttpRequest.onCreate = function (request) {
|
||||
setTimeout(() => request.error())
|
||||
}
|
||||
})
|
||||
})
|
||||
describe('root', () => {
|
||||
it('should support with null', () => {
|
||||
describe('#renderFile() with root specified', () => {
|
||||
it('should support undefined root', () => {
|
||||
engine = Liquid({
|
||||
extname: '.html'
|
||||
})
|
||||
@@ -82,12 +86,12 @@ describe('xhr', () => {
|
||||
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
|
||||
.to.eventually.equal('hello alice5')
|
||||
})
|
||||
it('should support with empty', () => {
|
||||
it('should support empty root', () => {
|
||||
engine = Liquid({
|
||||
root: '',
|
||||
extname: '.html'
|
||||
})
|
||||
server.respondWith('GET', 'https://example.com/foo/hello.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')
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import {resolve} from '../../src/template-browser.js'
|
||||
import chai from 'chai'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('template-browser', function () {
|
||||
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
||||
console.info('jsdom not supported, skipping template-browser...')
|
||||
return
|
||||
}
|
||||
const JSDOM = require('jsdom').JSDOM
|
||||
beforeEach(function () {
|
||||
const dom = new JSDOM(``, {
|
||||
url: 'https://example.com/foo/bar/',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true
|
||||
})
|
||||
global.document = dom.window.document
|
||||
})
|
||||
afterEach(function () {
|
||||
delete global.document
|
||||
})
|
||||
describe('resolve', function () {
|
||||
it('should support relative root', function () {
|
||||
expect(resolve('foo', './views/', {
|
||||
extname: '',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/foo/bar/views/foo')
|
||||
})
|
||||
it('should treat root as directory', function () {
|
||||
expect(resolve('foo', './views', {
|
||||
extname: '',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/foo/bar/views/foo')
|
||||
})
|
||||
it('should support absolute root', function () {
|
||||
expect(resolve('foo', '/views', {
|
||||
extname: '',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/views/foo')
|
||||
})
|
||||
it('should support empty root', function () {
|
||||
expect(resolve('page.html', '', {
|
||||
extname: '',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/foo/bar/page.html')
|
||||
})
|
||||
it('should support full url as root', function () {
|
||||
expect(resolve('page.html', 'https://example.com/views/', {
|
||||
extname: '',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
it('should use options.root when root argument absent', function () {
|
||||
expect(resolve('page.html', null, {
|
||||
extname: '',
|
||||
root: ['https://example.com/views', 'https://google.com/views']
|
||||
})).to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
it('should add extname when absent', function () {
|
||||
expect(resolve('page', 'https://example.com/views/', {
|
||||
extname: '.html',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
it('should add extname for urls have searchParams', function () {
|
||||
expect(resolve('page?foo=bar', 'https://example.com/views/', {
|
||||
extname: '.html',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/views/page.html?foo=bar')
|
||||
})
|
||||
it('should not add extname when full url is given', function () {
|
||||
expect(resolve('https://google.com/page.php', 'https://example.com/views/', {
|
||||
extname: '.html',
|
||||
root: ['.']
|
||||
})).to.equal('https://google.com/page.php')
|
||||
})
|
||||
it('should not add extname when already have one', function () {
|
||||
expect(resolve('page.php', 'https://example.com/views/', {
|
||||
extname: '.html',
|
||||
root: ['.']
|
||||
})).to.equal('https://example.com/views/page.php')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,63 +0,0 @@
|
||||
import {extname, resolve} from '../../../src/util/url.js'
|
||||
import chai from 'chai'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('util/url', function () {
|
||||
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
||||
return
|
||||
}
|
||||
const JSDOM = require('jsdom').JSDOM
|
||||
let dom
|
||||
beforeEach(function () {
|
||||
dom = new JSDOM(``, {
|
||||
url: 'https://example.com/foo/bar/',
|
||||
contentType: 'text/html',
|
||||
includeNodeLocations: true
|
||||
})
|
||||
global.document = dom.window.document
|
||||
})
|
||||
afterEach(function () {
|
||||
delete global.document
|
||||
})
|
||||
describe('resolve', function () {
|
||||
describe('root', 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 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 empty root', function () {
|
||||
expect(resolve('', 'page.html'))
|
||||
.to.equal('https://example.com/foo/bar/page.html')
|
||||
})
|
||||
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'))
|
||||
.to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
it('should get the first value when argument is array', function () {
|
||||
expect(resolve(['https://example.com/views', 'https://google.com/views'], 'page.html'))
|
||||
.to.equal('https://example.com/views/page.html')
|
||||
expect(resolve(['https://example.com/views/', 'https://google.com/views'], 'page.html'))
|
||||
.to.equal('https://example.com/views/page.html')
|
||||
})
|
||||
})
|
||||
describe('extname', function () {
|
||||
it('should support relative path', function () {
|
||||
expect(extname('./views/page.html')).to.equal('.html')
|
||||
})
|
||||
it('should support absolute path', function () {
|
||||
expect(extname('/views/page.xml')).to.equal('.xml')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user