mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -07:00
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { resolve } from '../../src/parser/template-browser'
|
|
import { expect } from 'chai'
|
|
|
|
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 as any).document = dom.window.document
|
|
})
|
|
afterEach(function () {
|
|
delete (global as any).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')
|
|
})
|
|
})
|
|
})
|